The resampling primitive computes forward or backward resampling operation on 1D, 2D, or 3D spatial data. Resampling performs spatial scaling of original tensor using one of the supported interpolation algorithms:
Resampling operation is defined by the source tensor and scaling factors in each spatial dimension. Upsampling and downsampling are the alternative terms for resampling that are used when all scaling factors are greater (upsampling) or less (downsampling) than one.
The resampling operation is defined by the following formulas. We show formulas only for 2D spatial data which are straightforward to generalize to cases of higher and lower dimensions. Variable names follow the standard Naming Conventions.
Let \(\src\) and \(\dst\) be \(N \times C \times IH \times IW\) and \(N \times C \times OH \times OW\) tensors respectively. Let \( F_h = \frac{OH}{IH} \) and \( F_w = \frac{OW}{IW} \) define scaling factors in each spatial dimension.
The following formulas show how oneDNN computes resampling for nearest neighbor and bilinear interpolation methods. To further simplify the formulas, we assume the following:
\[\dst(n, c, oh, ow) = \src(n, c, ih, iw)\]
where
\[ \dst(n, c, oh, ow) = \src(n, c, ih_0, iw_0) \cdot W_{ih} \cdot W_{iw} + \\ \src(n, c, ih_1, iw_0) \cdot (1 - W_{ih}) \cdot W_{iw} + \\ \src(n, c, ih_0, iw_1) \cdot W_{ih} \cdot (1 - W_{iw}) + \\ \src(n, c, ih_1, iw_1) \cdot (1 - W_{ih}) \cdot (1 - W_{iw}) \\ \]
where
There is no difference between the dnnl_forward_training and dnnl_forward_inference propagation kinds.
The backward propagation computes \(\diffsrc\) based on \(\diffdst\).
When executed, the inputs and outputs should be mapped to an execution argument index as specified by the following table.
Primitive input/output | Execution argument index |
---|---|
\(\src\) | DNNL_ARG_SRC |
\(\dst\) | DNNL_ARG_DST |
\(\diffsrc\) | DNNL_ARG_DIFF_SRC |
\(\diffdst\) | DNNL_ARG_DIFF_DST |
src
and dst
are expected to be the same. Resampling primitive supports dst
and diff_src
memory tag dnnl::memory::format_tag::any and can define destination format based on source format.Resampling primitive supports the following combination of data types for source and destination memory objects:
Propagation | Source / Destination |
---|---|
forward / backward | f32, bf16 |
forward | f16, s8, u8 |
The resampling primitive does not support any post-ops or attributes.
N/A
Engine | Name | Com |
---|---|---|
CPU/GPU | Resampling Primitive Example | This C++ API example demonstrates how to create and execute a Resampling primitive in forward training propagation mode. |