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 """ 16import pytest 17 18import mindspore.nn as nn 19import mindspore.common.dtype as mstype 20from mindspore import Tensor 21from mindspore import context 22 23context.set_context(mode=context.GRAPH_MODE) 24 25 26def test_resizebilinear(): 27 class Net(nn.Cell): 28 def __init__(self): 29 super(Net, self).__init__() 30 self.value = Tensor([[[[1, 2, 3, 4], [5, 6, 7, 8]]]], mstype.float32) 31 32 def construct(self): 33 interpolate = nn.ResizeBilinear() 34 return interpolate(self.value, size=(5, 5)) 35 36 net = Net() 37 net() 38 39 40def test_resizebilinear_1(): 41 class Net(nn.Cell): 42 def __init__(self): 43 super(Net, self).__init__() 44 self.value = Tensor([[[[1, 2, 3, 4], [5, 6, 7, 8]]]], mstype.float32) 45 46 def construct(self): 47 interpolate = nn.ResizeBilinear() 48 return interpolate(self.value, scale_factor=2) 49 50 net = Net() 51 net() 52 53 54def test_resizebilinear_parameter(): 55 class Net(nn.Cell): 56 def __init__(self): 57 super(Net, self).__init__() 58 59 def construct(self, x): 60 interpolate = nn.ResizeBilinear() 61 return interpolate(x, size=(5, 5)) 62 63 net = Net() 64 net(Tensor([[[[1, 2, 3, 4], [5, 6, 7, 8]]]], mstype.float32)) 65 66 67def test_resizebilinear_parameter_1(): 68 class Net(nn.Cell): 69 def __init__(self): 70 super(Net, self).__init__() 71 72 def construct(self, x): 73 interpolate = nn.ResizeBilinear() 74 return interpolate(x, scale_factor=2) 75 76 net = Net() 77 net(Tensor([[[[1, 2, 3, 4], [5, 6, 7, 8]]]], mstype.float32)) 78 79 80def test_resizebilinear_error(): 81 class Net(nn.Cell): 82 def __init__(self): 83 super(Net, self).__init__() 84 self.value = Tensor([[[[1, 2, 3, 4], [5, 6, 7, 8]]]], mstype.float32) 85 86 def construct(self): 87 interpolate = nn.ResizeBilinear() 88 return interpolate(self.value) 89 90 net = Net() 91 with pytest.raises(ValueError) as ex: 92 net() 93 assert "'size' and 'scale' both none" in str(ex.value) 94 95 96def test_resizebilinear_error_1(): 97 class Net(nn.Cell): 98 def __init__(self): 99 super(Net, self).__init__() 100 self.value = Tensor([[[[1, 2, 3, 4], [5, 6, 7, 8]]]], mstype.float32) 101 102 def construct(self): 103 interpolate = nn.ResizeBilinear() 104 return interpolate(self.value, size=(5, 5), scale_factor=2) 105 106 net = Net() 107 with pytest.raises(ValueError) as ex: 108 net() 109 assert "'size' and 'scale' both not none" in str(ex.value) 110