# oneflow.nn.Unfold¶

class oneflow.nn.Unfold(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)

This op extracts elements in a local window from input tensor, it also called img2col.

Consider a batched input tensor of shape $$(N, C, *)$$, where $$N$$ is the batch dimension, $$C$$ is the channel dimension, and $$*$$ represent arbitrary spatial dimensions. This operation flattens each sliding kernel_size-sized block within the spatial dimensions of input into a column (i.e., last dimension) of a 3-D output tensor of shape $$(N, C \times \prod(\text{kernel\_size}), L)$$, where $$C \times \prod(\text{kernel\_size})$$ is the total number of values within each block (a block has $$\prod(\text{kernel\_size})$$ spatial locations each containing a $$C$$-channeled vector), and $$L$$ is the total number of such blocks:

$L = \prod_d \left\lfloor\frac{\text{spatial\_size}[d] + 2 \times \text{padding}[d] % - \text{dilation}[d] \times (\text{kernel\_size}[d] - 1) - 1}{\text{stride}[d]} + 1\right\rfloor,$

where $$\text{spatial\_size}$$ is formed by the spatial dimensions of input ($$*$$ above), and $$d$$ is over all spatial dimensions.

Therefore, indexing output at the last dimension (column dimension) gives all values within a certain block.

Parameters
• 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, 1, 4, 4))

__init__(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
 __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__(kernel_size[, dilation, padding, …]) Initialize self. __init_subclass__ This method is called when a class is subclassed. __le__(value, /) Return self<=value. __lt__(value, /) Return self