- paddle.sparse.nn.functional. conv3d ( x, weight, bias=None, stride=1, padding=0, dilation=1, groups=1, data_format='NDHWC', name=None ) [source]
The sparse convolution3d functional calculates the output based on the input, filter and strides, paddings, dilations, groups parameters. Input(Input) and Output(Output) are multidimensional SparseCooTensors with a shape of \([N, D, H, W, C]\) . 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. If bias attribution is provided, bias is added to the output of the convolution.
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 1-D tensor with shape [M].
\(Out\): Output value, the shape of \(Out\) and \(X\) may be different.
x (Tensor) – The input is 5-D SparseCooTensor with shape [N, D, H, W, C], the data type of input is float16 or float32 or float64.
weight (Tensor) – The convolution kernel, a Tensor with shape [kD, kH, kW, C/g, M], where M is the number of filters(output channels), g is the number of groups, kD, kH, kW are the filter’s depth, height and width respectively.
bias (Tensor, optional) – The bias, a Tensor of shape [M].
stride (int|list|tuple, optional) – The stride size. It means the stride in convolution. If stride is a list/tuple, it must contain three integers, (stride_depth, stride_height, stride_width). Otherwise, stride_depth = stride_height = stride_width = stride. Default: stride = 1.
padding (string|int|list|tuple, optional) – The padding size. It means the number of zero-paddings on both sides for each dimension. If padding is a string, either ‘VALID’ or ‘SAME’ which is the padding algorithm. If padding size is a tuple or list, it could be in three forms: [pad_depth, pad_height, pad_width] or [pad_depth_front, pad_depth_back, pad_height_top, pad_height_bottom, pad_width_left, pad_width_right], and when data_format is “NCDHW”, padding can be in the form [[0,0], [0,0], [pad_depth_front, pad_depth_back], [pad_height_top, pad_height_bottom], [pad_width_left, pad_width_right]]. when data_format is “NDHWC”, padding can be in the form [[0,0], [pad_depth_front, pad_depth_back], [pad_height_top, pad_height_bottom], [pad_width_left, pad_width_right], [0,0]]. Default: padding = 0.
dilation (int|list|tuple, optional) – The dilation size. It means the spacing between the kernel points. If dilation is a list/tuple, it must contain three integers, (dilation_depth, dilation_height, dilation_width). Otherwise, dilation_depth = dilation_height = dilation_width = dilation. Default: dilation = 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. Default: groups=1. Currently, only support groups=1.
data_format (str, optional) – Specify the data format of the input, and the data format of the output will be consistent with that of the input. An optional string from: “NCDHW”, “NDHWC”. The default is “NDHWC”. When it is “NDHWC”, the data is stored in the order of: [batch_size, input_depth, input_height, input_width, input_channels].
name (str, optional) – For detailed information, please refer to Name. Usually name is no need to set and None by default.
A SparseCooTensor representing the conv3d, whose data type is the same with input.
import paddle indices = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 1, 2], [1, 3, 2, 3]] values = [, , , ] indices = paddle.to_tensor(indices, dtype='int32') values = paddle.to_tensor(values, dtype='float32') dense_shape = [1, 1, 3, 4, 1] sparse_x = paddle.sparse.sparse_coo_tensor(indices, values, dense_shape, stop_gradient=True) weight = paddle.randn((1, 3, 3, 1, 1), dtype='float32') y = paddle.sparse.nn.functional.conv3d(sparse_x, weight) print(y.shape) # (1, 1, 1, 2, 1)