使用 TensorRT 进行 Python 多处理

问题描述

我正在尝试使用 TensorRT 引擎在从多处理继承的 python 类中进行推理。该引擎在我系统上的独立 python 脚本中工作,但现在将其集成到代码库中时,类中使用的多处理似乎导致了问题。

我没有收到任何错误。它只是跳过行 self.runtime = trt.Runtime(self.trt_logger) 之后的所有内容。我的 vscode 调试器也没有进入该函数。

In the docs 提到了以下内容,但我不完全理解:

TensorRT builder 一次只能被一个线程使用。如果你 需要同时运行多个构建,您将需要创建 多个建设者。 TensorRT 运行时可以被多个 同时线程,只要每个对象使用不同的 执行上下文。

我的代码的以下部分从另一个文件开始、加入和终止:

# more imports
import logging
import multiprocessing
import tensorrt as trt
import pycuda.driver as cuda
import pycuda.autoinit

class MyClass(multiprocessing.Process):
    def __init__(self,messages):
        multiprocessing.Process.__init__(self)
        # other stuff
        self.exit = multiprocessing.Event()

    def load_tensorrt_model(self,config):
        '''Load tensorrt model with engine'''
        logging.debug('Start')

        # Reading the config parameters related to the engine
        engine_file = config['trt_engine']['trt_folder'] + os.path.sep + config['trt_engine']['engine_file']
        class_names_file = config['trt_engine']['trt_folder'] + os.path.sep + config['trt_engine']['class_names_file']

        # Verify if all the necessary files are present,if so load the detection network
        if os.path.exists(engine_file) and os.path.exists(class_names_file):
            try:
                logging.debug('In try statement')
                self.trt_logger = trt.Logger()
                f = open(engine_file,'rb')
                logging.debug('I can get here,but no further')
                self.runtime = trt.Runtime(self.trt_logger)
                logging.debug('Cannot get here')
                self.engine = self.runtime.deserialize_cuda_engine(f.read())
# More stuff                

我找到了一个拥有 multithreading problem 的人,但目前我无法使用它来解决我的问题。

感谢任何帮助。

系统规格:

  • Python 3.6.9
  • Jetson NX
  • 喷气背包 4.4.1
  • L4T 32.4.4
  • Tensorrt 7.1.3.0-1
  • Cuda10.2
  • Ubuntu 18.04

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...