DynamicShapeInfo
Models & Types · AiDotNet.Models
Describes which dimensions of a model’s input/output shapes are dynamic (variable at runtime).
How It Works
For Beginners: Most machine learning models have fixed input sizes (e.g., always 784 features). But some models can handle variable-sized inputs. For example, a model might accept any batch size, or a sequence model might handle different sequence lengths. This class describes which dimensions can vary and what their valid ranges are.
This follows the ONNX convention where -1 in a shape dimension means “variable at runtime”. For example, an input shape of [-1, 784] means “any number of samples, each with 784 features”.
Industry standards:
- ONNX: Uses -1 for dynamic dimensions in shape arrays
- TensorFlow Serving: Uses None/null for dynamic dimensions
- TorchServe: Uses -1 for dynamic dimensions
Constructors
| Constructor | Summary |
|---|---|
DynamicShapeInfo() |
Properties
| Property | Summary |
|---|---|
bool HasDynamicBatch { get; } |
Gets whether the batch dimension (index 0) is dynamic. |
bool HasDynamicInput { get; } |
Gets whether any input dimensions are dynamic. |
bool HasDynamicOutput { get; } |
Gets whether any output dimensions are dynamic. |
int[] DynamicInputDimensions { get; set; } |
Gets the indices of input dimensions that are variable at runtime. |
int[] DynamicOutputDimensions { get; set; } |
Gets the indices of output dimensions that are variable at runtime. |
int[] MaxInputDimensions { get; set; } |
Gets the maximum allowed values for dynamic input dimensions. |
int[] MinInputDimensions { get; set; } |
Gets the minimum allowed values for dynamic input dimensions. |
Methods
| Method | Summary |
|---|---|
bool IsValidShape(int[] concreteShape, int[] templateShape, int[] dynamicDimIndices, int[] minDimensions, int[] maxDimensions) |
Validates a concrete shape against a template shape, respecting dynamic dimensions. |
Fields
| Field | Summary |
|---|---|
DynamicShapeInfo None |
A shared instance representing no dynamic dimensions (all dimensions are fixed). |