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_interpolate.py 3.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. """ Test Interpolate """
  16. import pytest
  17. import mindspore.nn as nn
  18. import mindspore.common.dtype as mstype
  19. from mindspore import Tensor
  20. from mindspore import context
  21. context.set_context(mode=context.GRAPH_MODE)
  22. def test_interpolate():
  23. class Net(nn.Cell):
  24. def __init__(self):
  25. super(Net, self).__init__()
  26. self.value = Tensor([[[[1, 2, 3, 4], [5, 6, 7, 8]]]], mstype.float32)
  27. def construct(self):
  28. interpolate = nn.Interpolate()
  29. return interpolate(self.value, size=(5, 5))
  30. net = Net()
  31. net()
  32. def test_interpolate_1():
  33. class Net(nn.Cell):
  34. def __init__(self):
  35. super(Net, self).__init__()
  36. self.value = Tensor([[[[1, 2, 3, 4], [5, 6, 7, 8]]]], mstype.float32)
  37. def construct(self):
  38. interpolate = nn.Interpolate()
  39. return interpolate(self.value, scale_factor=2)
  40. net = Net()
  41. net()
  42. def test_interpolate_parameter():
  43. class Net(nn.Cell):
  44. def __init__(self):
  45. super(Net, self).__init__()
  46. def construct(self, x):
  47. interpolate = nn.Interpolate()
  48. return interpolate(x, size=(5, 5))
  49. net = Net()
  50. net(Tensor([[[[1, 2, 3, 4], [5, 6, 7, 8]]]], mstype.float32))
  51. def test_interpolate_parameter_1():
  52. class Net(nn.Cell):
  53. def __init__(self):
  54. super(Net, self).__init__()
  55. def construct(self, x):
  56. interpolate = nn.Interpolate()
  57. return interpolate(x, scale_factor=2)
  58. net = Net()
  59. net(Tensor([[[[1, 2, 3, 4], [5, 6, 7, 8]]]], mstype.float32))
  60. def test_interpolate_error():
  61. class Net(nn.Cell):
  62. def __init__(self):
  63. super(Net, self).__init__()
  64. self.value = Tensor([[[[1, 2, 3, 4], [5, 6, 7, 8]]]], mstype.float32)
  65. def construct(self):
  66. interpolate = nn.Interpolate()
  67. return interpolate(self.value)
  68. net = Net()
  69. with pytest.raises(ValueError) as ex:
  70. net()
  71. assert "size and scale both none" in str(ex.value)
  72. def test_interpolate_error_1():
  73. class Net(nn.Cell):
  74. def __init__(self):
  75. super(Net, self).__init__()
  76. self.value = Tensor([[[[1, 2, 3, 4], [5, 6, 7, 8]]]], mstype.float32)
  77. def construct(self):
  78. interpolate = nn.Interpolate()
  79. return interpolate(self.value, size=(5, 5), scale_factor=2)
  80. net = Net()
  81. with pytest.raises(ValueError) as ex:
  82. net()
  83. assert "size and scale both not none" in str(ex.value)