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:
const sessionOptions = {
freeDimensionOverrides: {
batch: 1,
height: 224,
width: 224
}
};This configuration locks the input dimensions to specific values, potentially improving model performance.
Symbolic Dimension


batch_size, height and widthWebNN Execution Provider needs specify fixed integer values via freeDimensionOverrides for all the symbolic dimensions to avoid fallbacks.