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.

text_lite_mindir.py 2.1 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # Copyright 2020 Huawei Technologies Co., Ltd
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # Copyright 2020 Huawei Technologies Co., Ltd
  5. #
  6. # Licensed under the Apache License, Version 2.0 (the "License");
  7. # you may not use this file except in compliance with the License.
  8. # You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS,
  14. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. # ============================================================================
  18. """mobilenetv2 export mindir."""
  19. import os
  20. import numpy as np
  21. import pytest
  22. from mindspore import Tensor
  23. from mindspore.train.serialization import export, load_checkpoint
  24. from mindspore import context
  25. from model_zoo.official.cv.mobilenetv2.src.mobilenetV2 import MobileNetV2Backbone, MobileNetV2Head, mobilenet_v2
  26. context.set_context(mode=context.GRAPH_MODE, device_target="GPU")
  27. ckpt_path = '/home/workspace/mindspore_dataset/checkpoint/mobilenetv2/mobilenetv2_gpu.ckpt'
  28. @pytest.mark.level0
  29. @pytest.mark.platform_x86_gpu_training
  30. @pytest.mark.env_onecard
  31. def test_export_mobilenetv2_gpu_mindir():
  32. backbone_net = MobileNetV2Backbone()
  33. head_net = MobileNetV2Head(input_channel=backbone_net.out_channels, num_classes=1000)
  34. net = mobilenet_v2(backbone_net, head_net)
  35. load_checkpoint(ckpt_path, net)
  36. input_tensor = Tensor(np.ones([1, 3, 224, 224]).astype(np.float32))
  37. export(net, input_tensor, file_name="mobilenetv2_gpu", file_format="MINDIR")
  38. output = net(input_tensor).asnumpy().tolist()
  39. file_obj = open('mobilenetv2_gpu_output.txt', 'w')
  40. file_obj.write("output 1 3 224 224\n")
  41. for num in output[0]:
  42. file_obj.write(str(num))
  43. file_obj.close()
  44. assert os.path.exists("mobilenetv2_gpu.mindir")
  45. assert os.path.exists("mobilenetv2_gpu_output.txt")