LearnTutorialsONNX RuntimeFree Dimension Overrides

Free Dimensions Overrides

ONNX models support dynamic input shapes through free dimensions. A free dimension allows the model to accept inputs of varying sizes along that dimension. For instance, a model with input shape [batch, 3, height, width] can process any number of RGB images (3 channels) of any size.

While flexible, you can optimize performance by fixing these dimensions when your application uses consistent input sizes. For example, if your WebNN app always processes single 224Ă—224 images, you can override the free dimensions from [batch, 3, height, width] to [1, 3, 224, 224] using the freeDimensionOverrides option:

free-dimension-overrides.js
const sessionOptions = {
  freeDimensionOverrides: {
    batch: 1,
    height: 224,
    width: 224
  }
};

This configuration locks the input dimensions to specific values, potentially improving model performance.

Symbolic Dimension

No symbolic dimensions
Example model without symbolic dimensions
Symbolic dimensions
Example model with three symbolic dimensions called batch_size, height and width

WebNN Execution Provider needs specify fixed integer values via freeDimensionOverrides for all the symbolic dimensions.

See Also: