TensorRT的调试报错整理
报错:pycuda._driver.LogicError: explicit_context_dependent failed: invalid device context - no currently active context?
原因:pycuda.driver没有初始化,导致无法得到context,需要在导入pycuda.driver后再导入pycuda.autoinit, 即如下:
import pycuda.driver as cuda
import pycuda.autoinit
报错:UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xaa in position 8: invalid start byte
原因:在打开导入序列化模型时,需要采用’rb’模式才能读,否则不能读取,即在读取序列化模型时,需要做3件事,如下:
- 打开文件,必须用rb模式:with open(cfg.work_dir + ‘serialized.engine’, ‘rb’) as f
- 创建runtime:trt.Runtime(logger) as runtime
- 基于runtime生成反序列化模型:engine = runtime.deserialize_cuda_engine(f.read())
报错:onnx.onnx_cpp2py_export.checker.ValidationError: Op registered for Upsample is deprecated in domain_version of 11
附加报错信息:
Context: Bad node spec: input: “085_convolutional_lrelu” output: “086_upsample” name: “086_upsample” op_type: “Upsample” attribute
{ name: “mode” s: “nearest” type: STRING } attribute { name: “scales” floats: 1 floats: 1 floats: 2 floats: 2 type: FLOATS }
问题原因:onnx更新太快了,在官方1.5.1以后就取消了upsample层,所以对yolov3报错了。参考https://devtalk.nvidia.com/default/topic/1052153/jetson-nano/tensorrt-backend-for-onnx-on-jetson-nano/1
修改方式是降级onnx到1.4.1
pip uninstall onnx
pip install onnx==1.4.1