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 16import numpy as np 17import pytest 18 19import mindspore.nn as nn 20import mindspore.common.dtype as mstype 21from mindspore.common.initializer import Normal 22from mindspore import Tensor 23from mindspore import context 24 25context.set_context(mode=context.GRAPH_MODE, device_target="GPU") 26 27 28@pytest.mark.level1 29@pytest.mark.platform_x86_gpu_training 30@pytest.mark.env_onecard 31def test_conv2d_depthwiseconv2d_str(): 32 net = nn.Conv2d(128, 128, (2, 3), stride=4, pad_mode='valid', padding=0, group=128, weight_init='normal') 33 input_data = Tensor(np.ones([3, 128, 127, 114]), dtype=mstype.float32) 34 output = net(input_data) 35 assert output.shape == (3, 128, 32, 28) 36 37 38@pytest.mark.level1 39@pytest.mark.platform_x86_gpu_training 40@pytest.mark.env_onecard 41def test_conv2d_depthwiseconv2d_initializer(): 42 net = nn.Conv2d(128, 128, (2, 3), stride=4, pad_mode='valid', padding=0, group=128, weight_init=Normal()) 43 input_data = Tensor(np.ones([3, 128, 127, 114]), dtype=mstype.float32) 44 output = net(input_data) 45 assert output.shape == (3, 128, 32, 28) 46 47 48@pytest.mark.level1 49@pytest.mark.platform_x86_gpu_training 50@pytest.mark.env_onecard 51def test_conv2d_depthwiseconv2d_tensor(): 52 weight_init = Tensor(np.random.randn(128, 1, 2, 3).astype(np.float32)) 53 net = nn.Conv2d(128, 128, (2, 3), stride=4, pad_mode='valid', padding=0, group=128, weight_init=weight_init) 54 input_data = Tensor(np.ones([3, 128, 127, 114]), dtype=mstype.float32) 55 output = net(input_data) 56 assert output.shape == (3, 128, 32, 28) 57