当前位置:网站首页>【环境搭建】tensorrt
【环境搭建】tensorrt
2022-08-09 09:03:00 【.云哲.】
1,介绍
TensorRT是一个高性能的深度学习推理(Inference)优化器,可以为深度学习应用提供低延迟、高吞吐率的部署推理。
2,安装
2.1 已经编译完成,nvidia官网下载
cuda:10.0
cudnn:7.6.0
cmake:3.9.2
tensorrt:7.1
2.2 配置环境变量
vim ~/.bashrc
# set tensorrt
export TENSORRT_ROOT=$HOME/TensorRT
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$TENSORRT_ROOT/lib
source ~/.bashrc
2.3 编译
sudo apt-get install zlib1g zlib1g-dev
git clone https://github.com/NVIDIA/TensorRT.git
cd TensorRT
git submodule sync
git submodule update --init --recursive
mkdir -p build && cd build
cmake .. -DTRT_LIB_DIR=$TRT_RELEASE/lib -DTRT_OUT_DIR=`pwd`/out -DCUDA_VERSION=10.2
make -j$(nproc)
make install # 根据硬件环境编译链接库,并更新
# 获取指定版本
git clone -b 7.1.3 https://github.com/NVIDIA/TensorRT.git
cd TensorRT
git checkout -b 7.1.3
git submodule sync
git submodule update --init --recursive
相关参考
https://zhuanlan.zhihu.com/p/181274475
3,python
3.1 安装要求
pip install pycuda # 版本>=2019.1.1
pip install tensorrt
pip install uff
pip install graphsurgeon
# 缺少依赖库
sudo cp libnvinfer.so.7 /usr/lib
sudo cp libnvonnxparser.so.7 /usr/lib
sudo cp libnvparsers.so.7 /usr/lib
sudo cp libnvinfer_plugin.so.7 /usr/lib
sudo cp libmyelin.so.1 /usr/lib
cuda -> pytorch -> tensorrt
10.2 -> 1.4.0 -> 7.0
10.2 -> 1.5/1.6 -> 7.1
3.2 代码
python
>>> import tensorrt
>>> tensorrt.__version__
'7.1.3.4'
3.4 动态维度
import torch
from torchvision import models
import time
resnet18 = models.resnet18(pretrained=True)
resnet18 = resnet18.eval().cuda()
x = torch.randn((1,3,224,224), dtype=torch.float32).cuda()
for i in range(10):
t1 = time.time()
torch.cuda.synchronize()
out = resnet18(x)
torch.cuda.synchronize()
t2 = time.time()
print("pytorch {} inference:{}".format(i, t2-t1))
output = out.data.cpu().numpy()
# onnx
onnx_file = "resnet18.onnx"
input = ["input"]
output = ["output"]
dynamic_axes = {'input' : {0 : 'batch_size'},
'output' : {0 : 'batch_size'}}
torch.onnx.export(resnet18,
x,
onnx_file,
export_params=True,
opset_version=10,
do_constant_folding=True,
input_names = input,
output_names = output,
dynamic_axes=dynamic_axes)
边栏推荐
- Xpath之爬取全国城市名称学习
- Module模块化编程的优点有哪些
- parse <compoN> error: Custom Component‘name should be form of my-component, not myComponent or MyCom
- [V&N2020 Open] Memory Forensics
- gin中改进版curd接口例子
- fastadmin图片上传方法改造
- PoPW token distribution mechanism may ignite the next bull market
- Arduino+2片74hc595 驱动8x8(共阳)点阵(1008BS)
- requests之数据解析Xpath介绍
- [Vulnerability reproduction] CVE-2018-12613 (remote file inclusion)
猜你喜欢

Go语言技巧之正确高效使用slice(听课笔记总结--简单易懂)

js实现看板全屏功能

+ 6000 words, help you understand the Internet architecture evolution.

算术表达式求值演示

数据库期末复习这一篇就够了(期末预习大概也行)

RESTful

The difference between big-endian and little-endian storage is easy to understand at a glance

leetcode 33. 搜索旋转排序数组 (二分经典题)

【愚公系列】2022年08月 Go教学课程 033-结构体方法重写、方法值、方法表达式

Anaconda4.8.3介绍、安装及使用教程安装(win10)并修改Jupyter默认工作目录
随机推荐
关于指针、地址的大小的问题(以及malloc的用法)
JVM进程诊断利器——Arthas
内存中的swap机制
parse <compoN> error: Custom Component‘name should be form of my-component, not myComponent or MyCom
【培训课程专用】CA/TA调用模型-代码导读
图像识别后将识别结果整理成列表,点击列表可跳转到搜索页面
【场景化解决方案】构建医疗通讯录,“慧医钉”助力医院实现数字化管理
DeFi 项目中的治理Token
Anaconda4.8.3介绍、安装及使用教程安装(win10)并修改Jupyter默认工作目录
UE4 RTS 框选功能实现
Xpath之爬取全国城市名称学习
H5页面px不对,单位不对等问题
不支持关键字: 'Provider'
【场景化解决方案】搭建数据桥梁,Dslink打通泛微系统连接流
C#学习笔记
QT程序生成独立exe程序(避坑版)
makefile - 学习小结
支付宝小程序禁止页面弹性下拉或上拉
【场景化解决方案】ERP系统与钉钉实现数据互通
Regular Expressions for Shell Programming