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 3.6 kB

5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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.conf import settings
  19. from mindinsight.utils.hook import BaseHook
  20. class ReloadIntervalAction(argparse.Action):
  21. """Reload interval action class definition."""
  22. def __call__(self, parser, namespace, values, option_string=None):
  23. """
  24. Inherited __call__ method from argparse.Action.
  25. Args:
  26. parser (ArgumentParser): Passed-in argument parser.
  27. namespace (Namespace): Namespace object to hold arguments.
  28. values (object): Argument values with type depending on argument definition.
  29. option_string (str): Option string for specific argument name.
  30. """
  31. reload_interval = values
  32. if reload_interval < 0:
  33. parser.error(f'{option_string} should be greater than or equal to 0')
  34. setattr(namespace, self.dest, reload_interval)
  35. class SummaryBaseDirAction(argparse.Action):
  36. """Summary base dir action class definition."""
  37. def __call__(self, parser, namespace, values, option_string=None):
  38. """
  39. Inherited __call__ method from argparse.Action.
  40. Args:
  41. parser (ArgumentParser): Passed-in argument parser.
  42. namespace (Namespace): Namespace object to hold arguments.
  43. values (object): Argument values with type depending on argument definition.
  44. option_string (str): Option string for specific argument name.
  45. """
  46. summary_base_dir = os.path.realpath(values)
  47. setattr(namespace, self.dest, summary_base_dir)
  48. class Hook(BaseHook):
  49. """Hook class definition."""
  50. def register_startup_arguments(self, parser):
  51. """
  52. Hook function to register startup arguments.
  53. Args:
  54. parser (ArgumentParser): Specify parser to which arguments are added.
  55. """
  56. parser.add_argument(
  57. '--reload-interval',
  58. type=int,
  59. action=ReloadIntervalAction,
  60. help="""
  61. data reload time(Seconds). It should be greater than 0 or equal to 0.
  62. If it equals 0, load data only once. Default value is %s seconds.
  63. """ % settings.RELOAD_INTERVAL)
  64. parser.add_argument(
  65. '--summary-base-dir',
  66. type=str,
  67. action=SummaryBaseDirAction,
  68. help="""
  69. directory where MindInsight will walk through its direct subdirectories
  70. and look for summary files naming with regex 'summary.\\d+' or '\\.pb$'. Any direct
  71. subdirectory containing summary files will turn out to be the summary
  72. file directory. Summary file existing in summary-base-dir indicates that
  73. sumamry-base-dir is one of the summary file directories as well. Default
  74. value is current directory.""")

MindInsight为MindSpore提供了简单易用的调优调试能力。在训练过程中,可以将标量、张量、图像、计算图、模型超参、训练耗时等数据记录到文件中,通过MindInsight可视化页面进行查看及分析。

Contributors (1)