代码拉取完成,页面将自动刷新
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)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。