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.

utils.py 1.8 kB

5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. Description: This file is used for some common util.
  17. """
  18. import os
  19. import shutil
  20. import time
  21. from urllib.parse import urlencode
  22. from mindinsight.datavisual.common.enums import DataManagerStatus
  23. def get_url(url, params):
  24. """
  25. Concatenate the URL and params.
  26. Args:
  27. url (str): A link requested. For example, http://example.com.
  28. params (dict): A dict consists of params. For example, {'offset': 1, 'limit':'100}.
  29. Returns:
  30. str, like http://example.com?offset=1&limit=100
  31. """
  32. return url + '?' + urlencode(params)
  33. def delete_files_or_dirs(path_list):
  34. """Delete files or dirs in path_list."""
  35. for path in path_list:
  36. if os.path.isdir(path):
  37. shutil.rmtree(path)
  38. else:
  39. os.remove(path)
  40. def check_loading_done(data_manager, time_limit=15):
  41. """If loading data for more than `time_limit` seconds, exit."""
  42. start_time = time.time()
  43. while data_manager.status != DataManagerStatus.DONE.value:
  44. time_used = time.time() - start_time
  45. if time_used > time_limit:
  46. break
  47. time.sleep(0.1)
  48. continue

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