From ed7aa8f9c3bada4964c8135b5f3ef15cbeb721b8 Mon Sep 17 00:00:00 2001 From: Kaipeng Deng Date: Mon, 23 Nov 2020 11:09:25 +0800 Subject: [PATCH] Fix conv transpose (#28629) * fix conv_transpose unittest. test=develop --- .../fluid/tests/unittests/CMakeLists.txt | 5 +- .../unittests/test_conv2d_transpose_op.py | 97 +------------------ ...test_conv2d_transpose_op_depthwise_conv.py | 96 ++++++++++++++++++ .../unittests/test_conv3d_transpose_op.py | 40 ++++---- 4 files changed, 121 insertions(+), 117 deletions(-) create mode 100644 python/paddle/fluid/tests/unittests/test_conv2d_transpose_op_depthwise_conv.py diff --git a/python/paddle/fluid/tests/unittests/CMakeLists.txt b/python/paddle/fluid/tests/unittests/CMakeLists.txt index 0efb88987e..858fe7a5fc 100644 --- a/python/paddle/fluid/tests/unittests/CMakeLists.txt +++ b/python/paddle/fluid/tests/unittests/CMakeLists.txt @@ -75,8 +75,6 @@ if(NOT WITH_GPU OR WIN32) LIST(REMOVE_ITEM TEST_OPS test_collective_allgather_api) endif() -#TODO(sunxiaolong01): Fix this unitest failed on GCC8. -LIST(REMOVE_ITEM TEST_OPS test_conv2d_transpose_op) if(WIN32) LIST(REMOVE_ITEM TEST_OPS test_boxps) LIST(REMOVE_ITEM TEST_OPS test_trainer_desc) @@ -341,7 +339,6 @@ list(REMOVE_ITEM TEST_OPS test_fuse_bn_act_pass) list(REMOVE_ITEM TEST_OPS test_fuse_bn_add_act_pass) list(REMOVE_ITEM TEST_OPS test_imperative_static_runner_mnist) list(REMOVE_ITEM TEST_OPS test_imperative_static_runner_while) -list(REMOVE_ITEM TEST_OPS test_conv3d_transpose_op) # disable this unittest temporarily list(REMOVE_ITEM TEST_OPS test_imperative_data_loader_exception) @@ -697,7 +694,9 @@ set_tests_properties(test_eager_deletion_lstm_net PROPERTIES TIMEOUT 120) set_tests_properties(test_parallel_executor_mnist PROPERTIES TIMEOUT 120) set_tests_properties(test_imperative_ptb_rnn PROPERTIES TIMEOUT 120) set_tests_properties(test_imperative_save_load_v2 PROPERTIES TIMEOUT 120) +set_tests_properties(test_conv2d_transpose_op PROPERTIES TIMEOUT 120) set_tests_properties(test_conv3d_transpose_part2_op PROPERTIES TIMEOUT 120) +set_tests_properties(test_conv3d_transpose_op PROPERTIES TIMEOUT 120) set_tests_properties(test_prroi_pool_op PROPERTIES TIMEOUT 120) set_tests_properties(test_multiprocess_dataloader_iterable_dataset_static PROPERTIES TIMEOUT 120) set_tests_properties(test_lstm_cudnn_op PROPERTIES TIMEOUT 120) diff --git a/python/paddle/fluid/tests/unittests/test_conv2d_transpose_op.py b/python/paddle/fluid/tests/unittests/test_conv2d_transpose_op.py index bc87e76fd9..fb6058c0f0 100644 --- a/python/paddle/fluid/tests/unittests/test_conv2d_transpose_op.py +++ b/python/paddle/fluid/tests/unittests/test_conv2d_transpose_op.py @@ -17,6 +17,8 @@ from __future__ import print_function import unittest import numpy as np +import paddle +paddle.enable_static() import paddle.fluid.core as core import paddle.fluid as fluid from op_test import OpTest @@ -654,101 +656,6 @@ class TestCUDNNWithEvenUpsample_NHWC(TestWithEvenUpsample): self.op_type = "conv2d_transpose" -class TestDepthwiseConvTranspose(TestConv2DTransposeOp): - def init_test_case(self): - self.pad = [1, 1] - self.stride = [2, 2] - self.dilations = [1, 1] - self.input_size = [2, 8, 16, 16] # NCHW - self.groups = 8 - assert np.mod(self.input_size[1], self.groups) == 0 - f_c = self.input_size[1] // self.groups - self.filter_size = [self.input_size[1], f_c, 4, 4] - self.op_type = "depthwise_conv2d_transpose" - - -class TestDepthwiseConvTransposeAsymmetricPad(TestConv2DTransposeOp): - def init_test_case(self): - self.pad = [1, 0, 1, 2] - self.stride = [2, 2] - self.dilations = [1, 1] - self.input_size = [2, 8, 16, 16] # NCHW - self.groups = 8 - assert np.mod(self.input_size[1], self.groups) == 0 - f_c = self.input_size[1] // self.groups - self.filter_size = [self.input_size[1], f_c, 3, 3] - self.op_type = "depthwise_conv2d_transpose" - self.data_format = 'NCHW' - - -class TestDepthwiseConvTransposeSAMEPad(TestConv2DTransposeOp): - def init_test_case(self): - self.stride = [2, 2] - self.dilations = [1, 1] - self.input_size = [2, 8, 16, 16] # NHWC - self.groups = 8 - assert np.mod(self.input_size[1], self.groups) == 0 - f_c = self.input_size[1] // self.groups - self.filter_size = [self.input_size[1], f_c, 3, 3] - self.op_type = "depthwise_conv2d_transpose" - self.padding_algorithm = 'SAME' - - -class TestDepthwiseConvTransposeVALIDPad(TestConv2DTransposeOp): - def init_test_case(self): - self.stride = [2, 2] - self.dilations = [1, 1] - self.input_size = [2, 8, 16, 16] # NHWC - self.groups = 8 - assert np.mod(self.input_size[1], self.groups) == 0 - f_c = self.input_size[1] // self.groups - self.filter_size = [self.input_size[1], f_c, 3, 3] - self.op_type = "depthwise_conv2d_transpose" - self.padding_algorithm = 'VALID' - - -class TestDepthwiseConvTranspose_NHWC_4x4kernel(TestConv2DTransposeOp): - def init_test_case(self): - self.pad = [1, 1] - self.stride = [2, 2] - self.dilations = [1, 1] - self.input_size = [2, 16, 16, 8] # NHWC - self.groups = 8 - assert np.mod(self.input_size[3], self.groups) == 0 - f_c = self.input_size[3] // self.groups - self.filter_size = [self.input_size[3], f_c, 4, 4] - self.op_type = "depthwise_conv2d_transpose" - self.data_format = 'NHWC' - - -class TestDepthwiseConvTranspose_NHWC_3x3kernel(TestConv2DTransposeOp): - def init_test_case(self): - self.pad = [1, 1] - self.stride = [2, 2] - self.dilations = [1, 1] - self.input_size = [2, 16, 16, 8] # NHWC - self.groups = 8 - assert np.mod(self.input_size[3], self.groups) == 0 - f_c = self.input_size[3] // self.groups - self.filter_size = [self.input_size[3], f_c, 3, 3] - self.op_type = "depthwise_conv2d_transpose" - self.data_format = 'NHWC' - - -class TestDepthwiseConvTransposeAsymmetricPad_NHWC(TestConv2DTransposeOp): - def init_test_case(self): - self.pad = [1, 0, 1, 2] - self.stride = [2, 2] - self.dilations = [1, 1] - self.input_size = [2, 16, 16, 8] # NHWC - self.groups = 8 - assert np.mod(self.input_size[3], self.groups) == 0 - f_c = self.input_size[3] // self.groups - self.filter_size = [self.input_size[3], f_c, 3, 3] - self.op_type = "depthwise_conv2d_transpose" - self.data_format = 'NHWC' - - @unittest.skipIf(not core.is_compiled_with_cuda(), "core is not compiled with CUDA") class TestCUDNN_FP16(TestConv2DTransposeOp): diff --git a/python/paddle/fluid/tests/unittests/test_conv2d_transpose_op_depthwise_conv.py b/python/paddle/fluid/tests/unittests/test_conv2d_transpose_op_depthwise_conv.py new file mode 100644 index 0000000000..65c5d35fe5 --- /dev/null +++ b/python/paddle/fluid/tests/unittests/test_conv2d_transpose_op_depthwise_conv.py @@ -0,0 +1,96 @@ +# Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from __future__ import print_function + +import unittest +import numpy as np + +import paddle +paddle.enable_static() +import paddle.fluid.core as core +import paddle.fluid as fluid +from op_test import OpTest +from test_conv2d_transpose_op import TestConv2DTransposeOp + + +class TestDepthwiseConvTranspose(TestConv2DTransposeOp): + def init_test_case(self): + self.pad = [1, 1] + self.stride = [1, 1] + self.dilations = [1, 1] + self.input_size = [1, 8, 4, 4] # NCHW + self.groups = 8 + assert np.mod(self.input_size[1], self.groups) == 0 + f_c = self.input_size[1] // self.groups + self.filter_size = [self.input_size[1], f_c, 4, 4] + self.op_type = "depthwise_conv2d_transpose" + + +class TestDepthwiseConvTransposeAsymmetricPad(TestConv2DTransposeOp): + def init_test_case(self): + self.pad = [1, 1, 1, 2] + self.stride = [1, 1] + self.dilations = [1, 1] + self.input_size = [1, 8, 4, 4] # NCHW + self.groups = 8 + assert np.mod(self.input_size[1], self.groups) == 0 + f_c = self.input_size[1] // self.groups + self.filter_size = [self.input_size[1], f_c, 3, 3] + self.op_type = "depthwise_conv2d_transpose" + self.data_format = 'NCHW' + + +class TestDepthwiseConvTransposeSAMEPad(TestConv2DTransposeOp): + def init_test_case(self): + self.stride = [1, 1] + self.dilations = [1, 1] + self.input_size = [1, 8, 4, 4] # NHWC + self.groups = 8 + assert np.mod(self.input_size[1], self.groups) == 0 + f_c = self.input_size[1] // self.groups + self.filter_size = [self.input_size[1], f_c, 3, 3] + self.op_type = "depthwise_conv2d_transpose" + self.padding_algorithm = 'SAME' + + +class TestDepthwiseConvTransposeVALIDPad(TestConv2DTransposeOp): + def init_test_case(self): + self.stride = [1, 1] + self.dilations = [1, 1] + self.input_size = [1, 8, 4, 4] # NHWC + self.groups = 8 + assert np.mod(self.input_size[1], self.groups) == 0 + f_c = self.input_size[1] // self.groups + self.filter_size = [self.input_size[1], f_c, 3, 3] + self.op_type = "depthwise_conv2d_transpose" + self.padding_algorithm = 'VALID' + + +class TestDepthwiseConvTranspose_NHWC_3x3kernel(TestConv2DTransposeOp): + def init_test_case(self): + self.pad = [1, 1] + self.stride = [1, 1] + self.dilations = [1, 1] + self.input_size = [1, 4, 4, 8] # NHWC + self.groups = 8 + assert np.mod(self.input_size[3], self.groups) == 0 + f_c = self.input_size[3] // self.groups + self.filter_size = [self.input_size[3], f_c, 3, 3] + self.op_type = "depthwise_conv2d_transpose" + self.data_format = 'NHWC' + + +if __name__ == '__main__': + unittest.main() diff --git a/python/paddle/fluid/tests/unittests/test_conv3d_transpose_op.py b/python/paddle/fluid/tests/unittests/test_conv3d_transpose_op.py index 42062b1557..1e4d09c509 100644 --- a/python/paddle/fluid/tests/unittests/test_conv3d_transpose_op.py +++ b/python/paddle/fluid/tests/unittests/test_conv3d_transpose_op.py @@ -17,6 +17,8 @@ from __future__ import print_function import unittest import numpy as np +import paddle +paddle.enable_static() import paddle.fluid.core as core import paddle.fluid as fluid from op_test import OpTest @@ -207,7 +209,7 @@ class TestWithSymmetricPad(TestConv3DTransposeOp): self.stride = [1, 1, 1] self.dilations = [1, 1, 1] self.groups = 1 - self.input_size = [2, 3, 5, 5, 5] # NCDHW + self.input_size = [1, 2, 5, 5, 5] # NCDHW f_c = self.input_size[1] self.filter_size = [f_c, 6, 3, 3, 3] @@ -218,7 +220,7 @@ class TestWithAsymmetricPad(TestConv3DTransposeOp): self.stride = [1, 1, 1] self.dilations = [1, 1, 1] self.groups = 1 - self.input_size = [2, 3, 5, 5, 5] # NCDHW + self.input_size = [1, 2, 5, 5, 5] # NCDHW f_c = self.input_size[1] self.filter_size = [f_c, 6, 3, 3, 3] @@ -228,7 +230,7 @@ class TestWithSAMEPad(TestConv3DTransposeOp): self.stride = [1, 1, 2] self.dilations = [1, 2, 1] self.groups = 1 - self.input_size = [2, 3, 5, 5, 6] # NCDHW + self.input_size = [1, 2, 5, 5, 6] # NCDHW f_c = self.input_size[1] self.filter_size = [f_c, 6, 3, 3, 4] self.padding_algorithm = 'SAME' @@ -239,7 +241,7 @@ class TestWithVALIDPad(TestConv3DTransposeOp): self.stride = [2, 1, 1] self.dilations = [1, 1, 1] self.groups = 1 - self.input_size = [2, 3, 5, 5, 5] # NCDHW + self.input_size = [1, 2, 5, 5, 5] # NCDHW f_c = self.input_size[1] self.filter_size = [f_c, 6, 3, 4, 3] self.padding_algorithm = 'VALID' @@ -252,7 +254,7 @@ class TestWithStride(TestConv3DTransposeOp): self.stride = [2, 2, 2] self.dilations = [1, 1, 1] self.groups = 1 - self.input_size = [2, 3, 5, 5, 5] # NCDHW + self.input_size = [1, 2, 5, 5, 5] # NCDHW f_c = self.input_size[1] self.filter_size = [f_c, 6, 3, 3, 3] @@ -263,7 +265,7 @@ class TestWithGroups(TestConv3DTransposeOp): self.stride = [1, 1, 1] self.dilations = [1, 1, 1] self.groups = 2 - self.input_size = [2, 4, 5, 5, 5] # NCHW + self.input_size = [1, 2, 5, 5, 5] # NCHW f_c = self.input_size[1] self.filter_size = [f_c, 3, 3, 3, 3] @@ -274,7 +276,7 @@ class TestWithDilation(TestConv3DTransposeOp): self.stride = [1, 1, 1] self.dilations = [2, 2, 2] self.groups = 1 - self.input_size = [2, 3, 5, 5, 5] # NCDHW + self.input_size = [1, 2, 5, 5, 5] # NCDHW f_c = self.input_size[1] self.filter_size = [f_c, 6, 3, 3, 3] @@ -285,7 +287,7 @@ class Test_NHWC(TestConv3DTransposeOp): self.stride = [1, 1, 1] self.dilations = [1, 1, 1] self.groups = 1 - self.input_size = [2, 5, 5, 5, 3] # NDHWC + self.input_size = [1, 5, 5, 5, 2] # NDHWC f_c = self.input_size[-1] self.filter_size = [f_c, 6, 3, 3, 3] self.data_format = 'NHWC' @@ -308,7 +310,7 @@ class TestCUDNNWithSymmetricPad(TestWithSymmetricPad): self.stride = [1, 1, 1] self.dilations = [1, 1, 1] self.groups = 1 - self.input_size = [2, 3, 5, 5, 5] # NCDHW + self.input_size = [1, 2, 5, 5, 5] # NCDHW f_c = self.input_size[1] self.filter_size = [f_c, 6, 3, 3, 3] @@ -325,7 +327,7 @@ class TestCUDNNWithAsymmetricPad(TestWithAsymmetricPad): self.stride = [1, 1, 1] self.dilations = [1, 1, 1] self.groups = 1 - self.input_size = [2, 3, 4, 4, 4] # NCDHW + self.input_size = [1, 2, 4, 4, 4] # NCDHW f_c = self.input_size[1] self.filter_size = [f_c, 6, 3, 3, 3] @@ -341,7 +343,7 @@ class TestCUDNNWithSAMEPad(TestWithSAMEPad): self.stride = [1, 1, 2] self.dilations = [1, 2, 1] self.groups = 1 - self.input_size = [2, 3, 5, 5, 5] # NCDHW + self.input_size = [1, 2, 5, 5, 5] # NCDHW f_c = self.input_size[1] self.filter_size = [f_c, 6, 3, 4, 3] self.padding_algorithm = 'SAME' @@ -358,7 +360,7 @@ class TestCUDNNWithVALIDPad(TestWithVALIDPad): self.stride = [1, 1, 1] self.dilations = [1, 1, 1] self.groups = 1 - self.input_size = [2, 3, 5, 5, 5] # NCDHW + self.input_size = [1, 2, 5, 5, 5] # NCDHW f_c = self.input_size[1] self.filter_size = [f_c, 6, 3, 3, 3] self.padding_algorithm = 'VALID' @@ -376,7 +378,7 @@ class TestCUDNNWithStride(TestWithStride): self.stride = [2, 2, 2] self.dilations = [1, 1, 1] self.groups = 1 - self.input_size = [2, 3, 5, 5, 5] # NCDHW + self.input_size = [1, 2, 5, 5, 5] # NCDHW f_c = self.input_size[1] self.filter_size = [f_c, 6, 3, 3, 3] @@ -393,7 +395,7 @@ class TestCUDNNWithGroups(TestWithGroups): self.stride = [1, 1, 1] self.dilations = [1, 1, 1] self.groups = 2 - self.input_size = [2, 4, 5, 5, 5] # NCHW + self.input_size = [1, 2, 5, 5, 5] # NCHW f_c = self.input_size[1] self.filter_size = [f_c, 3, 3, 3, 3] @@ -425,7 +427,7 @@ class TestCUDNN_NHWC(TestConv3DTransposeOp): self.stride = [1, 1, 1] self.dilations = [1, 1, 1] self.groups = 1 - self.input_size = [2, 5, 5, 5, 3] # NDHWC + self.input_size = [1, 5, 5, 5, 2] # NDHWC f_c = self.input_size[-1] self.filter_size = [f_c, 6, 3, 3, 3] self.data_format = 'NHWC' @@ -443,7 +445,7 @@ class TestCUDNNWithSymmetricPad_NHWC(TestWithSymmetricPad): self.stride = [1, 1, 1] self.dilations = [1, 1, 1] self.groups = 1 - self.input_size = [2, 5, 5, 5, 3] # NDHWC + self.input_size = [1, 5, 5, 5, 2] # NDHWC f_c = self.input_size[-1] self.filter_size = [f_c, 6, 3, 3, 3] self.data_format = 'NHWC' @@ -461,7 +463,7 @@ class TestCUDNNWithAsymmetricPad_NHWC(TestWithAsymmetricPad): self.stride = [1, 1, 1] self.dilations = [1, 1, 1] self.groups = 1 - self.input_size = [2, 5, 5, 5, 3] # NDHWC + self.input_size = [1, 5, 5, 5, 2] # NDHWC f_c = self.input_size[-1] self.filter_size = [f_c, 6, 3, 3, 3] self.data_format = 'NHWC' @@ -479,7 +481,7 @@ class TestCUDNNWithStride_NHWC(TestWithStride): self.stride = [2, 2, 2] self.dilations = [1, 1, 1] self.groups = 1 - self.input_size = [2, 5, 5, 5, 3] # NCDHW + self.input_size = [1, 5, 5, 5, 2] # NDHWC f_c = self.input_size[-1] self.filter_size = [f_c, 6, 3, 3, 3] self.data_format = 'NHWC' @@ -497,7 +499,7 @@ class TestCUDNNWithGroups_NHWC(TestWithGroups): self.stride = [1, 1, 1] self.dilations = [1, 1, 1] self.groups = 2 - self.input_size = [2, 5, 5, 5, 4] # NCHW + self.input_size = [1, 5, 5, 5, 2] # NDHWC f_c = self.input_size[-1] self.filter_size = [f_c, 3, 3, 3, 3] self.data_format = 'NHWC' -- GitLab