ReferenceEvaluator is an ONNX reference evaluator for executing a complete ONNX graph or an individual node from Python. It supports inspecting intermediate results, making it useful when conversion or optimization introduces inefficiencies. section 10.3
Use it to:
- Run a model with input feeds and inspect its outputs. section 10.3
- Evaluate one node independently to isolate behavior or investigate graph inefficiencies. section 10.3
- Increase verbosity from level 1 to 4 to expose operations, values, intermediate outputs, and intermediate inputs. section 10.3 section 10.4
- Register Python implementations of custom operators by extending OpRun and passing them through new_ops. section 10.3
Checking an optimized graph
Run the original and optimized models with identical feeds, compare their outputs, and measure execution time. In the demonstrated linear-regression graph, replacing EyeLike plus Add with AddEyeLike produced identical outputs and reduced the reported time for 10,000 runs from 1.1428 to 0.8636. section 10.3
from onnx.reference import ReferenceEvaluator
sess = ReferenceEvaluator(onnx_model)
Use this minimal construction to create an evaluator from an ONNX model before supplying feeds to run. section 10.3
