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.

test_net.py 1.9 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # Copyright 2021 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 net test."""
  16. import os
  17. import numpy as np
  18. import pytest
  19. import mindspore as ms
  20. import mindspore.nn as nn
  21. from mindspore import context
  22. from mindspore.common.tensor import Tensor
  23. from mindspore.train.serialization import export
  24. class SliceNet(nn.Cell):
  25. def __init__(self):
  26. super().__init__()
  27. self.relu = nn.ReLU()
  28. def construct(self, x, y):
  29. x = self.relu(x)
  30. x[2,] = y
  31. return x
  32. @pytest.mark.level0
  33. @pytest.mark.platform_x86_ascend_training
  34. @pytest.mark.platform_arm_ascend_training
  35. @pytest.mark.env_onecard
  36. def test_export_slice_net():
  37. context.set_context(mode=context.GRAPH_MODE, device_target="Ascend")
  38. input_x = Tensor(np.random.rand(4, 4, 4), ms.float32)
  39. input_y = Tensor(np.array([1]), ms.float32)
  40. net = SliceNet()
  41. file_name = "slice_net"
  42. export(net, input_x, input_y, file_name=file_name, file_format='AIR')
  43. verify_name = file_name + ".air"
  44. assert os.path.exists(verify_name)
  45. os.remove(verify_name)
  46. export(net, input_x, input_y, file_name=file_name, file_format='MINDIR')
  47. verify_name = file_name + ".mindir"
  48. assert os.path.exists(verify_name)
  49. os.remove(verify_name)