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_squeeze_op.py 2.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. # Copyright 2019-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. import numpy as np
  16. import pytest
  17. import mindspore.context as context
  18. import mindspore.nn as nn
  19. from mindspore import Tensor
  20. from mindspore.ops import operations as P
  21. class SqueezeNet(nn.Cell):
  22. def __init__(self):
  23. super(SqueezeNet, self).__init__()
  24. self.squeeze = P.Squeeze()
  25. def construct(self, tensor):
  26. return self.squeeze(tensor)
  27. def squeeze(nptype):
  28. context.set_context(mode=context.GRAPH_MODE, device_target="GPU")
  29. np.random.seed(0)
  30. x = np.random.randn(1, 16, 1, 1).astype(nptype)
  31. net = SqueezeNet()
  32. output = net(Tensor(x))
  33. assert np.all(output.asnumpy() == x.squeeze())
  34. @pytest.mark.level0
  35. @pytest.mark.platform_x86_gpu_training
  36. @pytest.mark.env_onecard
  37. def test_squeeze_bool():
  38. squeeze(np.bool)
  39. @pytest.mark.level0
  40. @pytest.mark.platform_x86_gpu_training
  41. @pytest.mark.env_onecard
  42. def test_squeeze_uint8():
  43. squeeze(np.uint8)
  44. @pytest.mark.level0
  45. @pytest.mark.platform_x86_gpu_training
  46. @pytest.mark.env_onecard
  47. def test_squeeze_uint16():
  48. squeeze(np.uint16)
  49. @pytest.mark.level0
  50. @pytest.mark.platform_x86_gpu_training
  51. @pytest.mark.env_onecard
  52. def test_squeeze_uint32():
  53. squeeze(np.uint32)
  54. @pytest.mark.level0
  55. @pytest.mark.platform_x86_gpu_training
  56. @pytest.mark.env_onecard
  57. def test_squeeze_int8():
  58. squeeze(np.int8)
  59. @pytest.mark.level0
  60. @pytest.mark.platform_x86_gpu_training
  61. @pytest.mark.env_onecard
  62. def test_squeeze_int16():
  63. squeeze(np.int16)
  64. @pytest.mark.level0
  65. @pytest.mark.platform_x86_gpu_training
  66. @pytest.mark.env_onecard
  67. def test_squeeze_int32():
  68. squeeze(np.int32)
  69. @pytest.mark.level0
  70. @pytest.mark.platform_x86_gpu_training
  71. @pytest.mark.env_onecard
  72. def test_squeeze_int64():
  73. squeeze(np.int64)
  74. @pytest.mark.level0
  75. @pytest.mark.platform_x86_gpu_training
  76. @pytest.mark.env_onecard
  77. def test_squeeze_float16():
  78. squeeze(np.float16)
  79. @pytest.mark.level0
  80. @pytest.mark.platform_x86_gpu_training
  81. @pytest.mark.env_onecard
  82. def test_squeeze_float32():
  83. squeeze(np.float32)
  84. @pytest.mark.level0
  85. @pytest.mark.platform_x86_gpu_training
  86. @pytest.mark.env_onecard
  87. def test_squeeze_float64():
  88. squeeze(np.float64)