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.8 kB

5 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # Copyright 2020 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. ##############export checkpoint file into air and onnx models#################
  17. python export.py
  18. """
  19. import argparse
  20. import numpy as np
  21. from mindspore import Tensor, load_checkpoint, load_param_into_net, export
  22. if __name__ == '__main__':
  23. parser = argparse.ArgumentParser(description='resnet export')
  24. parser.add_argument('--network_dataset', type=str, default='resnet50_cifar10', choices=['resnet50_cifar10',
  25. 'resnet50_imagenet2012',
  26. 'resnet101_imagenet2012',
  27. "se-resnet50_imagenet2012"],
  28. help='network and dataset name.')
  29. parser.add_argument('--ckpt_file', type=str, default='', help='resnet ckpt file.')
  30. parser.add_argument('--output_file', type=str, default='', help='resnet output air name.')
  31. args_opt = parser.parse_args()
  32. if args_opt.network_dataset == 'resnet50_cifar10':
  33. from src.config import config1 as config
  34. from src.resnet import resnet50 as resnet
  35. elif args_opt.network_dataset == 'resnet50_imagenet2012':
  36. from src.config import config2 as config
  37. from src.resnet import resnet50 as resnet
  38. elif args_opt.network_dataset == 'resnet101_imagenet2012':
  39. from src.config import config3 as config
  40. from src.resnet import resnet101 as resnet
  41. elif args_opt.network_dataset == 'se-resnet50_imagenet2012':
  42. from src.config import config4 as config
  43. from src.resnet import se_resnet50 as resnet
  44. else:
  45. raise ValueError("network and dataset is not support.")
  46. net = resnet(config.class_num)
  47. assert args_opt.ckpt_file is not None, "checkpoint_path is None."
  48. param_dict = load_checkpoint(args_opt.ckpt_file)
  49. load_param_into_net(net, param_dict)
  50. input_arr = Tensor(np.zeros([1, 3, 224, 224], np.float32))
  51. export(net, input_arr, file_name=args_opt.output_file, file_format="AIR")