You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The interpolation algorithm used to fill the output tensor values.
7136
7136
7137
+
Both algorithms start with these inputs, computed for each spatial axis (based on {{MLResample2dOptions/axes}}), where `inputSize` is given by the {{MLGraphBuilder/resample2d(input, options)/input}} tensor's [=MLTensor/shape=], `outputSize` is given by {{MLResample2dOptions/sizes}} or {{MLResample2dOptions/scales}}, and `outputCoordinate` identifies the element in the output tensor being computed.
For a given `outputCoordinate.x` and `outputCoordinate.y` location in the output tensor, the above equations give a rational `inputCoordinate.x` and `inputCoordinate.y`.
The `inputCoordinate.x` and `inputCoordinate.y` computed above are used as inputs to a nearest-neighbor sampling algorithm to compute the output tensor value as follows:
7149
+
```
7150
+
x = ceil(inputCoordinate.x - 0.5)
7151
+
y = ceil(inputCoordinate.y - 0.5)
7152
+
output tensor value = input tensor value at (x, y)
7153
+
```
7154
+
7155
+
: <dfn>linear</dfn>
7156
+
::
7157
+
The `inputCoordinate.x` and `inputCoordinate.y` computed above are used as inputs to a bilinear sampling algorithm to compute the output tensor value as follows:
The specific sampling algorithms are based on those widely used in existing Machine Learning frameworks. For example, when performing {{MLInterpolationMode/linear}} resampling from the following *[4, 4]* input tensor (considering only spatial dimensions):
7269
+
7270
+
```
7271
+
[ 0 1 2 3 ]
7272
+
[ 0 1 2 3 ]
7273
+
[ 12 13 14 15 ]
7274
+
[ 12 13 14 15 ]
7275
+
```
7276
+
7277
+
For an *[8, 8]* output tensor, the expected values are:
7278
+
7279
+
```
7280
+
[ 0 0.25 0.75 1.25 1.75 2.25 2.75 3 ]
7281
+
[ 0 0.25 0.75 1.25 1.75 2.25 2.75 3 ]
7282
+
[ 0 0.25 0.75 1.25 1.75 2.25 2.75 3 ]
7283
+
[ 3 3.25 3.75 4.25 4.75 5.25 5.75 6 ]
7284
+
[ 9 9.25 9.75 10.25 10.75 11.25 11.75 12 ]
7285
+
[ 12 12.25 12.75 13.25 13.75 14.25 14.75 15 ]
7286
+
[ 12 12.25 12.75 13.25 13.75 14.25 14.75 15 ]
7287
+
[ 12 12.25 12.75 13.25 13.75 14.25 14.75 15 ]
7288
+
```
7289
+
7290
+
This has the convenient properties that the sampling is evenly distributed, symmetric, robust to image mirroring, and the corner values are aligned.
Alter the shape of a tensor to a new shape. Reshape does not copy or change the content of the tensor. It just changes the tensor's logical shape for the subsequent operations.
0 commit comments