extract_patches¶
dragon.vision.
extract_patches
(
inputs,
kernel_shape=(3, 3),
strides=1,
pads=0,
dilations=1,
padding='VALID',
data_format='NCHW',
**kwargs
)[source]¶Extract the sliding patches from input.
- If
data_format
is'NCHW'
, excepts input shape \((N, C, D1, D2, ...)\), and output shape is \((N, C \times \prod(\text{kernel\_shape}), D1_{\text{out}}, D2_{\text{out}}, ...)\). - If
data_format
is'NHWC'
, excepts input shape \((N, D1, D2, ..., C)\), and output shape is \((N, D1_{\text{out}}, D2_{\text{out}}, ..., \prod(\text{kernel\_shape}) \times C)\). - If
padding
is'VALID'
,pads
controls the explicit padding size. Otherwise, size are computed automatically use the given method.
Examples:
for i in range(3): ndim = i + 1 x = dragon.ones((1, 2) + (2,) * ndim) y = dragon.vision.extract_patches(x, kernel_shape=(2,) * ndim) assert y.shape == (1, 2 * (2 ** ndim)) + (1,) * ndim
- Parameters:
- inputs (dragon.Tensor) – The input tensor.
- kernel_shape (Sequence[int], optional, default=(3, 3)) – The shape of sliding window.
- strides (Union[int, Sequence[int]], optional, default=1) – The stride of sliding window.
- pads (Union[int, Sequence[int]], optional, default=0) – The zero padding size.
- dilations (Union[int, Sequence[int]], optional, default=1) – The dilated rate of sliding window.
- padding (str, optional, default='VALID') –
'VALID'
,'SAME'
,'SAME_UPPER'
or'SAME_LOWER'
. - data_format (str, optional, default='NCHW') –
'NCHW'
or'NHWC'
.
- Returns:
dragon.Tensor – The output tensor.
- If