test_conv3d_transpose_op.py 18.8 KB
Newer Older
1
#   Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
D
dzhwinter 已提交
2
#
D
dzhwinter 已提交
3 4 5
# 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
D
dzhwinter 已提交
6
#
D
dzhwinter 已提交
7
#     http://www.apache.org/licenses/LICENSE-2.0
D
dzhwinter 已提交
8
#
D
dzhwinter 已提交
9 10 11 12 13 14
# 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.

C
chengduoZH 已提交
15
import unittest
16

C
chengduoZH 已提交
17
import numpy as np
18

K
Kaipeng Deng 已提交
19
import paddle
20

K
Kaipeng Deng 已提交
21
paddle.enable_static()
W
wanghuancoder 已提交
22
from eager_op_test import OpTest
C
chengduoZH 已提交
23

24 25
import paddle.fluid.core as core

C
chengduoZH 已提交
26

C
chengduoZH 已提交
27
def conv3dtranspose_forward_naive(input_, filter_, attrs):
28 29
    padding_algorithm = attrs['padding_algorithm']
    if padding_algorithm not in ["SAME", "VALID", "EXPLICIT"]:
30 31 32 33
        raise ValueError(
            "Unknown Attr(padding_algorithm): '%s'. "
            "It can only be 'SAME' or 'VALID'." % str(padding_algorithm)
        )
34 35 36

    if attrs['data_format'] == 'NHWC':
        input_ = np.transpose(input_, [0, 4, 1, 2, 3])
C
chengduoZH 已提交
37
    in_n, in_c, in_d, in_h, in_w = input_.shape
38 39
    f_c, f_out_c, f_d, f_h, f_w = filter_.shape
    groups = attrs['groups']
C
chengduoZH 已提交
40
    assert in_c == f_c
41
    out_c = f_out_c * groups
M
minqiyang 已提交
42
    sub_in_c = in_c // groups
C
chengduoZH 已提交
43

44 45 46 47 48
    stride, pad, dilations = (
        attrs['strides'],
        attrs['paddings'],
        attrs['dilations'],
    )
C
chengduoZH 已提交
49

50 51
    def _get_padding_with_SAME(input_shape, kernel_size, kernel_stride):
        padding = []
52 53 54
        for input_size, filter_size, stride_size in zip(
            input_shape, kernel_size, kernel_stride
        ):
55
            out_size = int((input_size + stride_size - 1) / stride_size)
56
            pad_sum = np.max(
57 58
                ((out_size - 1) * stride_size + filter_size - input_size, 0)
            )
59 60 61 62 63 64 65 66 67 68
            pad_0 = int(pad_sum / 2)
            pad_1 = int(pad_sum - pad_0)
            padding.append(pad_0)
            padding.append(pad_1)
        return padding

    ksize = filter_.shape[2:5]
    if padding_algorithm == "VALID":
        pad = [0, 0, 0, 0, 0, 0]
    elif padding_algorithm == "SAME":
69 70
        dilations = [1, 1, 1]
        input_data_shape = input_.shape[2:5]
71 72 73 74 75 76 77 78 79 80
        pad = _get_padding_with_SAME(input_data_shape, ksize, stride)

    pad_d_0, pad_d_1 = pad[0], pad[0]
    pad_h_0, pad_h_1 = pad[1], pad[1]
    pad_w_0, pad_w_1 = pad[2], pad[2]
    if len(pad) == 6:
        pad_d_0, pad_d_1 = pad[0], pad[1]
        pad_h_0, pad_h_1 = pad[2], pad[3]
        pad_w_0, pad_w_1 = pad[4], pad[5]

C
chengduoZH 已提交
81 82 83 84 85 86
    d_bolck_d = dilations[0] * (f_d - 1) + 1
    d_bolck_h = dilations[1] * (f_h - 1) + 1
    d_bolck_w = dilations[2] * (f_w - 1) + 1
    out_d = (in_d - 1) * stride[0] + d_bolck_d
    out_h = (in_h - 1) * stride[1] + d_bolck_h
    out_w = (in_w - 1) * stride[2] + d_bolck_w
C
chengduoZH 已提交
87 88 89 90 91 92
    out = np.zeros((in_n, out_c, out_d, out_h, out_w))

    for n in range(in_n):
        for d in range(in_d):
            for i in range(in_h):
                for j in range(in_w):
93
                    for g in range(groups):
94 95 96 97 98 99
                        input_masked = input_[
                            n, g * sub_in_c : (g + 1) * sub_in_c, d, i, j
                        ]  # (c)
                        input_masked = np.reshape(
                            input_masked, (sub_in_c, 1, 1, 1)
                        )
100 101 102
                        input_masked = np.tile(input_masked, (1, f_d, f_h, f_w))

                        for k in range(f_out_c):
103 104 105 106 107 108 109 110 111 112 113
                            tmp_out = np.sum(
                                input_masked
                                * filter_[
                                    g * sub_in_c : (g + 1) * sub_in_c,
                                    k,
                                    :,
                                    :,
                                    :,
                                ],
                                axis=0,
                            )
114 115 116
                            d1, d2 = d * stride[0], d * stride[0] + d_bolck_d
                            i1, i2 = i * stride[1], i * stride[1] + d_bolck_h
                            j1, j2 = j * stride[2], j * stride[2] + d_bolck_w
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
                            out[
                                n,
                                g * f_out_c + k,
                                d1 : d2 : dilations[0],
                                i1 : i2 : dilations[1],
                                j1 : j2 : dilations[2],
                            ] += tmp_out

    out = out[
        :,
        :,
        pad_d_0 : out_d - pad_d_1,
        pad_h_0 : out_h - pad_h_1,
        pad_w_0 : out_w - pad_w_1,
    ]
132 133
    if attrs['data_format'] == 'NHWC':
        out = np.transpose(out, [0, 2, 3, 4, 1])
C
chengduoZH 已提交
134 135 136
    return out


W
wanghuancoder 已提交
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
def conv3d_transpose_wrapper(
    x,
    weight,
    stride=1,
    padding=0,
    output_padding=[],
    output_size=[],
    padding_algorithm="EXPLICIT",
    groups=1,
    dilation=1,
    data_format="NCDHW",
):
    if data_format == "AnyLayout":
        data_format = "NCDHW"
    return paddle._C_ops.conv3d_transpose(
        x,
        weight,
        stride,
        padding,
        output_padding,
        output_size,
        padding_algorithm,
        groups,
        dilation,
        data_format,
    )


C
cnn 已提交
165
class TestConv3DTransposeOp(OpTest):
C
chengduoZH 已提交
166 167
    def setUp(self):
        # init as conv transpose
168
        self.use_cudnn = False
169 170
        self.check_no_input = False
        self.check_no_filter = False
171 172 173
        self.data_format = 'NCHW'
        self.pad = [0, 0, 0]
        self.padding_algorithm = "EXPLICIT"
C
chengduoZH 已提交
174 175 176 177 178 179 180 181 182 183
        self.init_op_type()
        self.init_test_case()

        input_ = np.random.random(self.input_size).astype("float32")
        filter_ = np.random.random(self.filter_size).astype("float32")

        self.inputs = {'Input': input_, 'Filter': filter_}
        self.attrs = {
            'strides': self.stride,
            'paddings': self.pad,
184
            'padding_algorithm': self.padding_algorithm,
185
            'dilations': self.dilations,
186
            'groups': self.groups,
187
            'use_cudnn': self.use_cudnn,
188
            'data_format': self.data_format,
C
chengduoZH 已提交
189
        }
C
chengduoZH 已提交
190

191 192 193
        output = conv3dtranspose_forward_naive(
            input_, filter_, self.attrs
        ).astype("float32")
C
chengduoZH 已提交
194

C
chengduoZH 已提交
195 196 197
        self.outputs = {'Output': output}

    def test_check_output(self):
198 199 200 201 202
        if self.use_cudnn:
            place = core.CUDAPlace(0)
            self.check_output_with_place(place, atol=1e-5)
        else:
            self.check_output()
C
chengduoZH 已提交
203 204

    def test_check_grad(self):
205 206
        if self.use_cudnn:
            place = core.CUDAPlace(0)
207 208 209 210 211 212
            self.check_grad_with_place(
                place,
                set(['Input', 'Filter']),
                'Output',
                max_relative_error=0.03,
            )
213
        else:
214 215 216
            self.check_grad(
                set(['Input', 'Filter']), 'Output', max_relative_error=0.03
            )
C
chengduoZH 已提交
217 218

    def test_check_grad_no_filter(self):
219 220
        if self.use_cudnn:
            place = core.CUDAPlace(0)
221 222 223 224 225 226 227
            self.check_grad_with_place(
                place,
                ['Input'],
                'Output',
                max_relative_error=0.03,
                no_grad_set=set(['Filter']),
            )
228
        elif self.check_no_filter:
229 230 231 232 233 234
            self.check_grad(
                ['Input'],
                'Output',
                max_relative_error=0.03,
                no_grad_set=set(['Filter']),
            )
C
chengduoZH 已提交
235 236

    def test_check_grad_no_input(self):
237 238
        if self.use_cudnn:
            place = core.CUDAPlace(0)
239 240 241 242 243 244 245
            self.check_grad_with_place(
                place,
                ['Filter'],
                'Output',
                max_relative_error=0.03,
                no_grad_set=set(['Input']),
            )
246
        elif self.check_no_input:
247 248 249 250 251 252
            self.check_grad(
                ['Filter'],
                'Output',
                max_relative_error=0.03,
                no_grad_set=set(['Input']),
            )
C
chengduoZH 已提交
253 254 255 256 257

    def init_test_case(self):
        self.pad = [0, 0, 0]
        self.stride = [1, 1, 1]
        self.dilations = [1, 1, 1]
258
        self.groups = 1
C
chengduoZH 已提交
259
        self.input_size = [2, 3, 5, 5, 5]  # NCDHW
C
chengduoZH 已提交
260 261 262 263
        f_c = self.input_size[1]
        self.filter_size = [f_c, 6, 3, 3, 3]

    def init_op_type(self):
C
chengduoZH 已提交
264
        self.op_type = "conv3d_transpose"
W
wanghuancoder 已提交
265
        self.python_api = conv3d_transpose_wrapper
C
chengduoZH 已提交
266 267


C
cnn 已提交
268
class TestWithSymmetricPad(TestConv3DTransposeOp):
C
chengduoZH 已提交
269
    def init_test_case(self):
270
        self.check_no_input = True
C
chengduoZH 已提交
271 272 273
        self.pad = [1, 1, 1]
        self.stride = [1, 1, 1]
        self.dilations = [1, 1, 1]
274
        self.groups = 1
K
Kaipeng Deng 已提交
275
        self.input_size = [1, 2, 5, 5, 5]  # NCDHW
C
chengduoZH 已提交
276 277 278 279
        f_c = self.input_size[1]
        self.filter_size = [f_c, 6, 3, 3, 3]


C
cnn 已提交
280
class TestWithAsymmetricPad(TestConv3DTransposeOp):
281 282 283 284 285
    def init_test_case(self):
        self.pad = [1, 0, 1, 0, 1, 2]
        self.stride = [1, 1, 1]
        self.dilations = [1, 1, 1]
        self.groups = 1
K
Kaipeng Deng 已提交
286
        self.input_size = [1, 2, 5, 5, 5]  # NCDHW
287 288 289 290
        f_c = self.input_size[1]
        self.filter_size = [f_c, 6, 3, 3, 3]


C
cnn 已提交
291
class TestWithSAMEPad(TestConv3DTransposeOp):
292
    def init_test_case(self):
293 294
        self.stride = [1, 1, 2]
        self.dilations = [1, 2, 1]
295
        self.groups = 1
K
Kaipeng Deng 已提交
296
        self.input_size = [1, 2, 5, 5, 6]  # NCDHW
297
        f_c = self.input_size[1]
298
        self.filter_size = [f_c, 6, 3, 3, 4]
299 300 301
        self.padding_algorithm = 'SAME'


C
cnn 已提交
302
class TestWithVALIDPad(TestConv3DTransposeOp):
303
    def init_test_case(self):
304
        self.stride = [2, 1, 1]
305 306
        self.dilations = [1, 1, 1]
        self.groups = 1
K
Kaipeng Deng 已提交
307
        self.input_size = [1, 2, 5, 5, 5]  # NCDHW
308
        f_c = self.input_size[1]
309
        self.filter_size = [f_c, 6, 3, 4, 3]
310 311 312
        self.padding_algorithm = 'VALID'


C
cnn 已提交
313
class TestWithStride(TestConv3DTransposeOp):
314
    def init_test_case(self):
315
        self.check_no_filter = True
316
        self.pad = [1, 1, 1]
317
        self.stride = [2, 2, 2]
318
        self.dilations = [1, 1, 1]
319
        self.groups = 1
K
Kaipeng Deng 已提交
320
        self.input_size = [1, 2, 5, 5, 5]  # NCDHW
321
        f_c = self.input_size[1]
322
        self.filter_size = [f_c, 6, 3, 3, 3]
323 324


C
cnn 已提交
325
class TestWithGroups(TestConv3DTransposeOp):
C
chengduoZH 已提交
326 327
    def init_test_case(self):
        self.pad = [1, 1, 1]
328
        self.stride = [1, 1, 1]
C
chengduoZH 已提交
329
        self.dilations = [1, 1, 1]
330
        self.groups = 2
K
Kaipeng Deng 已提交
331
        self.input_size = [1, 2, 5, 5, 5]  # NCHW
C
chengduoZH 已提交
332
        f_c = self.input_size[1]
333
        self.filter_size = [f_c, 3, 3, 3, 3]
C
chengduoZH 已提交
334 335


C
cnn 已提交
336
class TestWithDilation(TestConv3DTransposeOp):
C
chengduoZH 已提交
337 338 339 340
    def init_test_case(self):
        self.pad = [1, 1, 1]
        self.stride = [1, 1, 1]
        self.dilations = [2, 2, 2]
341
        self.groups = 1
K
Kaipeng Deng 已提交
342
        self.input_size = [1, 2, 5, 5, 5]  # NCDHW
C
chengduoZH 已提交
343 344 345 346
        f_c = self.input_size[1]
        self.filter_size = [f_c, 6, 3, 3, 3]


C
cnn 已提交
347
class Test_NHWC(TestConv3DTransposeOp):
348 349 350 351 352
    def init_test_case(self):
        self.pad = [0, 0, 0]
        self.stride = [1, 1, 1]
        self.dilations = [1, 1, 1]
        self.groups = 1
K
Kaipeng Deng 已提交
353
        self.input_size = [1, 5, 5, 5, 2]  # NDHWC
354 355 356 357 358
        f_c = self.input_size[-1]
        self.filter_size = [f_c, 6, 3, 3, 3]
        self.data_format = 'NHWC'


C
chengduoZH 已提交
359
# ------------ test_cudnn ------------
360 361 362
@unittest.skipIf(
    not core.is_compiled_with_cuda(), "core is not compiled with CUDA"
)
C
cnn 已提交
363
class TestCUDNN(TestConv3DTransposeOp):
C
chengduoZH 已提交
364
    def init_op_type(self):
365 366
        self.use_cudnn = True
        self.op_type = "conv3d_transpose"
W
wanghuancoder 已提交
367
        self.python_api = conv3d_transpose_wrapper
C
chengduoZH 已提交
368 369


370 371 372
@unittest.skipIf(
    not core.is_compiled_with_cuda(), "core is not compiled with CUDA"
)
373
class TestCUDNNWithSymmetricPad(TestWithSymmetricPad):
C
chengduoZH 已提交
374 375 376 377
    def init_test_case(self):
        self.pad = [1, 1, 1]
        self.stride = [1, 1, 1]
        self.dilations = [1, 1, 1]
378
        self.groups = 1
K
Kaipeng Deng 已提交
379
        self.input_size = [1, 2, 5, 5, 5]  # NCDHW
C
chengduoZH 已提交
380 381 382 383
        f_c = self.input_size[1]
        self.filter_size = [f_c, 6, 3, 3, 3]

    def init_op_type(self):
384 385
        self.use_cudnn = True
        self.op_type = "conv3d_transpose"
W
wanghuancoder 已提交
386
        self.python_api = conv3d_transpose_wrapper
C
chengduoZH 已提交
387 388


389 390 391
@unittest.skipIf(
    not core.is_compiled_with_cuda(), "core is not compiled with CUDA"
)
392 393 394 395 396 397
class TestCUDNNWithAsymmetricPad(TestWithAsymmetricPad):
    def init_test_case(self):
        self.pad = [1, 1, 1, 0, 0, 2]
        self.stride = [1, 1, 1]
        self.dilations = [1, 1, 1]
        self.groups = 1
K
Kaipeng Deng 已提交
398
        self.input_size = [1, 2, 4, 4, 4]  # NCDHW
399 400 401 402 403 404
        f_c = self.input_size[1]
        self.filter_size = [f_c, 6, 3, 3, 3]

    def init_op_type(self):
        self.use_cudnn = True
        self.op_type = "conv3d_transpose"
W
wanghuancoder 已提交
405
        self.python_api = conv3d_transpose_wrapper
406 407


408 409 410
@unittest.skipIf(
    not core.is_compiled_with_cuda(), "core is not compiled with CUDA"
)
411 412
class TestCUDNNWithSAMEPad(TestWithSAMEPad):
    def init_test_case(self):
413 414
        self.stride = [1, 1, 2]
        self.dilations = [1, 2, 1]
415
        self.groups = 1
K
Kaipeng Deng 已提交
416
        self.input_size = [1, 2, 5, 5, 5]  # NCDHW
417
        f_c = self.input_size[1]
418
        self.filter_size = [f_c, 6, 3, 4, 3]
419 420 421 422 423
        self.padding_algorithm = 'SAME'

    def init_op_type(self):
        self.use_cudnn = True
        self.op_type = "conv3d_transpose"
W
wanghuancoder 已提交
424
        self.python_api = conv3d_transpose_wrapper
425 426


427 428 429
@unittest.skipIf(
    not core.is_compiled_with_cuda(), "core is not compiled with CUDA"
)
430 431 432 433 434
class TestCUDNNWithVALIDPad(TestWithVALIDPad):
    def init_test_case(self):
        self.stride = [1, 1, 1]
        self.dilations = [1, 1, 1]
        self.groups = 1
K
Kaipeng Deng 已提交
435
        self.input_size = [1, 2, 5, 5, 5]  # NCDHW
436 437 438 439 440 441 442
        f_c = self.input_size[1]
        self.filter_size = [f_c, 6, 3, 3, 3]
        self.padding_algorithm = 'VALID'

    def init_op_type(self):
        self.use_cudnn = True
        self.op_type = "conv3d_transpose"
W
wanghuancoder 已提交
443
        self.python_api = conv3d_transpose_wrapper
444 445


446 447 448
@unittest.skipIf(
    not core.is_compiled_with_cuda(), "core is not compiled with CUDA"
)
449
class TestCUDNNWithStride(TestWithStride):
C
chengduoZH 已提交
450 451 452 453
    def init_test_case(self):
        self.pad = [1, 1, 1]
        self.stride = [2, 2, 2]
        self.dilations = [1, 1, 1]
454
        self.groups = 1
K
Kaipeng Deng 已提交
455
        self.input_size = [1, 2, 5, 5, 5]  # NCDHW
C
chengduoZH 已提交
456 457 458 459
        f_c = self.input_size[1]
        self.filter_size = [f_c, 6, 3, 3, 3]

    def init_op_type(self):
460 461
        self.use_cudnn = True
        self.op_type = "conv3d_transpose"
W
wanghuancoder 已提交
462
        self.python_api = conv3d_transpose_wrapper
C
chengduoZH 已提交
463 464


465 466 467
@unittest.skipIf(
    not core.is_compiled_with_cuda(), "core is not compiled with CUDA"
)
468 469 470 471 472 473
class TestCUDNNWithGroups(TestWithGroups):
    def init_test_case(self):
        self.pad = [1, 1, 1]
        self.stride = [1, 1, 1]
        self.dilations = [1, 1, 1]
        self.groups = 2
K
Kaipeng Deng 已提交
474
        self.input_size = [1, 2, 5, 5, 5]  # NCHW
475 476 477 478 479 480
        f_c = self.input_size[1]
        self.filter_size = [f_c, 3, 3, 3, 3]

    def init_op_type(self):
        self.use_cudnn = True
        self.op_type = "conv3d_transpose"
W
wanghuancoder 已提交
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496
        self.python_api = conv3d_transpose_wrapper

        # Please Don't remove the following code.
        # Currently, CI use cudnn V5.0 which not support dilation conv.
        # class TestCUDNNWithDilation(TestWithDilation):
        #     def init_test_case(self):
        #         self.pad = [1, 1, 1]
        #         self.stride = [2, 2, 2]
        #         self.dilations = [2, 2, 2]
        #         self.input_size = [2, 3, 5, 5, 5]  # NCDHW
        #         f_c = self.input_size[1]
        #         self.filter_size = [f_c, 6, 3, 3, 3]
        #
        #     def init_op_type(self):
        #         self.op_type = "conv3d_transpose"
        self.python_api = conv3d_transpose_wrapper
C
chengduoZH 已提交
497

498

499 500 501
@unittest.skipIf(
    not core.is_compiled_with_cuda(), "core is not compiled with CUDA"
)
C
cnn 已提交
502
class TestCUDNN_NHWC(TestConv3DTransposeOp):
503 504 505 506 507
    def init_test_case(self):
        self.pad = [0, 0, 0]
        self.stride = [1, 1, 1]
        self.dilations = [1, 1, 1]
        self.groups = 1
K
Kaipeng Deng 已提交
508
        self.input_size = [1, 5, 5, 5, 2]  # NDHWC
509 510 511 512 513 514 515
        f_c = self.input_size[-1]
        self.filter_size = [f_c, 6, 3, 3, 3]
        self.data_format = 'NHWC'

    def init_op_type(self):
        self.use_cudnn = True
        self.op_type = "conv3d_transpose"
W
wanghuancoder 已提交
516
        self.python_api = conv3d_transpose_wrapper
517 518


519 520 521
@unittest.skipIf(
    not core.is_compiled_with_cuda(), "core is not compiled with CUDA"
)
522 523 524 525 526 527
class TestCUDNNWithSymmetricPad_NHWC(TestWithSymmetricPad):
    def init_test_case(self):
        self.pad = [1, 1, 1]
        self.stride = [1, 1, 1]
        self.dilations = [1, 1, 1]
        self.groups = 1
K
Kaipeng Deng 已提交
528
        self.input_size = [1, 5, 5, 5, 2]  # NDHWC
529 530 531 532 533 534 535
        f_c = self.input_size[-1]
        self.filter_size = [f_c, 6, 3, 3, 3]
        self.data_format = 'NHWC'

    def init_op_type(self):
        self.use_cudnn = True
        self.op_type = "conv3d_transpose"
W
wanghuancoder 已提交
536
        self.python_api = conv3d_transpose_wrapper
537 538


539 540 541
@unittest.skipIf(
    not core.is_compiled_with_cuda(), "core is not compiled with CUDA"
)
542 543 544 545 546 547
class TestCUDNNWithAsymmetricPad_NHWC(TestWithAsymmetricPad):
    def init_test_case(self):
        self.pad = [1, 0, 1, 0, 0, 2]
        self.stride = [1, 1, 1]
        self.dilations = [1, 1, 1]
        self.groups = 1
K
Kaipeng Deng 已提交
548
        self.input_size = [1, 5, 5, 5, 2]  # NDHWC
549 550 551 552 553 554 555
        f_c = self.input_size[-1]
        self.filter_size = [f_c, 6, 3, 3, 3]
        self.data_format = 'NHWC'

    def init_op_type(self):
        self.use_cudnn = True
        self.op_type = "conv3d_transpose"
W
wanghuancoder 已提交
556
        self.python_api = conv3d_transpose_wrapper
557 558


559 560 561
@unittest.skipIf(
    not core.is_compiled_with_cuda(), "core is not compiled with CUDA"
)
562 563 564 565 566 567
class TestCUDNNWithStride_NHWC(TestWithStride):
    def init_test_case(self):
        self.pad = [1, 1, 1]
        self.stride = [2, 2, 2]
        self.dilations = [1, 1, 1]
        self.groups = 1
K
Kaipeng Deng 已提交
568
        self.input_size = [1, 5, 5, 5, 2]  # NDHWC
569 570 571 572 573 574 575
        f_c = self.input_size[-1]
        self.filter_size = [f_c, 6, 3, 3, 3]
        self.data_format = 'NHWC'

    def init_op_type(self):
        self.use_cudnn = True
        self.op_type = "conv3d_transpose"
W
wanghuancoder 已提交
576
        self.python_api = conv3d_transpose_wrapper
577 578


579 580 581
@unittest.skipIf(
    not core.is_compiled_with_cuda(), "core is not compiled with CUDA"
)
582 583 584 585 586 587
class TestCUDNNWithGroups_NHWC(TestWithGroups):
    def init_test_case(self):
        self.pad = [1, 1, 1]
        self.stride = [1, 1, 1]
        self.dilations = [1, 1, 1]
        self.groups = 2
K
Kaipeng Deng 已提交
588
        self.input_size = [1, 5, 5, 5, 2]  # NDHWC
589 590 591 592 593 594 595
        f_c = self.input_size[-1]
        self.filter_size = [f_c, 3, 3, 3, 3]
        self.data_format = 'NHWC'

    def init_op_type(self):
        self.use_cudnn = True
        self.op_type = "conv3d_transpose"
W
wanghuancoder 已提交
596
        self.python_api = conv3d_transpose_wrapper
597 598


599 600 601 602 603 604 605 606 607 608 609 610 611
class TestConv3dTranspose(unittest.TestCase):
    def error_weight_input(self):
        array = np.array([1], dtype=np.float32)
        x = paddle.to_tensor(
            np.reshape(array, [1, 1, 1, 1, 1]), dtype='float32'
        )
        weight = paddle.to_tensor(np.reshape(array, [1]), dtype='float32')
        paddle.nn.functional.conv3d_transpose(x, weight, bias=0)

    def test_type_error(self):
        self.assertRaises(ValueError, self.error_weight_input)


C
chengduoZH 已提交
612 613
if __name__ == '__main__':
    unittest.main()