Principle:Onnx Onnx Output Dimension Expansion
| Knowledge Sources | |
|---|---|
| Domains | Model_Composition, Shape_Manipulation |
| Last Updated | 2026-02-10 00:00 GMT |
Overview
A shape transformation mechanism that inserts an extra dimension of extent 1 into each output of an ONNX model to enable shape-compatible model composition.
Description
When composing two ONNX models, the output shapes of the first model must be compatible with the input shapes of the second model. A common mismatch occurs when the second model expects a batch dimension that the first model does not produce. Output dimension expansion resolves this by inserting Unsqueeze operations that add a dimension of size 1 at a specified index in each output tensor.
This is a graph-level transformation that modifies the model's graph by appending Unsqueeze nodes after each original output and updating the output shape specifications accordingly.
Usage
Use this principle as an optional preparation step before model merging, specifically when the second model in the composition expects an additional dimension (such as a batch dimension) in its inputs that the first model does not produce.
Theoretical Basis
Dimension expansion applies an Unsqueeze operation at a specified axis:
For a tensor with shape , inserting at index produces shape .