NvInferModel

Inheritance diagram of NvInferModel

NvInferModel inheritance diagram

class savant.deepstream.nvinfer.model.NvInferModel(local_path=None, remote=None, model_file=None, batch_size=1, precision=ModelPrecision.FP16, input=NvInferModelInput(object='auto.frame', layer_name=None, shape=None, maintain_aspect_ratio=False, scale_factor=1.0, offsets=(0.0, 0.0, 0.0), color_format=<ModelColorFormat.RGB: 0>, preprocess_object_meta=None, preprocess_object_image=None, object_min_width=None, object_min_height=None, object_max_width=None, object_max_height=None), format=None, config_file=None, int8_calib_file=None, engine_file=None, proto_file=None, custom_config_file=None, mean_file=None, label_file=None, tlt_model_key=None, gpu_id=0, interval=0, workspace_size=6144, custom_lib_path=None, engine_create_func_name=None, layer_device_precision=<factory>)

Base configuration template for a nvinfer model.

input: NvInferModelInput = NvInferModelInput(object='auto.frame', layer_name=None, shape=None, maintain_aspect_ratio=False, scale_factor=1.0, offsets=(0.0, 0.0, 0.0), color_format=<ModelColorFormat.RGB: 0>, preprocess_object_meta=None, preprocess_object_image=None, object_min_width=None, object_min_height=None, object_max_width=None, object_max_height=None)

Optional configuration of input data and custom preprocessing methods for a model. If not set, then input will default to entire frame.

format: NvInferModelFormat | None = None

Model file format.

Example

format: onnx
# format: caffe
# etc.
# look in enum for full list of format options
config_file: str | None = None

Model configuration file. Should be specified without a location.

int8_calib_file: str | None = None

INT8 calibration file for dynamic range adjustment with an FP32 model. Required only for models in INT8.

engine_file: str | None = None

Serialized model engine file.

proto_file: str | None = None

Caffe model prototxt file. By default, the model file name (model_file) will be used with the extension .prototxt.

custom_config_file: str | None = None

Configuration file for custom model, eg for YOLO. By default, the model file name (model_file) will be used with the extension .cfg.

mean_file: str | None = None

Pathname of mean data file in PPM format.

label_file: str | None = None

Pathname of a text file containing the labels for the model.

batch_size: int = 1

Number of frames or objects to be inferred together in a batch.

Note

In case the model is an NvInferModel and it is configured to use the TRT engine file directly, the default value for batch_size will be taken from the engine file name, by parsing it according to the scheme {model_name}_b{batch_size}_gpu{gpu_id}_{precision}.engine

local_path: str | None = None

Path where all the necessary model files are placed. By default, the value of module parameter “model_path” and element name will be used (“model_path / element_name”).

model_file: str | None = None

The model file, eg yolov4.onnx.

Note

The model file is specified without a location. The absolute path to the model file will be defined as “local_path/model_file”.

precision: ModelPrecision = 2

Data format to be used by inference.

Example

precision: fp16
# precision: int8
# precision: fp32

Note

In case the model is an NvInferModel and it is configured to use the TRT engine file directly, the default value for precision will be taken from the engine file name, by parsing it according to the scheme {model_name}_b{batch_size}_gpu{gpu_id}_{precision}.engine

remote: RemoteFile | None = None

Configuration of model files remote location. Supported schemes: s3, http, https, ftp.

tlt_model_key: str | None = None

Key for the TAO toolkit encoded model.

gpu_id: int = 0

Device ID of GPU to use for pre-processing/inference (dGPU only).

Note

In case the model is configured to use the TRT engine file directly, the default value for gpu_id will be taken from the engine_file, by parsing it according to the scheme {model_name}_b{batch_size}_gpu{gpu_id}_{precision}.engine

interval: int = 0

Specifies the number of consecutive batches to be skipped for inference.

workspace_size: int = 6144

Workspace size to be used by the engine, in MB

custom_lib_path: str | None = None

Absolute pathname of a library containing custom method implementations for custom models.

engine_create_func_name: str | None = None

Name of the custom TensorRT CudaEngine creation function.

layer_device_precision: List[str]

Specifies the device type and precision for any layer in the network. List of items of format <layer1-name>:<precision>:<device-type>.