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 2.4 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # Copyright 2021 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. """export for retinanet"""
  16. import argparse
  17. import numpy as np
  18. import mindspore.common.dtype as mstype
  19. from mindspore import context, Tensor
  20. from mindspore.train.serialization import load_checkpoint, load_param_into_net, export
  21. from src.retinanet import retinanet50, resnet50, retinanetInferWithDecoder
  22. from src.config import config
  23. from src.box_utils import default_boxes
  24. if __name__ == '__main__':
  25. parser = argparse.ArgumentParser(description='retinanet evaluation')
  26. parser.add_argument("--device_id", type=int, default=0, help="Device id, default is 0.")
  27. parser.add_argument("--run_platform", type=str, default="Ascend", choices=("Ascend"),
  28. help="run platform, only support Ascend.")
  29. parser.add_argument("--file_format", type=str, choices=["AIR", "MINDIR"], default="MINDIR", help="file format")
  30. parser.add_argument("--batch_size", type=int, default=1, help="batch size")
  31. parser.add_argument("--file_name", type=str, default="retinanet", help="output file name.")
  32. args_opt = parser.parse_args()
  33. context.set_context(mode=context.GRAPH_MODE, device_target=args_opt.run_platform, device_id=args_opt.device_id)
  34. backbone = resnet50(config.num_classes)
  35. net = retinanet50(backbone, config)
  36. net = retinanetInferWithDecoder(net, Tensor(default_boxes), config)
  37. param_dict = load_checkpoint(config.checkpoint_path)
  38. net.init_parameters_data()
  39. load_param_into_net(net, param_dict)
  40. net.set_train(False)
  41. shape = [args_opt.batch_size, 3] + config.img_shape
  42. input_data = Tensor(np.zeros(shape), mstype.float32)
  43. export(net, input_data, file_name=args_opt.file_name, file_format=args_opt.file_format)