peal.architectures.onnx_predictor.find_final_linear

peal.architectures.onnx_predictor.find_final_linear(path)[source]

Locate the classifier’s final linear layer in an ONNX graph.

Walks back from the (single) graph output through pass-through ops and at most one constant-index Gather on the last axis (the output selection select_onnx_outputs() adds) to a Gemm, or a MatMul optionally followed by an Add, whose weight (and bias) are initializers.

Parameters:

path (str) – .onnx file.

Returns:

None when no such layer is found; otherwise node (name of the Gemm / MatMul), op, feature_tensor (its data input), weight / bias (initializer names, bias None if absent), add_node (the bias Add of a MatMul, or None), weight_layout ("class_major" for [C, F], "feature_major" for [F, C]), n_features, n_classes and selected (the class indices the output Gather picks, or None for all classes).

Return type:

dict or None