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

5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142
  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. """export AIR file."""
  16. import argparse
  17. import numpy as np
  18. from mindspore import Tensor, context, load_checkpoint, load_param_into_net, export
  19. from src.nets import net_factory
  20. context.set_context(mode=context.GRAPH_MODE, save_graphs=False)
  21. if __name__ == '__main__':
  22. parser = argparse.ArgumentParser(description='checkpoint export')
  23. parser.add_argument('--checkpoint', type=str.lower, default='', help='checkpoint of deeplabv3 (Default: None)')
  24. parser.add_argument('--model', type=str.lower, default='deeplab_v3_s8', choices=['deeplab_v3_s16', 'deeplab_v3_s8'],
  25. help='Select model structure (Default: deeplab_v3_s8)')
  26. parser.add_argument('--num_classes', type=int, default=21, help='the number of classes (Default: 21)')
  27. args = parser.parse_args()
  28. if args.model == 'deeplab_v3_s16':
  29. network = net_factory.nets_map['deeplab_v3_s16']('eval', args.num_classes, 16, True)
  30. else:
  31. network = net_factory.nets_map['deeplab_v3_s8']('eval', args.num_classes, 8, True)
  32. param_dict = load_checkpoint(args.checkpoint)
  33. # load the parameter into net
  34. load_param_into_net(network, param_dict)
  35. input_data = np.random.uniform(0.0, 1.0, size=[32, 3, 513, 513]).astype(np.float32)
  36. export(network, Tensor(input_data), file_name=args.model+'-300_11.air', file_format='AIR')