OnnxWeightLoader
Utility for loading ONNX model initializers (weights) into SKaiNET Module parameters.
Features:
ONNX-specific tensor decoding (FLOAT, INT32, INT64)
Format-agnostic weight mapping via WeightMapper
Support for multiple tensor data types (all converted to Float)
Debug mode for troubleshooting weight mapping issues
Example usage:
val model = ModelProto.decodeFromByteArray(bytes)
val ctx = DirectCpuExecutionContext(phase = Phase.INFERENCE)
val loadResult = OnnxWeightLoader.loadInitializers(model, ctx)
val mapping = OnnxWeightLoader.applyWeights(module, loadResult.tensors)Types
Result of loading initializers from an ONNX model.
Functions
Apply ONNX weights to a module using name-based matching with shape-based fallback.
Apply weights from legacy InitTensor list.
Apply weights with optional debug output.
Decode a single ONNX TensorProto into a WeightTensor.
Extract the most specific "model.X.Y.Z" pattern from a DSL module path. E.g., "Yolo8/model.22.cv2.0/model.22.cv2.0.0/Conv2d-0" -> "model.22.cv2.0.0"
Load all initializers (weights) from an ONNX ModelProto.
Load initializers returning the legacy InitializerLoadResult type.
Check if an ONNX tensor name matches a DSL layer name.
Normalize a DSL layer name to ONNX naming format. DSL uses underscores in some places while ONNX uses dots.
Validate that all module parameters were mapped from ONNX initializers. Throws IllegalArgumentException if mapping is incomplete.