1 Star 0 Fork 0

cuglujun/CenterNet_TensorRT_Nano

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
torch2trt_test.py 1.20 KB
一键复制 编辑 原始数据 按行查看 历史
kobe 提交于 2019-12-03 12:51 . .add comment
import torch
from torch2trt.torch2trt import torch2trt
from torchvision.models.resnet import resnet50
import time
import numpy as np
# create some regular pytorch model...
model = resnet50(pretrained=True).eval().cuda()
# create example data
x = torch.ones((1, 3, 512, 512)).cuda()
#get model parameters
print(sum(p.numel() for p in model.parameters() if p.requires_grad))
# convert to TensorRT feeding sample data as input
print('x = torch.ones((1, 3, 512, 512)).cuda()')
model_trt = torch2trt(model, [x])
timelist = []
print('y = model(x)')
for i in range(101):
start = time.time()
y = model(x)
end = time.time()
print(end - start)
timelist.append(end - start)
temp = np.array(timelist)
print(sum(timelist))
print('mean = {}'.format(temp.mean()))
torch.save(model_trt.state_dict(), 'Resnet_50.pth')
from torch2trt import TRTModule
model_trt_load = TRTModule()
model_trt_load.load_state_dict(torch.load('Resnet_50.pth'))
timelist.clear()
timelist = []
for i in range(101):
start = time.time()
y_trt = model_trt_load(x)
end = time.time()
print(end - start)
timelist.append(end - start)
temp = np.array(timelist)
print(sum(timelist))
print('mean = {}'.format(temp.mean()))
print(1)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/cuglujun/CenterNet_TensorRT_Nano.git
[email protected]:cuglujun/CenterNet_TensorRT_Nano.git
cuglujun
CenterNet_TensorRT_Nano
CenterNet_TensorRT_Nano
master

搜索帮助