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.

train_visual_api.py 5.0 kB

5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. Backend interface module.
  17. This module provides the interfaces to train processors functions.
  18. """
  19. from flask import Blueprint
  20. from flask import request
  21. from flask import jsonify
  22. from mindinsight.conf import settings
  23. from mindinsight.datavisual.utils.tools import get_train_id
  24. from mindinsight.datavisual.utils.tools import if_nan_inf_to_none
  25. from mindinsight.datavisual.processors.images_processor import ImageProcessor
  26. from mindinsight.datavisual.processors.scalars_processor import ScalarsProcessor
  27. from mindinsight.datavisual.processors.graph_processor import GraphProcessor
  28. from mindinsight.datavisual.data_transform.data_manager import DATA_MANAGER
  29. BLUEPRINT = Blueprint("train_visual", __name__, url_prefix=settings.URL_PREFIX)
  30. @BLUEPRINT.route("/datavisual/image/metadata", methods=["GET"])
  31. def image_metadata():
  32. """
  33. Interface to fetch metadata about the images for the particular run,tag, and zero-indexed sample.
  34. Returns:
  35. Response, which contains a list in JSON containing image events, each
  36. one of which is an object containing items wall_time, step, width,
  37. height, and query.
  38. """
  39. tag = request.args.get("tag")
  40. train_id = get_train_id(request)
  41. processor = ImageProcessor(DATA_MANAGER)
  42. response = processor.get_metadata_list(train_id, tag)
  43. return jsonify(response)
  44. @BLUEPRINT.route("/datavisual/image/single-image", methods=["GET"])
  45. def single_image():
  46. """
  47. Interface to fetch raw image data for a particular image.
  48. Returns:
  49. Response, which contains a byte string of image.
  50. """
  51. tag = request.args.get("tag")
  52. step = request.args.get("step")
  53. train_id = get_train_id(request)
  54. processor = ImageProcessor(DATA_MANAGER)
  55. img_data = processor.get_single_image(train_id, tag, step)
  56. return img_data
  57. @BLUEPRINT.route("/datavisual/scalar/metadata", methods=["GET"])
  58. def scalar_metadata():
  59. """
  60. Interface to fetch metadata about the scalars for the particular run and tag.
  61. Returns:
  62. Response, which contains a list in JSON containing scalar events, each
  63. one of which is an object containing items' wall_time, step and value.
  64. """
  65. tag = request.args.get("tag")
  66. train_id = request.args.get("train_id")
  67. processor = ScalarsProcessor(DATA_MANAGER)
  68. response = processor.get_metadata_list(train_id, tag)
  69. metadatas = response['metadatas']
  70. for metadata in metadatas:
  71. value = metadata.get("value")
  72. metadata["value"] = if_nan_inf_to_none('scalar_value', value)
  73. return jsonify(response)
  74. @BLUEPRINT.route("/datavisual/graphs/nodes", methods=["GET"])
  75. def graph_nodes():
  76. """
  77. Interface to get graph nodes.
  78. Returns:
  79. Response, which contains a JSON object.
  80. """
  81. name = request.args.get('name', default=None)
  82. node_type = request.args.get('type', default='name_scope')
  83. tag = request.args.get("tag", default=None)
  84. train_id = get_train_id(request)
  85. graph_process = GraphProcessor(train_id, DATA_MANAGER, tag)
  86. response = graph_process.get_nodes(name=name, node_type=node_type)
  87. return jsonify(response)
  88. @BLUEPRINT.route("/datavisual/graphs/nodes/names", methods=["GET"])
  89. def graph_node_names():
  90. """
  91. Interface to query node names.
  92. Returns:
  93. Response, which contains a JSON object.
  94. """
  95. search_content = request.args.get("search")
  96. offset = request.args.get("offset", default=0)
  97. limit = request.args.get("limit", default=100)
  98. tag = request.args.get("tag", default=None)
  99. train_id = get_train_id(request)
  100. graph_process = GraphProcessor(train_id, DATA_MANAGER, tag)
  101. resp = graph_process.search_node_names(search_content, offset, limit)
  102. return jsonify(resp)
  103. @BLUEPRINT.route("/datavisual/graphs/single-node", methods=["GET"])
  104. def graph_search_single_node():
  105. """
  106. Interface to search single node.
  107. Returns:
  108. Response, which contains a JSON object.
  109. """
  110. name = request.args.get("name")
  111. tag = request.args.get("tag", default=None)
  112. train_id = get_train_id(request)
  113. graph_process = GraphProcessor(train_id, DATA_MANAGER, tag)
  114. resp = graph_process.search_single_node(name)
  115. return jsonify(resp)
  116. def init_module(app):
  117. """
  118. Init module entry.
  119. Args:
  120. app (Flask): The application obj.
  121. """
  122. app.register_blueprint(BLUEPRINT)

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

Contributors (1)