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.

export.py 1.8 kB

3 years ago
3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # Copyright 2022 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. import mindspore as ms
  16. from src.yolo import YOLOV5s_Infer
  17. from model_utils.config import config
  18. from model_utils.moxing_adapter import moxing_wrapper, modelarts_export_preprocess
  19. @moxing_wrapper(pre_process=modelarts_export_preprocess, pre_args=[config])
  20. def run_export():
  21. ms.set_context(mode=ms.GRAPH_MODE, device_target=config.device_target)
  22. if config.device_target == "Ascend":
  23. ms.set_context(device_id=config.device_id)
  24. dict_version = {'yolov5s': 0, 'yolov5m': 1, 'yolov5l': 2, 'yolov5x': 3}
  25. config.file_name = config.file_name + '_' + config.yolov5_version
  26. network = YOLOV5s_Infer(config.testing_shape[0], version=dict_version[config.yolov5_version])
  27. network.set_train(False)
  28. param_dict = ms.load_checkpoint(config.ckpt_file)
  29. ms.load_param_into_net(network, param_dict)
  30. ts = config.testing_shape[0] // 2
  31. input_data = ms.numpy.zeros([config.batch_size, 12, ts, ts], ms.float32)
  32. ms.export(network, input_data, file_name=config.file_name, file_format=config.file_format)
  33. print('==========success export===============')
  34. if __name__ == "__main__":
  35. run_export()

随着人工智能和大数据的发展,任一方面对自动化工具有着一定的需求,在当下疫情防控期间,使用mindspore来实现yolo模型来进行目标检测及语义分割,对视频或图片都可以进行口罩佩戴检测和行人社交距离检测,来对公共场所的疫情防控来实行自动化管理。