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_conv """ 16import numpy as np 17 18import mindspore.nn as nn 19from mindspore import Tensor 20 21weight = Tensor(np.ones([2, 2])) 22in_channels = 3 23out_channels = 64 24kernel_size = 3 25 26 27def test_check_conv2d_1(): 28 m = nn.Conv2d(3, 64, 3, bias_init='zeros') 29 output = m(Tensor(np.ones([1, 3, 16, 50], dtype=np.float32))) 30 output_np = output.asnumpy() 31 assert isinstance(output_np[0][0][0][0], (np.float32, np.float64)) 32 33 34def test_check_conv2d_2(): 35 Tensor(np.ones([2, 2])) 36 m = nn.Conv2d(3, 64, 4, has_bias=False, weight_init='normal') 37 output = m(Tensor(np.ones([1, 3, 16, 50], dtype=np.float32))) 38 output_np = output.asnumpy() 39 assert isinstance(output_np[0][0][0][0], (np.float32, np.float64)) 40 41 42def test_check_conv2d_3(): 43 Tensor(np.ones([2, 2])) 44 m = nn.Conv2d(3, 64, (3, 3)) 45 output = m(Tensor(np.ones([1, 3, 16, 50], dtype=np.float32))) 46 output_np = output.asnumpy() 47 assert isinstance(output_np[0][0][0][0], (np.float32, np.float64)) 48 49 50def test_check_conv2d_4(): 51 Tensor(np.ones([2, 2])) 52 m = nn.Conv2d(3, 64, (3, 3), stride=2, pad_mode='pad', padding=4) 53 output = m(Tensor(np.ones([1, 3, 16, 50], dtype=np.float32))) 54 output_np = output.asnumpy() 55 assert isinstance(output_np[0][0][0][0], (np.float32, np.float64)) 56 57 58def test_check_conv2d_bias(): 59 m = nn.Conv2d(3, 64, 3, bias_init='zeros') 60 output = m(Tensor(np.ones([1, 3, 16, 50], dtype=np.float32))) 61 output_np = output.asnumpy() 62 assert isinstance(output_np[0][0][0][0], (np.float32, np.float64)) 63