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.

data_loader.py 2.3 kB

5 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # Copyright 2019 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. """
  16. DataLoader is an adapter for all other loaders.
  17. This module can identify what loader should be used to load data.
  18. """
  19. from mindinsight.datavisual.common.log import logger
  20. from mindinsight.datavisual.data_transform.ms_data_loader import MSDataLoader
  21. from mindinsight.datavisual.common import exceptions
  22. class DataLoader:
  23. """
  24. The adapter of all kinds of loaders.
  25. Args:
  26. summary_dir (str): A directory path.
  27. """
  28. def __init__(self, summary_dir):
  29. self._summary_dir = summary_dir
  30. self._loader = None
  31. def load(self):
  32. """Load the data when loader is exist."""
  33. if self._loader is None:
  34. ms_dataloader = MSDataLoader(self._summary_dir)
  35. loaders = [ms_dataloader]
  36. for loader in loaders:
  37. if loader.filter_valid_files():
  38. self._loader = loader
  39. break
  40. if self._loader is None:
  41. logger.warning("No valid files can be loaded, summary_dir: %s.", self._summary_dir)
  42. raise exceptions.SummaryLogPathInvalid()
  43. self._loader.load()
  44. def get_events_data(self):
  45. """
  46. Get events data from log file.
  47. Returns:
  48. Optional[EventsData], None or events data.
  49. """
  50. return self._loader.get_events_data()
  51. def has_valid_files(self):
  52. """
  53. Check the directory for valid files.
  54. Returns:
  55. bool, if the directory has valid files, return True.
  56. """
  57. ms_dataloader = MSDataLoader(self._summary_dir)
  58. return bool(ms_dataloader.filter_valid_files())

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

Contributors (1)