ai.onnx.Resize / README.md
Xenova's picture
Xenova HF Staff
sync 2e7068faf55e
c1dd5b3 verified
|
Raw
History Blame
5.13 kB
metadata
library_name: kernels
license: apache-2.0
tags:
  - kernel
  - webgpu
  - wgsl

ai.onnx.Resize

ai.onnx · standard ONNX operator · ONNX opset ≥ 19

Description

Resizes the input tensor by sampling neighboring input values. Output dimensions are determined by per-axis scale factors or explicit target sizes. Supports nearest, linear, and cubic interpolation with configurable coordinate transformation modes.

See the ONNX Resize spec for the reference semantics.

Inputs

Name Bind key Logical dtype Rank Shape Description Presence
X x T N-D input tensor to be resized. required

Outputs

Name Bind key Logical dtype Rank Shape Description Presence
Y y T same as X N-D output tensor after resizing. required

Attributes

Attributes and default values (overridable per request):

Attribute Default Description
mode "nearest" Interpolation mode: "nearest" (default), "linear" (bilinear/N-linear), or "cubic" (bicubic/N-cubic).
coordinate_transformation_mode "half_pixel" How to map a coordinate in the output tensor back to the input tensor; supported modes include "half_pixel", "pytorch_half_pixel", "align_corners", "asymmetric", and "tf_crop_and_resize".
nearest_mode "round_prefer_floor" Rounding strategy used when mode is "nearest": "round_prefer_floor" (default), "round_prefer_ceil", "floor", or "ceil".
cubic_coeff_a -0.75 Coefficient a in the cubic interpolation filter; the default is -0.75. Valid only when mode is "cubic".
roi [] Values of the optional roi tensor, supplied as [starts..., ends...] with one pair per input axis or per axes entry; used only by "tf_crop_and_resize".
scales [] Values of the optional scales tensor. Supply one positive value per input axis, or one per axes entry when that attribute is present; omit it when the output shape represents the exact sizes input.
extrapolation_value 0 Fill value used for out-of-bounds samples when coordinate_transformation_mode is "tf_crop_and_resize".
antialias 0 When set to 1, stretches the resampling filter during downscaling so that more input pixels contribute to each output pixel, reducing aliasing.
exclude_outside 0 When set to 1, zero-weights sampling locations that fall outside the input tensor and renormalizes the remaining weights to sum to 1.
keep_aspect_ratio_policy "stretch" How explicit sizes preserve aspect ratio. Only the default "stretch" policy is supported; "not_larger" and "not_smaller" are not yet implemented.
axes Optional axes to resize. When omitted, the scale values or requested output size apply to every input axis.

Type constraints

Variable Allowed dtypes
T float32, float16, uint8, int8

Files

Use with @huggingface/kernels

The loader automatically allocates outputs whose metadata it can derive from the manifest contract and this call.

The explicit outputs entries provide shape and logical dtype metadata for the results listed below:

  • y

Each entry either requests an optional result or supplies metadata that cannot be inferred from the inputs.

The version: 1 option selects the published kernel contract; it is independent of any operator opset, contrib since_version, or model version.

Replace each *Data placeholder with a typed array containing the corresponding input data.

import { getKernel } from "@huggingface/kernels";

const kernel = await getKernel("webgpu-kernels/ai.onnx.Resize", { version: 1 });
// Explicit destinations request optional results or supply metadata that cannot be inferred.
const { y } = await kernel({ x: { data: xData, shape: [1, 1, 2, 4] } }, {
  outputs: { y: { shape: [1, 1, 1, 2], dtype: "float32" } },
});