5.16. Model debugger
PopRT provides an accuracy tracking tool (Model Debugger) to help debug accuracy issues. Model Debugger can be used to compare the accuracy of ONNX models or TensorFlow pb models, as well as to print and modify the specified ONNX models.
5.16.1. Model Debugger tool
You can download the Model Debugger tool from GitHub: model_debugger.py .
Model Debugger provides three subcommands (compare
, modify
and print
), each with their own parameters:
The
compare
subcommand compares the accuracy between the source model and the target mode and has the following parameters:--src_model
: specifies the path to the source model. Use--dst_model
to specify the second model for accuracy comparison.--src_backend
: specifies the backend used to run the source model. Options aretensorflow
(for TensorFlow),onnxruntime
(for ONNX) andpoprt
(for PopRT). Default:onnxruntime
.--dst_model
: specifies the target model path.--dst_backend
: specifies the backend used to run the target model. Options aretensorflow
(for TensorFlow),onnxruntime
(for ONNX) andpoprt
(for PopRT). Default:poprt
.--compare_method
: specifies the comparison method. Separate multiple methods with a comma (“,”). Options are:mse
(mean square error),rmse
(root mean squared error),mae
(mean absolute error),mape
(mean absolute percentage error) andr2
(R^2 coefficient of determination between two sets of results).--input_data
: specifies input data for each input tensor. It can be a path to the NumPy file or a character string fromzeros
,ones
, orrand
.--mark_outputs
: marks the name of the tensor to be compared. Separate multiple names with a comma (“,”). If"all"
is specified, then all intermediate tensors will be compared.--mark_io_mapping
: specifies input and output mappings to compare results of the same tensor with different names in the source model and target model.
--dump_data
: dumps the tensor data to be compared to a local file.--dump_dir
: the directory to save the dumped data to.The
modify
subcommand modifies the input model using the specified operation and has the following parameters:--src_model
or--model
: specifies the path to the source model.--update
: useskey=value
to map and update the specified weight, wherekey
is the weight name andvalue
can be a path to a NumPy file or a character string fromzeros
,ones
, orrand
.--extract
: extracts subgraphs into the model. Use--extract input_names=in_name output_names=out_name
to extract the subgraphs betweenin_name
andout_name
.--sort
: performs topological sorting on models.--output_model
: the path to save the modified model to.
The print
subcommand prints the input model and has the following parameters:
--src_model
or--model
: specifies the path to the source model.
--level
: sets the printing level. Options are:
model
to print the model.
graph
to print the graph.
node
to print the nodes.
tensor
to print the tensors.
--name
: specifies the name of the tensor or node to be printed.
5.16.2. Examples
Here are some examples
python model_debugger.py compare --src_model model1.onnx --dst_model model2.onnx --input_data input=rand --mark_outputs all
python model_debugger.py compare --src_model model.onnx --src_backend onnxruntime --dst_model model.pb --dst_backend tensorflow --input_data x:0=rand --compare_method mse,rmse,mae --dump_data --dump_dir temp_output
python model_debugger.py modify --src_model model.onnx --extract input_names=Conv_output_0 output_names=Mul_output_0 --output_model extracted.onnx
python model_debugger.py modify --src_model model.onnx --update onnx::Conv_770=zeros
python model_debugger.py print --src_model model.onnx --name onnx::Conv_770
python model_debugger.py print --src_model ./debug_tools_dev/extracted.onnx --level graph