ai.onnx.LpPool

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

Description

Applies Lp pooling over a spatial input tensor by computing the Lp norm within each kernel window and writing the result to the output. Output spatial dimensions are determined by the kernel size, strides, padding, and ceil_mode; p controls which norm is used (e.g. p=1 for sum-of-absolutes, p=2 for Euclidean).

See the ONNX LpPool spec for the reference semantics.

Inputs

Name Upstream name Logical dtype Rank Shape Description Presence
x X T Input tensor of shape (N x C x D1 x ... x Dn); for images the spatial axes are H and W. required

Outputs

Name Upstream name Logical dtype Rank Shape Description Presence
y Y T same as x derived Output tensor after Lp pooling; spatial dimensions vary with kernel, stride, and pad settings. required

Attributes

Attributes and default values (overridable per request):

Attribute Default Description
auto_pad "NOTSET" Deprecated auto-padding mode (NOTSET, SAME_UPPER, SAME_LOWER, or VALID). It cannot be used together with pads.
ceil_mode 0 When non-zero, uses ceil instead of floor to compute output spatial dimensions.
dilations Dilation along each spatial axis. When omitted, every dilation is 1.
kernel_shape Required kernel shape, with one positive value per spatial axis.
p 2 The exponent of the Lp norm used for pooling; default 2 gives Euclidean (L2) pooling.
pads Padding at the beginning and end of each spatial axis, ordered as [begin_0, ..., begin_n, end_0, ..., end_n]. When omitted, every pad is 0.
strides Stride along each spatial axis. When omitted, every stride is 1.

Type constraints

Variable Allowed dtypes
T float32, float16

Files

Use with @huggingface/kernels

npm install --save-exact @huggingface/kernels@0.0.1-preview.2

Required output shapes and logical data types are inferred from the supplied inputs and attributes; result tensors are allocated automatically.

The version: 1 option selects the published kernel contract; it is independent of any operator opset, contrib since_version, or model version. It follows the v1 branch as fixes land. To pin exact artifact bytes, pass a 40-character commit revision instead of 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.LpPool", { version: 1 });
const { y } = await kernel({ x: { data: xData, shape: [1, 1, 4] } }, {
  attrs: { kernel_shape: [3] },
});
Downloads last month
-
kernel
webgpu
wgsl
apache-2.0
WebGPU

Requires WebGPU support. See the compatibility table.