peal.architectures.onnx_predictor.normalize_onnx_graph¶
- peal.architectures.onnx_predictor.normalize_onnx_graph(model)[source]¶
Rewrite an ONNX model in place so onnx2torch accepts it.
torch.onnx.exportde-duplicates identical weight tensors (every zero conv bias, say) into one initializer plusIdentitynodes, and some exporters emit weights asConstantnodes. onnx2torch looks weights up ingraph.initializeronly, so both forms fail with aKeyErroron the aliased name. Returns(model, n_constants_moved, n_identities_resolved).- Parameters:
model (
onnx.ModelProto) – Loaded model; its graph is modified in place.- Returns:
(model, n_constants_moved, n_identities_resolved): the same model object, the number ofConstantnodes turned into initializers and the number ofIdentityaliases replaced by copied initializers. Both node kinds are removed fromgraph.node.- Return type: