记录TensorRT使用时发现的问题和解决方法

No rule to make target ‘/usr/TensorRT-8.5.1.7/targets/x86_64-linux-gnu/lib/libnvinfer_builder_resource.so’, needed by ‘run’. Stop.

使用find命令找到libnvinfer_builder_resource.so位置, 复制到/usr/lib中.

error while loading shared libraries: libnvinfer_plugin.so.8: cannot open shared object file: No such file or directory

解决方法同(一), 也是把libnvinfer_plugin.so.8复制到/usr/lib中

Could NOT find CUDA (missing: CUDA_CUDART_LIBRARY) (found version

在clion 中添加cmake环境变量 -DCUDA_CUDART_LIBRARY=/usr/local/cuda/lib64/libcudart.so
在这里插入图片描述
四 /usr/bin/ld: cannot find -lnvinfer
/usr/bin/ld: cannot find -lnvinfer_plugin
/usr/bin/ld: cannot find -lnvonnxparser

libnvinfer.so.8: cannot open shared object file: No such file or directory
将TensorRT下的lib文件夹文件全部拷贝到/usr/lib文件夹中可解决问题. 若安装了多个版本TensorRT, 这种版本就很low,因为会混乱多个版本动态库.
在~/.bashrc文件添加以下两行

export LD_LIBRARY_PATH=/usr/TensorRT-8.5.1.7/lib:$LD_LIBRARY_PATH
export LIBRARY_PATH=/usr/TensorRT-8.5.1.7/lib:$LIBRARY_PATH

若扔不能解决,那么在cmakelists.txt中添加
link_directories(/usr/local/TensorRT-8.5.1.7/lib)

还不行就指定到环境变量中
在这里插入图片描述
如果以上都不能解决,那就终极解决方案: 在/usr/lib中添加这几个动态库的软连接,至少,变更TensorRT版本重新指定软连接就好.

cd /usr/lib
ln -s /usr/local/TensorRT-8.5.1.7/lib/libnvinfer_plugin.so libnvinfer_plugin.so

五 [libLoader.h::DynamicLibrary::54] Error Code 6: Internal Error (Unable to load library: libnvinfer_builder_resource.so.8.5.1)
使用find找到目标文件路径,然后复制到/usr/lib中

find /usr -iname libnvinfer_builder_resource.so.8.5.1

cp /usr/local/TensorRT-8.5.1.7/targets/x86_64-linux-gnu/lib/libnvinfer_builder_resource.so.8.5.1 /usr/lib
  • 18
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
TensorRT是英伟达(NVIDIA)专门为深度学习模型推理(inference)而开发的高性能推理引擎。TensorRT可以优化和加速深度学习推理,并提供支持各种深度学习框架的API,例如 TensorFlow,PyTorch,Caffe 等等。 使用TensorRT进行推理可以大幅度提高推理速度,因为它采用了多项技术优化,包括半精度计算(half precision),kernel融合(kernel fusion),动态tensor缓冲区等等。 TensorRT使用流程一般如下: 1. 用深度学习框架训练好模型,如TensorFlow、PyTorch等等。 2. 导出训练好的模型为ONNX或UFF格式。 3. 用TensorRT API读取ONNX或UFF格式的模型,创建推理引擎。 4. 将待推理的数据输入到引擎中,进行推理计算。 5. 获取结果并输出。 以下是一个简单的使用TensorRT API进行推理的示例代码: ```python import tensorrt as trt # Load the serialized TensorRT model from disk. with open('model.engine', 'rb') as f: engine_data = f.read() # Create a TensorRT engine from the serialized data. trt_runtime = trt.Logger(trt.Logger.WARNING) engine = trt_runtime.deserialize_cuda_engine(engine_data) # Allocate memory for input and output tensors. input_shape = (1, 3, 224, 224) output_shape = (1, 1000) input_tensor = cuda.mem_alloc(np.prod(input_shape) * np.dtype(np.float32).itemsize) output_tensor = cuda.mem_alloc(np.prod(output_shape) * np.dtype(np.float32).itemsize) # Create a CUDA stream for the engine to execute on. stream = cuda.Stream() # Create a bindings object that maps the input and output tensors to memory. bindings = [int(input_tensor), int(output_tensor)] # Create a Python context object that can execute the engine. context = engine.create_execution_context() # Perform inference on a batch of data. input_data = np.random.rand(*input_shape).astype(np.float32) cuda.memcpy_htod_async(input_tensor, input_data, stream) context.execute_async_v2(bindings=bindings, stream_handle=stream.handle) cuda.memcpy_dtoh_async(output_data, output_tensor, stream) stream.synchronize() # Print the inference result. print(output_data) ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值