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

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