当前位置:网站首页>【环境搭建】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)
边栏推荐
猜你喜欢
XCTF College War "Epidemic" Network Security Sharing Competition Misc wp
The difference between big-endian and little-endian storage is easy to understand at a glance
数理逻辑MOOC+知识点总结(未完无待续)
零搜索量的关键词,你需要布局吗?
BUUCTF MISC brush notes (2)
这下你知道为什么程序员要和产品干架了吧?
第五届蓝帽杯初赛 misc 赛后复现
深度学习时代的视频理解综述
PoPW token distribution mechanism may ignite the next bull market
js实现看板全屏功能
随机推荐
Module模块化编程的优点有哪些
Regular Expressions for Shell Programming
【CNN】白话迁移学习中域适应
GBJ610-ASEMI超薄整流扁桥GBJ610
[漏洞复现]CVE-2018-7490(路径遍历)
使用C语言实现双向链表(带头结点)
BUUCTF MISC Writing Notes (1)
centos7 mysql异常ERROR 2002 (HY000)分析解决
STM32 如何知道FLASH的使用情况
[漏洞复现]CVE-2018-12613(远程文件包含)
Makefile中的%标记和系统通配符*的区别
基于 JSch 实现服务的自定义监控解决方案
Xpath之爬取全国城市名称学习
Shell programming loop statement and function
makefile的foreach、filter、filter-out函数
往二维数组追加键值
UE4 RTS frame selection function implementation
法院3D导航系统-轻松实现室内实时定位导航
Venture DAO 行业研报:宏观和经典案例分析、模式总结、未来建议
二叉树的遍历(非递归)