☰
【Tensorflow实战系列】Tensorflow: TensoeRT的安装及编译(c++接口)
2026/10/22 12:21:57 网站建设 项目流程

1. 下载对应版本的TensorRT

首先去NVIDIA官网下载对应版本的TensorRT,LZ这里使用的是6.0.1版本

下载的是tar版本,按照官方文档,只要增加一下系统变量就行啦

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:<TensorRT-${version}/lib>

2. 在tf中重新config(挺多坑的,找了好久才知道原因)

超级多could not find的问题:

Could not find any NvInferVersion.h matching version'6'in any subdirectory:

给出config对应的日志:

felaim@felaim-pc:~/Documents/software/tensorflow-r1.14$./configure WARNING:--batch mode is deprecated.Please instead explicitly shut down your Bazel server using the command"bazel shutdown".You have bazel0.24.1installed.Please specify the location of python.[Default is/usr/bin/python]:/home/felaim/anaconda3/envs/tensorflow-gpu/bin/python Found possible Python library paths:/home/felaim/anaconda3/envs/tensorflow-gpu/lib/python3.7/site-packages Please input the desired Python library path to use.Default is[/home/felaim/anaconda3/envs/tensorflow-gpu/lib/python3.7/site-packages]Do you wish to build TensorFlow with XLA JIT support?[Y/n]:n No XLA JIT support will be enabledforTensorFlow.Do you wish to build TensorFlow with OpenCL SYCL support?[y/N]:n No OpenCL SYCL support will be enabledforTensorFlow.Do you wish to build TensorFlow with ROCm support?[y/N]:n No ROCm support will be enabledforTensorFlow.Do you wish to build TensorFlow with CUDA support?[y/N]:y CUDA support will be enabledforTensorFlow.Do you wish to build TensorFlow with TensorRT support?[y/N]:y TensorRT support will be enabledforTensorFlow.Could not find any NvInferVersion.h matching version''in any subdirectory:'''include''include/cuda''include/*-linux-gnu''extras/CUPTI/include''include/cuda/CUPTI'of:'/home/felaim/intel/ipp/lib/intel64_lin''/lib/x86_64-linux-gnu''/usr''/usr/lib''/usr/lib/x86_64-linux-gnu''/usr/lib/x86_64-linux-gnu/libfakeroot''/usr/lib/x86_64-linux-gnu/mesa''/usr/lib/x86_64-linux-gnu/mesa-egl''/usr/local/cuda''/usr/local/cuda-10.1/targets/x86_64-linux/lib' '/usr/local/cuda/extras/CUPTI/lib64''/usr/local/lib'Askingfordetailed CUDA configuration...Please specify the CUDA SDK version you want to use.[Leave empty todefaultto CUDA10]:Please specify the cuDNN version you want to use.[Leave empty todefaultto cuDNN7]:Please specify the TensorRT version you want to use.[Leave empty todefaultto TensorRT5]:6Please specify the locally installed NCCL version you want to use.[Leave empty to use http://github.com/nvidia/nccl]:Please specify the comma-separated list of base paths to lookforCUDA libraries and headers.[Leave empty to use thedefault]:/usr/local/cuda,/usr/local/cuda/bin,/usr/local/cuda/lib64,/usr/local/cuda/include,/home/felaim/Documents/software/TensorRT-6.0.1.5,/usr/lib/x86_64-linux-gnu/Found CUDA10.1in:/usr/local/cuda/lib64/usr/local/cuda/include Found cuDNN7in:/usr/local/cuda/lib64/usr/local/cuda/include Found TensorRT6in:/home/felaim/Documents/software/TensorRT-6.0.1.5/lib/home/felaim/Documents/software/TensorRT-6.0.1.5/include Please specify a list of comma-separated CUDA compute capabilities you want to build with.You can find the compute capability of your device at:https://developer.nvidia.com/cuda-gpus.Please note that each additional compute capability significantly increases your build time and binary size,and that TensorFlow only supports compute capabilities>=3.5[Default is:5.2]:Do you want to use clang as CUDA compiler?[y/N]:nvcc will be used as CUDA compiler.Please specify which gcc should be used by nvcc as the host compiler.[Default is/usr/bin/gcc]:Do you wish to build TensorFlow with MPI support?[y/N]:No MPI support will be enabledforTensorFlow.Please specify optimization flags to use during compilation when bazel option"--config=opt"is specified[Default is-march=native-Wno-sign-compare]:Would you like to interactively configure./WORKSPACEforAndroid builds?[y/N]:Not configuring the WORKSPACEforAndroid builds.Preconfigured Bazel build configs.You can use any of the below by adding"--config=<>"to your build command.See.bazelrcformore details.--config=mkl # Build with MKL support.--config=monolithic # Configformostlystaticmonolithic build.--config=gdr # Build with GDR support.--config=verbs # Build with libverbs support.--config=ngraph # Build with Intel nGraph support.--config=numa # Build with NUMA support.--config=dynamic_kernels #(Experimental)Build kernels into separate shared objects.Preconfigured Bazel build configs to DISABLEdefaulton features:--config=noaws # Disable AWS S3 filesystem support.--config=nogcp # Disable GCP support.--config=nohdfs # Disable HDFS support.--config=noignite # Disable Apache Ignite support.--config=nokafka # Disable Apache Kafka support.--config=nonccl # Disable NVIDIA NCCL support.Configuration finished

最后只要按照之前编译tensorflow c++接口重新编译一遍即可!,参考LZ之前的博客https://blog.csdn.net/Felaim/article/details/100349318。

到处都是知识盲区!/(ㄒoㄒ)/~~

参考地址:

  1. https://docs.nvidia.com/deeplearning/sdk/tensorrt-install-guide/index.html#installing-tar

  2. https://github.com/tensorflow/tensorflow/issues/33251

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询