• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2022 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 pytest
17
18import mindspore as ms
19import mindspore.nn as nn
20import mindspore.ops as ops
21
22
23class Net(nn.Cell):
24    def __init__(self, kernel_size=1, stride=1, pad_mode="valid", padding=0, ceil_mode=False, count_include_pad=True,
25                 divisor_override=None):
26        super(Net, self).__init__()
27        self.pool = nn.AvgPool3d(kernel_size=kernel_size, stride=stride, pad_mode=pad_mode, padding=padding,
28                                 ceil_mode=ceil_mode, count_include_pad=count_include_pad,
29                                 divisor_override=divisor_override)
30
31    def construct(self, x):
32        out = self.pool(x)
33        return out
34
35
36@pytest.mark.level2
37@pytest.mark.platform_x86_gpu_training
38@pytest.mark.platform_x86_cpu
39@pytest.mark.platform_arm_cpu
40@pytest.mark.env_onecard
41@pytest.mark.parametrize('mode', [ms.GRAPH_MODE, ms.PYNATIVE_MODE])
42def test_avgpool3d_normal(mode):
43    """
44    Feature: AvgPool3d
45    Description: Verify the result of AvgPool3d
46    Expectation: success
47    """
48    ms.set_context(mode=mode)
49    x1 = ops.randn(1, 2, 4, 4, 5).astype(ms.float32)
50    pool1 = Net(kernel_size=3, stride=1)
51    output1 = pool1(x1)
52
53    x2 = ops.randn(6, 5, 7, 7, 5).astype(ms.float32)
54    pool2 = Net(kernel_size=4, stride=2, pad_mode='pad', padding=(2, 2, 1), divisor_override=10)
55    output2 = pool2(x2)
56
57    assert output1.shape == (1, 2, 2, 2, 3)
58    assert output2.shape == (6, 5, 4, 4, 2)
59