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

5 years ago
5 years ago
4 years ago
5 years ago
5 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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, onnx, mindir models#################
  17. python export.py
  18. """
  19. import os
  20. # import sys
  21. # sys.path.append(os.path.join(os.getcwd(), 'utils'))
  22. from utils.config import config
  23. import numpy as np
  24. import mindspore as ms
  25. from mindspore import context, Tensor, load_checkpoint, load_param_into_net, export
  26. from src.alexnet import AlexNet
  27. if os.path.exists(config.data_path_local):
  28. ckpt_path = config.ckpt_path_local
  29. else:
  30. ckpt_path = os.path.join(config.data_path, 'checkpoint_alexnet-30_1562.ckpt')
  31. context.set_context(mode=context.GRAPH_MODE, device_target=config.device_target)
  32. if config.device_target == "Ascend":
  33. context.set_context(device_id=config.device_id)
  34. if __name__ == '__main__':
  35. net = AlexNet(num_classes=config.num_classes)
  36. param_dict = load_checkpoint(ckpt_path)
  37. load_param_into_net(net, param_dict)
  38. input_arr = Tensor(np.zeros([config.batch_size, 3, config.image_height, config.image_width]), ms.float32)
  39. export(net, input_arr, file_name=config.file_name, file_format=config.file_format)