当前位置:网站首页>【环境搭建】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)
边栏推荐
- Getting started with ctfshow-web Part of the file upload part solution
- [Vulnerability reproduction] CVE-2018-7490 (path traversal)
- 【CNN】2022 ECCV Oral 自反馈学习的mixup训练框架AutoMix
- epoll LT和ET 问题总结
- 常用SQL server语句
- Some of the topics in VNCTF2021 are reproduced
- 图像识别后将识别结果整理成列表,点击列表可跳转到搜索页面
- Go语言技巧之正确高效使用slice(听课笔记总结--简单易懂)
- 管理方向发展
- define 可变参数定义
猜你喜欢
随机推荐
RDMA
go Antlr重构脚本解释器如何实现
C#学习笔记
.net 控件calendar 基础用法
makefile的foreach、filter、filter-out函数
BUUCTF MISC刷题笔记(二)
The 5th Blue Cap Cup preliminary misc reappears after the game
uva11624 Fire! (双bfs)
医院智能3D蓝牙导航导诊系统
H5页面px不对,单位不对等问题
Xpath之爬取全国城市名称学习
关于指针、地址的大小的问题(以及malloc的用法)
[漏洞复现]CVE-2018-12613(远程文件包含)
ASP.net中的数据库应用
js在for循环中按照顺序响应请求
嵌入式之串口中断只能收到一个字节
Shell programming loop statement and function
CPU主频 外频 芯片组 倍频 cache FSB PCI简介
QT program generates independent exe program (pit-avoiding version)
一篇文章带你熟悉 TCP/IP 协议(网络协议篇二)








![[V&N2020 Open] Memory Forensics](/img/b7/20f72a40d43a402009e9451903615b.png)
