# oneflow.nn.Fold¶

class oneflow.nn.Fold(output_size: Union[int, Tuple[int, int]], kernel_size: Union[int, Tuple[int, int]], dilation: Union[int, Tuple[int, int]] = 1, padding: Union[int, Tuple[int, int]] = 0, stride: Union[int, Tuple[int, int]] = 1)

Combines an array of sliding local blocks into a large containing tensor, it also called col2img.

Consider a batched input tensor containing sliding local blocks, e.g., patches of images, of shape $$(N, C \times \prod(\text{kernel\_size}), L)$$, where $$N$$ is batch dimension, $$C \times \prod(\text{kernel\_size})$$ is the number of values within a block (a block has $$\prod(\text{kernel\_size})$$ spatial locations each containing a $$C$$-channeled vector), and $$L$$ is the total number of blocks. (This is exactly the same specification as the output shape of Unfold.) This operation combines these local blocks into the large output tensor of shape $$(N, C, \text{output\_size}[0], \text{output\_size}[1], \dots)$$ by summing the overlapping values. Similar to Unfold, the arguments must satisfy

$L = \prod_d \left\lfloor\frac{\text{output\_size}[d] + 2 \times \text{padding}[d] % - \text{dilation}[d] \times (\text{kernel\_size}[d] - 1) - 1}{\text{stride}[d]} + 1\right\rfloor,$
Parameters
• output_size (_size_2_t) – The spatial dimension of output tensor.

• kernel_size (_size_2_t) – The size of kernel.

• dilation (_size_2_t, optional) – The dilation rate. Defaults to 1.

• stride (_size_2_t, optional) – The stride of sliding window. Defaults to 1.

For example:

>>> import oneflow as flow
>>> import numpy as np

>>> x_tensor = flow.Tensor(np.random.randn(1, 9, 16))
>>> fold = flow.nn.Fold(output_size=(4, 4), kernel_size=3, padding=1)
>>> out = fold(x_tensor)
>>> out.shape
oneflow.Size([1, 1, 4, 4])

__init__(output_size: Union[int, Tuple[int, int]], kernel_size: Union[int, Tuple[int, int]], dilation: Union[int, Tuple[int, int]] = 1, padding: Union[int, Tuple[int, int]] = 0, stride: Union[int, Tuple[int, int]] = 1)None

Initialize self. See help(type(self)) for accurate signature.

Methods

 __call__(*args, **kwargs) Call self as a function. __delattr__(name, /) Implement delattr(self, name). __dir__() Default dir() implementation. __eq__(value, /) Return self==value. __format__(format_spec, /) Default object formatter. __ge__(value, /) Return self>=value. __getattr__(name) __getattribute__(name, /) Return getattr(self, name). __gt__(value, /) Return self>value. __hash__() Return hash(self). __init__(output_size, kernel_size[, …]) Initialize self. __init_subclass__ This method is called when a class is subclassed. __le__(value, /) Return self<=value. __lt__(value, /) Return self