Using trtexec to generate an engine file from an ONNX model works fine with one RTSP input source, but encounters an error when there are two or more RTSP input sources.
Environment
TensorRT Version: 8.5 GPU Type: Jetson Orin Nano(4GB) Nvidia Driver Version: CUDA Version: 11.4 CUDNN Version: 8.6.0 Operating System + Version: ubuntu 20.04 Python Version (if applicable):3.8.10 TensorFlow Version (if applicable): PyTorch Version (if applicable): Baremetal or Container (if container which image + tag): baremetal
WARNING: [TRT]: The getMaxBatchSize() function should not be used with an engine built from a network created with NetworkDefinitionCreationFlag::kEXPLICIT_BATCH flag. This function will always return 1.
INFO: [Implicit Engine Info]: layers num: 2
0 INPUT kFLOAT images 3x640x640
1 OUTPUT kFLOAT output0 20x8400
0:00:07.486230283 136305 0x39905600 WARN nvinfer gstnvinfer.cpp:677:gst_nvinfer_logger:<primary-inference> NvDsInferContext[UID 1]: Warning from NvDsInferContextImpl::checkBackendParams() <nvdsinfer_context_impl.cpp:1841> [UID = 1]: Backend has maxBatchSize 1 whereas 2 has been requested
0:00:07.486305614 136305 0x39905600 WARN nvinfer gstnvinfer.cpp:677:gst_nvinfer_logger:<primary-inference> NvDsInferContext[UID 1]: Warning from NvDsInferContextImpl::generateBackendContext() <nvdsinfer_context_impl.cpp:2018> [UID = 1]: deserialized backend context :/opt/nvidia/deepstream/deepstream-6.2/sources/deepstream_python_apps/apps/deepstream-imagedata-multistream-test/face1.engine failed to match config params, trying rebuild
0:00:07.502963990 136305 0x39905600 INFO nvinfer gstnvinfer.cpp:680:gst_nvinfer_logger:<primary-inference> NvDsInferContext[UID 1]: Info from NvDsInferContextImpl::buildModel() <nvdsinfer_context_impl.cpp:1923> [UID = 1]: Trying to create engine from model files
ERROR: failed to build network since there is no model file matched.
ERROR: failed to build network.
0:00:10.463399348 136305 0x39905600 ERROR nvinfer gstnvinfer.cpp:674:gst_nvinfer_logger:<primary-inference> NvDsInferContext[UID 1]: Error in NvDsInferContextImpl::buildModel() <nvdsinfer_context_impl.cpp:1943> [UID = 1]: build engine file failed
0:00:10.682420140 136305 0x39905600 ERROR nvinfer gstnvinfer.cpp:674:gst_nvinfer_logger:<primary-inference> NvDsInferContext[UID 1]: Error in NvDsInferContextImpl::generateBackendContext() <nvdsinfer_context_impl.cpp:2029> [UID = 1]: build backend context failed
0:00:10.682910206 136305 0x39905600 ERROR nvinfer gstnvinfer.cpp:674:gst_nvinfer_logger:<primary-inference> NvDsInferContext[UID 1]: Error in NvDsInferContextImpl::initialize() <nvdsinfer_context_impl.cpp:1266> [UID = 1]: generate backend failed, check config file settings
0:00:10.684895459 136305 0x39905600 WARN nvinfer gstnvinfer.cpp:888:gst_nvinfer_start:<primary-inference> error: Failed to create NvDsInferContext instance
0:00:10.684992902 136305 0x39905600 WARN nvinfer gstnvinfer.cpp:888:gst_nvinfer_start:<primary-inference> error: Config file path: config_face_nvinfer.txt, NvDsInfer Error: NVDSINFER_CONFIG_FAILED
wish
I expect that after using the trtexec command to generate the engine file from onnx, it can run normally when running with multiple input source parameters.
Hi:
Can you give me some tips ,code or command on how to modify it?
I tried to use onnx-modifier tools to change it, and used the trtexec command to change it, but the change could not be successful.
Hi:
Thank for your reply!
I refer to the information provided for execution. The executed commands and error reports are as follows:
cmd1:trtexec --onnx=face.onnx --saveEngine=face2.engine --batch=2
cmd2:trtexec --onnx=face.onnx --saveEngine=face2.engine --batch=2 --maxBatch=10 --fp16
The --batch and --maxBatch flags should not be used when the input model is ONNX or when dynamic shapes are provided. Please use --optShapes and --shapes to set input shapes instead.
cmd1:trtexec --optShapes=images:2x3x640x640 --minShapes=images:1x3x640x640 --maxShapes=images:12x3x640x640 --onnx=face.onnx --saveEngine=face4.engine
cmd2:trtexec --shapes=images:6x3x640x640 --optShapes=images:2x3x640x640 --minShapes=images:1x3x640x640 --maxShapes=images:12x3x640x640 --onnx=face.onnx --saveEngine=face4.engine
Static model does not take explicit shapes since the shape of inference tensors will be determined by the model itself
To add some content, when using the following commandtrtexec --onnx=face.onnx --saveEngine=face.engine, the engine file can be generated, but when using python to run the multi-input source Deepstream program, the error is as follows
:00:07.557811059 125932 0x2c271330 INFO nvinfer gstnvinfer.cpp:680:gst_nvinfer_logger:<primary-inference> NvDsInferContext[UID 1]: Info from NvDsInferContextImpl::deserializeEngineAndBackend() <nvdsinfer_context_impl.cpp:1909> [UID = 1]: deserialized trt engine from :/opt/nvidia/deepstream/deepstream-6.2/sources/deepstream_python_apps/apps/deepstream_face_detection2/face3.engine
WARNING: [TRT]: The getMaxBatchSize() function should not be used with an engine built from a network created with NetworkDefinitionCreationFlag::kEXPLICIT_BATCH flag. This function will always return 1.
INFO: [Implicit Engine Info]: layers num: 2
0 INPUT kFLOAT images 3x640x640
1 OUTPUT kFLOAT output0 20x8400
0:00:07.829792653 125932 0x2c271330 WARN nvinfer gstnvinfer.cpp:677:gst_nvinfer_logger:<primary-inference> NvDsInferContext[UID 1]: Warning from NvDsInferContextImpl::checkBackendParams() <nvdsinfer_context_impl.cpp:1841> [UID = 1]: Backend has maxBatchSize 1 whereas 2 has been requested
0:00:07.829884048 125932 0x2c271330 WARN nvinfer gstnvinfer.cpp:677:gst_nvinfer_logger:<primary-inference> NvDsInferContext[UID 1]: Warning from NvDsInferContextImpl::generateBackendContext() <nvdsinfer_context_impl.cpp:2018> [UID = 1]: deserialized backend context :/opt/nvidia/deepstream/deepstream-6.2/sources/deepstream_python_apps/apps/deepstream_face_detection2/face3.engine failed to match config params, trying rebuild
0:00:07.847787874 125932 0x2c271330 INFO nvinfer gstnvinfer.cpp:680:gst_nvinfer_logger:<primary-inference> NvDsInferContext[UID 1]: Info from NvDsInferContextImpl::buildModel() <nvdsinfer_context_impl.cpp:1923> [UID = 1]: Trying to create engine from model files
ERROR: failed to build network since there is no model file matched.
ERROR: failed to build network.
0:00:10.413748400 125932 0x2c271330 ERROR nvinfer gstnvinfer.cpp:674:gst_nvinfer_logger:<primary-inference> NvDsInferContext[UID 1]: Error in NvDsInferContextImpl::buildModel() <nvdsinfer_context_impl.cpp:1943> [UID = 1]: build engine file failed
0:00:10.625657789 125932 0x2c271330 ERROR nvinfer gstnvinfer.cpp:674:gst_nvinfer_logger:<primary-inference> NvDsInferContext[UID 1]: Error in NvDsInferContextImpl::generateBackendContext() <nvdsinfer_context_impl.cpp:2029> [UID = 1]: build backend context failed
0:00:10.626082315 125932 0x2c271330 ERROR nvinfer gstnvinfer.cpp:674:gst_nvinfer_logger:<primary-inference> NvDsInferContext[UID 1]: Error in NvDsInferContextImpl::initialize() <nvdsinfer_context_impl.cpp:1266> [UID = 1]: generate backend failed, check config file settings
0:00:10.628016683 125932 0x2c271330 WARN nvinfer gstnvinfer.cpp:888:gst_nvinfer_start:<primary-inference> error: Failed to create NvDsInferContext instance
0:00:10.628146223 125932 0x2c271330 WARN nvinfer gstnvinfer.cpp:888:gst_nvinfer_start:<primary-inference> error: Config file path: config_face_nvinfer2.txt, NvDsInfer Error: NVDSINFER_CONFIG_FAILED
[NvMultiObjectTracker] De-initialized
**PERF: {'stream0': 0.0, 'stream1': 0.0}
Error: gst-resource-error-quark: Failed to create NvDsInferContext instance (1): gstnvinfer.cpp(888): gst_nvinfer_start (): /GstPipeline:pipeline0/GstNvInfer:primary-inference:
Config file path: config_face_nvinfer2.txt, NvDsInfer Error: NVDSINFER_CONFIG_FAILED
Exiting app
Thanks for your patience and sorry for the late update.
Since your model is static, you will need to update the batch size by modifying the model parameter directly.
Please check below for the detailed steps:
1. Install dependencies
$ git clone https://github.com/NVIDIA/TensorRT.git
$ cd TensorRT/tools/onnx-graphsurgeon/
$ make build
$ python3 -m pip install dist/onnx_graphsurgeon-*-py2.py3-none-any.whl
$ pip3 install onnx
2. Modify the batch size to 2
Edit modify.py
import onnx
import onnx_graphsurgeon as gs
batch = 2
graph = gs.import_onnx(onnx.load("face.onnx"))
for input in graph.inputs:
input.shape[0] = batch
reshape_nodes = [node for node in graph.nodes if node.op == "Reshape"]
for node in reshape_nodes:
node.inputs[1].values[0] = batch
onnx.save(gs.export_onnx(graph), "dynamic.onnx")
Put the face1.engine to /opt/nvidia/deepstream/deepstream-6.3/sources/deepstream_python_apps/apps/deepstream-imagedata-multistream-test.
$ python3 deepstream_imagedata-multistream.py file:///opt/nvidia/deepstream/deepstream-6.3/sources/deepstream_python_apps/apps/deepstream-imagedata-multistream-test/darkface2.mp4 file:///opt/nvidia/deepstream/deepstream-6.3/sources/deepstream_python_apps/apps/deepstream-imagedata-multistream-test/darkface2.mp4 frames/
Frames will be saved in 2024-01-09-07-07-41
...
0:00:00.249330389 25336 0x3d997560 WARN nvinfer gstnvinfer.cpp:887:gst_nvinfer_start:<primary-inference> warning: NvInfer output-tensor-meta is enabled but init_params auto increase memory (auto-inc-mem) is disabled. The bufferpool will not be automatically resized.
0:00:04.110218019 25336 0x3d997560 INFO nvinfer gstnvinfer.cpp:682:gst_nvinfer_logger:<primary-inference> NvDsInferContext[UID 1]: Info from NvDsInferContextImpl::deserializeEngineAndBackend() <nvdsinfer_context_impl.cpp:1988> [UID = 1]: deserialized trt engine from :/opt/nvidia/deepstream/deepstream-6.3/sources/deepstream_python_apps/apps/deepstream-imagedata-multistream-test/face1.engine
WARNING: [TRT]: The getMaxBatchSize() function should not be used with an engine built from a network created with NetworkDefinitionCreationFlag::kEXPLICIT_BATCH flag. This function will always return 1.
INFO: [Implicit Engine Info]: layers num: 2
0 INPUT kFLOAT images 3x640x640
1 OUTPUT kFLOAT output0 20x8400
0:00:04.273834882 25336 0x3d997560 INFO nvinfer gstnvinfer.cpp:682:gst_nvinfer_logger:<primary-inference> NvDsInferContext[UID 1]: Info from NvDsInferContextImpl::generateBackendContext() <nvdsinfer_context_impl.cpp:2091> [UID = 1]: Use deserialized engine model: /opt/nvidia/deepstream/deepstream-6.3/sources/deepstream_python_apps/apps/deepstream-imagedata-multistream-test/face1.engine
0:00:04.441997274 25336 0x3d997560 INFO nvinfer gstnvinfer_impl.cpp:328:notifyLoadModelStatus:<primary-inference> [UID 1]: Load new model:config_face_nvinfer.txt successfully
...
**PERF: {'stream0': 0.0, 'stream1': 0.0}
arr1=1
arr1=1
arr1=2
arr1=2