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.export de-duplicates identical weight tensors (every zero conv bias, say) into one initializer plus Identity nodes, and some exporters emit weights as Constant nodes. onnx2torch looks weights up in graph.initializer only, so both forms fail with a KeyError on 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 of Constant nodes turned into initializers and the number of Identity aliases replaced by copied initializers. Both node kinds are removed from graph.node.

Return type:

tuple