Error 3 Cuda initialization while deserializing TensorRT model


I encountered an error when running these lines of code in my project:

with open(engine_file_path, "rb") as f, trt.Runtime(trt.Logger()) as runtime:
    engine = runtime.deserialize_cuda_engine(
[TensorRT] ERROR: Cuda initialization failure with error 3.              Please check cuda installation:   
 ERROR - This exception occurred while initialing detector pipeline. Stopping
Traceback (most recent call last):
  File ".../yolo_tensorrt/", line 15, in __init__
    self.engine = self.load_tensorrt_engine(checkpoint_path, self.TRT_LOGGER)
  File ".../yolo_tensorrt/", line 23, in load_tensorrt_engine
    with open(engine_file_path, "rb") as f, trt.Runtime(trt.Logger()) as runtime:
TypeError: pybind11::init(): factory function returned nullptr

I am using this image: ,
Ubuntu 16.04
Python 3.5
Cuda 10.0.130
Cudnn 7.4.2
Tensorrt 5.0.2

First running /opt/tensorrt/python/, then running the script.

Also, when only running the code snippet above in the python console, I get no errors:

>>> type(engine)
<class 'tensorrt.tensorrt.ICudaEngine'>

Could you please explain the error code (error 3) and the error itself (pybind11::init(): factory function returned nullptr)?

1 Like

I have the same problem,any body solve this problem?

i got the same error,could anyone help??

I have the same problem.

When I run inference on the main thread of my application it’s fine, but it blocks the main thread which doesn’t work for my use case so I need to run in a separate process or thread.

I have tried multiple implementations to run inference via a separate process. My latest attempt was to run inference using a separate worker task via Python Celery (

I have also tried to use the Python threading API and the multiprocessing API but ran into the same issues.

with open(engine_file_path, "rb") as f, trt.Runtime(TRT_LOGGER) as runtime:
            return runtime.deserialize_cuda_engine(
TypeError('pybind11::init(): factory function returned nullptr',)

Anyone found the solution yet? I am facing the same issue here. Any hints would be very helpful.

I had a similar issue, and solve it by adding a line of code on the main process, before start the subprocesses:



Hi bro, have you solved this problem ?
I have met the same, there is a wrong error like this :[TensorRT] ERROR: INVALID_CONFIG: Deserialize the cuda engine failed
Here are the version I used. I
CUDA :10.2
Python :3.6.9