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.

path_parser.py 2.8 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. """This file provides path resolution."""
  16. from mindinsight.datavisual.data_transform.summary_watcher import SummaryWatcher
  17. from mindinsight.lineagemgr.common.log import logger
  18. from mindinsight.lineagemgr.common.utils import get_timestamp
  19. from mindinsight.utils.exceptions import MindInsightException
  20. class SummaryPathParser:
  21. """
  22. Summary path parser.
  23. This class is a utility class, users can use it to parse summary dir,
  24. parse summary log path, get the latest lineage summary log, etc.
  25. """
  26. LINEAGE_SUMMARY_SUFFIX = '_lineage'
  27. _LINEAGE_SUMMARY_SUFFIX_LEN = len(LINEAGE_SUMMARY_SUFFIX)
  28. @staticmethod
  29. def get_lineage_summaries(summary_dir, is_sorted=False, reverse=True):
  30. """
  31. Get lineage summaries according to summary dir.
  32. Args:
  33. summary_dir (str): Summary dir.
  34. is_sorted (bool): If it is True, files will be sorted.
  35. reverse (bool): If it is True, sort by timestamp increments and filename decrement.
  36. Returns:
  37. list, if the lineage summary log exist, return the file names, else return [].
  38. """
  39. try:
  40. summary_watcher = SummaryWatcher()
  41. summaries = summary_watcher.list_summaries(summary_base_dir=summary_dir)
  42. except MindInsightException as err:
  43. logger.warning(str(err))
  44. return []
  45. summary_files = [summary.get('file_name') for summary in summaries]
  46. lineage_files_name = list(filter(
  47. lambda filename: (filename.endswith(SummaryPathParser.LINEAGE_SUMMARY_SUFFIX)), summary_files))
  48. if is_sorted:
  49. lineage_files_name = SummaryPathParser._sorted_summary_files(lineage_files_name, reverse)
  50. return lineage_files_name
  51. @staticmethod
  52. def _sorted_summary_files(summary_files, reverse):
  53. """Sort by timestamp increments and filename decrement."""
  54. sorted_files = sorted(summary_files,
  55. key=lambda filename: (-get_timestamp(filename), filename),
  56. reverse=reverse)
  57. return sorted_files

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