tensorrt.parsers

The parsers package provides parsers for both Caffe and the Universal Framework Format (UFF).

Caffe Parser

class tensorrt.parsers.caffeparser.CaffeParser

Class used for parsing Caffe models.

Allows users to export models trained using Caffe to TRT.

C++ includes: NvCaffeParser.h

destroy()

destroy()=0

Destroy this ICaffeParser object.

parse()

parse(const char *deploy, const char *model, nvinfer1::INetworkDefinition &network, nvinfer1::DataType weightType)=0 -> const IBlobNameToTensor *

Parse a prototxt file and a binaryproto Caffe model to extract network configuration and weights associated with the network, respectively.

Parameters:
  • deploy (*) – The plain text, prototxt file used to define the network configuration.
  • model (*) – The binaryproto Caffe model that contains the weights associated with the network.
  • network (*) – Network in which the CaffeParser will fill the layers.
  • weightType (*) – The type to which the weights will transformed.
Returns:

  • A pointer to an IBlobNameToTensor object that contains the extracted data.
  • See also (nvcaffeparser1::IBlobNameToTensor)

parse_binary_proto()

parseBinaryProto(const char *fileName)=0 -> IBinaryProtoBlob *

Parse and extract data stored in binaryproto file.

The binaryproto file contains data stored in a binary blob. parseBinaryProto() converts it to an IBinaryProtoBlob object which gives the user access to the data and meta-data about data.

Parameters:fileName (*) – Path to file containing binary proto.
Returns:
  • A pointer to an IBinaryProtoBlob object that contains the extracted data.
  • See also (nvcaffeparser1::IBinaryProtoBlob)
set_plugin_factory()

setPluginFactory(IPluginFactory *factory)=0

Set the IPluginFactory used to create the user defined plugins.

Parameters:factory (*) – Pointer to an instance of the user implmentation of IPluginFactory.
set_plugin_factory_ext()

setPluginFactoryExt(IPluginFactoryExt *factory)=0

Set the IPluginFactoryExt used to create the user defined pluginExts.

Parameters:factory (*) – Pointer to an instance of the user implmentation of IPluginFactoryExt.
set_protobuf_buffer_size()

setProtobufBufferSize(size_t size)=0

Set buffer size for the parsing and storage of the learned model.

Parameters:
  • size (*) – The size of the buffer specified as the number of bytes.
  • note (Default size is 2^30 bytes.) –

BlobNameToTensor

class tensorrt.parsers.caffeparser.BlobNameToTensor

Object used to store and query Tensors after they have been extracted from a Caffe model using the ICaffeParser.

note: The lifetime of IBlobNameToTensor is the same as the lifetime of its parent ICaffeParser.

See also: nvcaffeparser1::ICaffeParser

C++ includes: NvCaffeParser.h

find()

find(const char *name) const =0 -> nvinfer1::ITensor *

Given a blob name, returns a pointer to a ITensor object.

Parameters:name (*) – Caffe blob name for which the user wants the corresponding ITensor.
Returns:
Return type:ITensor* corresponding to the queried name. If no such ITensor exists, then nullptr is returned.

BinaryProtoBlob

class tensorrt.parsers.caffeparser.BinaryProtoBlob

Object used to store and query data extracted from a binaryproto file using the ICaffeParser.

See also: nvcaffeparser1::ICaffeParser

C++ includes: NvCaffeParser.h

destroy()

destroy()=0

get_data()

getData()=0 -> const void *

get_data_type()

getDataType()=0 -> nvinfer1::DataType

get_dimensions()

getDimensions()=0 -> nvinfer1::DimsNCHW

PluginFactory

class tensorrt.parsers.caffeparser.PluginFactory

Plugin factory used to configure plugins.

C++ includes: NvCaffeParser.h

create_plugin()

createPlugin(const char *layerName, const nvinfer1::Weights *weights, int nbWeights)=0 -> nvinfer1::IPlugin *

Creates a plugin.

Parameters:
  • layerName (*) – Name of layer associated with the plugin.
  • weights (*) – Weights used for the layer.
  • nbWeights (*) – Number of weights.
is_plugin()

isPlugin(const char *layerName)=0 -> bool

A user implemented function that determines if a layer configuration is provided by an IPlugin.

Parameters:layerName (*) – Name of the layer which the user wishes to validate.

UFF Parser

class tensorrt.parsers.uffparser.UffParser

Class used for parsing models described using the UFF format.

C++ includes: NvUffParser.h

destroy()

destroy()=0

get_uff_required_version_major()

getUffRequiredVersionMajor()=0 -> int

Return Version Major of the UFF.

get_uff_required_version_minor()

getUffRequiredVersionMinor()=0 -> int

Return Version Minor of the UFF.

get_uff_required_version_patch()

getUffRequiredVersionPatch()=0 -> int

Return Patch Version of the UFF.

parse()

parse(const char *file, nvinfer1::INetworkDefinition &network, nvinfer1::DataType weightsType=nvinfer1::DataType::kFLOAT)=0 -> bool

Parse a UFF file.

Parameters:
  • file (*) – File name of the UFF file.
  • network (*) – Network in which the UFFParser will fill the layers.
  • weightsType (*) – The type on which the weights will transformed in.
parse_buffer()

parseBuffer(const char *buffer, std::size_t size, nvinfer1::INetworkDefinition &network, nvinfer1::DataType weightsType=nvinfer1::DataType::kFLOAT)=0 -> bool

Parse a UFF buffer, useful if the file already live in memory.

Parameters:
  • buffer (*) – Buffer of the UFF file.
  • size (*) – Size of buffer of the UFF file.
  • network (*) – Network in which the UFFParser will fill the layers.
  • weightsType (*) – The type on which the weights will transformed in.
parse_from_file()

parse(const char *file, nvinfer1::INetworkDefinition &network, nvinfer1::DataType weightsType=nvinfer1::DataType::kFLOAT)=0 -> bool

Parse a UFF file.

Parameters:
  • file (*) – File name of the UFF file.
  • network (*) – Network in which the UFFParser will fill the layers.
  • weightsType (*) – The type on which the weights will transformed in.
register_input()

registerInput(const char *inputName, nvinfer1::Dims inputDims, UffInputOrder inputOrder)=0 -> bool

Register an input name of a UFF network with the associated Dimensions.

Parameters:
  • inputName (*) – Input name.
  • inputDims (*) – Input Dimensions, always provide your dimensions in CHW even if your network input was in HWC in yout original framework.
  • inputOrder (*) – Input order on which the framework input was originally.
register_output()

registerOutput(const char *outputName)=0 -> bool

Register an output name of a UFF network.

Parameters:outputName (*) – Output name.
set_plugin_factory()

setPluginFactory(IPluginFactory *factory)=0

Set the IPluginFactory used to create the user defined plugins.

Parameters:factory (*) – Pointer to an instance of the user implmentation of IPluginFactory.
set_plugin_factory_ext()

setPluginFactoryExt(IPluginFactoryExt *factory)=0

Set the IPluginFactoryExt used to create the user defined pluginExts.

Parameters:factory (*) – Pointer to an instance of the user implmentation of IPluginFactoryExt.

create_uff_parser

tensorrt.parsers.uffparser.create_uff_parser()

createUffParser() -> TENSORRTAPI IUffParser *

Creates a IUffParser object.

Returns:
  • A pointer to the IUffParser object is returned.
  • See also (nvuffparser::IUffParser)

shutdown_protobuf_library

tensorrt.parsers.uffparser.shutdown_protobuf_library()

shutdownProtobufLibrary(void) -> TENSORRTAPI void

Shuts down protocol buffers library.

note: No part of the protocol buffers library can be used after this function is called.

ONNX Parser

class tensorrt.parsers.onnxparser.ONNXParser

Derived from C++ class nvonnxparser::IONNXParser

convert_to_trtnetwork()

Convert ONNX model to TensorRT network.

get_logger()

Returns the logger.

get_trtnetwork()

Returns the TensorRT network.

parse()

Parse the ONNX model.

report_parsing_info()

Report parsing info.

write_text()

Write ASCII equivalent of the ONNX protobuf file.

write_text_with_weights()

Write ASCII equivalent of the ONNX protobuf file with weights.

create_onnxparser

tensorrt.parsers.onnxparser.create_onnxparser()

ONNX Config

class tensorrt.parsers.onnxparser.OnnxConfig

Derived from C++ class nvonnxparser::IOnnxConfig

add_verbosity()

Increase the verbosity level.

get_full_text_file_name()

Get the File Name of the Network Description as a Text File, including the weights.

get_model_dtype()

Get the Model Data Type.

get_model_file_name()

Get the Model FileName.

get_print_layer_info()

Get whether the layer information will be printed.

get_text_file_name()

Returns the File Name of the Network Description as a Text File.

get_verbosity_level()

Get the Verbosity Level.

reduce_verbosity()

Write ASCII equivalent of the ONNX protobuf file with weights.

set_full_text_file_name()

Set the File Name of the Network Description as a Text File, including the weights.

This API allows setting a file name for the network description in plain text, equivalent of the ONNX protobuf.

This method copies the name string.

set_model_dtype()

Set the Model Data Type. Sets the Model DataType, one of the following: float -d 32 (default), half precision -d 16, and int8 -d 8 data types.

set_model_file_name()

Set the Model File Name.

The Model File name contains the Network Description in ONNX pb format.

This method copies the name string.

set_print_layer_info()

Set whether the layer information will be printed.

set_text_file_name()

Set the File Name of the Network Description as a Text File.

This API allows setting a file name for the network description in plain text, equivalent of the ONNX protobuf.

This method copies the name string.

set_verbosity_level()

Set Verbosity level.

create_onnxconfig

tensorrt.parsers.onnxparser.create_onnxconfig()