# Conv3D¶

class paddle.fluid.dygraph.Conv3D(name_scope, num_filters, filter_size, stride=1, padding=0, dilation=1, groups=None, param_attr=None, bias_attr=None, use_cudnn=True, act=None)[source]

Convlution3D Layer

The convolution3D layer calculates the output based on the input, filter and strides, paddings, dilations, groups parameters. Input(Input) and Output(Output) are multidimensional tensors with a shape of $$[N, C, D, H, W]$$ . Where N is batch size, C is the number of channels, D is the depth of the feature, H is the height of the feature, and W is the width of the feature. Convlution3D is similar with Convlution2D but adds one dimension(depth). If bias attribution and activation type are provided, bias is added to the output of the convolution, and the corresponding activation function is applied to the final result.

For each input $$X$$, the equation is:

$Out = \sigma (W \ast X + b)$

In the above equation:

• $$X$$: Input value, a tensor with NCDHW or NDHWC format.

• $$W$$: Filter value, a tensor with MCDHW format.

• $$\ast$$: Convolution operation.

• $$b$$: Bias value, a 2-D tensor with shape [M, 1].

• $$\sigma$$: Activation function.

• $$Out$$: Output value, the shape of $$Out$$ and $$X$$ may be different.

Example

• Input:

Input shape: $$(N, C_{in}, D_{in}, H_{in}, W_{in})$$

Filter shape: $$(C_{out}, C_{in}, D_f, H_f, W_f)$$

• Output: Output shape: $$(N, C_{out}, D_{out}, H_{out}, W_{out})$$

Where

$\begin{split}D_{out}&= \frac{(D_{in} + 2 * paddings - (dilations * (D_f - 1) + 1))}{strides} + 1 \\ H_{out}&= \frac{(H_{in} + 2 * paddings - (dilations * (H_f - 1) + 1))}{strides} + 1 \\ W_{out}&= \frac{(W_{in} + 2 * paddings - (dilations * (W_f - 1) + 1))}{strides} + 1\end{split}$
Parameters
• name_scope (str) – The name for this class.

• num_filters (int) – The number of filter. It is as same as the output image channel.

• filter_size (int|tuple, optional) – The filter size. If filter_size is a tuple, it must contain three integers, (filter_size_D, filter_size_H, filter_size_W). Otherwise, the filter will be a square, filter_size_depth = filter_size_height = filter_size_width = filter_size.

• stride (int|tuple, optional) – The stride size. If stride is a tuple, it must contain three integers, (stride_D, stride_H, stride_W). Otherwise, the stride_D = stride_H = stride_W = stride. The default value is 1.

• dilation (int|tuple, optional) – The dilation size. If dilation is a tuple, it must contain three integers, (dilation_D, dilation_H, dilation_W). Otherwise, the dilation_D = dilation_H = dilation_W = dilation. The default value is 1.

• groups (int, optional) – The groups number of the Conv3d Layer. According to grouped convolution in Alex Krizhevsky’s Deep CNN paper: when group=2, the first half of the filters is only connected to the first half of the input channels, while the second half of the filters is only connected to the second half of the input channels. The default value is 1.

• param_attr (ParamAttr, optional) – The parameter attribute for learnable parameters/weights of conv3d. If it is set to None or one attribute of ParamAttr, conv3d will create ParamAttr as param_attr. If it is set to None, the parameter is initialized with $$Normal(0.0, std)$$, and the $$std$$ is $$(\frac{2.0 }{filter\_elem\_num})^{0.5}$$. The default value is None.

• bias_attr (ParamAttr|bool, optional) – The parameter attribute for the bias of conv3d. If it is set to False, no bias will be added to the output units. If it is set to None or one attribute of ParamAttr, conv3d will create ParamAttr as bias_attr. If the Initializer of the bias_attr is not set, the bias is initialized zero. The default value is None.

• use_cudnn (bool, optional) – Use cudnn kernel or not, it is valid only when the cudnn library is installed. The default value is True.

• act (str, optional) – Activation type, if it is set to None, activation is not appended. The default value is None.

Attribute:

weight (Parameter): the learnable weights of filters of this layer.

bias (Parameter): the learnable bias of this layer.

Returns

None.

Raises

ValueError – If the shapes of input, filter_size, stride, padding and groups mismatch.

Examples

import paddle.fluid as fluid
import numpy

with fluid.dygraph.guard():
data = numpy.random.random((5, 3, 12, 32, 32)).astype('float32')
conv3d = fluid.dygraph.nn.Conv3D(
'Conv3D', num_filters=2, filter_size=3, act="relu")
ret = conv3d(fluid.dygraph.base.to_variable(data))

forward(input)

Defines the computation performed at every call. Should be overridden by all subclasses.

Parameters
• *inputs (tuple) – unpacked tuple arguments

• **kwargs (dict) – unpacked dict arguments