You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

datavisual.py 2.4 kB

5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # Copyright 2020 Huawei Technologies Co., Ltd
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # ============================================================================
  15. """Datavisual hook."""
  16. import argparse
  17. import os
  18. from mindinsight.utils.hook import BaseHook
  19. class SummaryBaseDirAction(argparse.Action):
  20. """Summary base dir action class definition."""
  21. def __call__(self, parser, namespace, values, option_string=None):
  22. """
  23. Inherited __call__ method from argparse.Action.
  24. Args:
  25. parser (ArgumentParser): Passed-in argument parser.
  26. namespace (Namespace): Namespace object to hold arguments.
  27. values (object): Argument values with type depending on argument definition.
  28. option_string (str): Option string for specific argument name.
  29. """
  30. summary_base_dir = os.path.realpath(values)
  31. setattr(namespace, self.dest, summary_base_dir)
  32. class Hook(BaseHook):
  33. """Hook class definition."""
  34. def register_startup_arguments(self, parser):
  35. """
  36. Hook function to register startup arguments.
  37. Args:
  38. parser (ArgumentParser): Specify parser to which arguments are added.
  39. """
  40. parser.add_argument(
  41. '--summary-base-dir',
  42. type=str,
  43. action=SummaryBaseDirAction,
  44. help="""
  45. directory where MindInsight will walk through its direct subdirectories
  46. and look for summary files naming with regex 'summary.\\d+' or '\\.pb$'. Any direct
  47. subdirectory containing summary files will turn out to be the summary
  48. file directory. Summary file existing in summary-base-dir indicates that
  49. sumamry-base-dir is one of the summary file directories as well. Default
  50. value is current directory.""")