商汇粹外网资源平台

搜索
查看: 1083|回复: 0

pytorch 转onnx

[复制链接]

该用户从未签到

4

主题

11

帖子

54

积分

注册会员

Rank: 2

积分
54
发表于 2022-11-30 18:47:10 | 显示全部楼层 |阅读模式
大佬们,渣渣最近要把pytorch 的模型转成onnx 的,转之前模型是可以预测的可视




转之后框都飞了。
下面是我转换的脚本
在预测的时候回警告说CleanUnusedInitializers] Removing initializer 'layer3.1.bn1.num_batches_tracked'. It is not used by any node and should be removed from the model
os.environ["CUDA_VISIBLE_DEVICES"] = "0"
pt_model_path = ’model_best.pth'
onnx_model_path = 'model_latest.onnx
model = resnet18(pretrained=True)
model.eval().cuda()
model.load_state_dict(torch.load(pt_model_path), False
input_tensor = torch.randn(1,3,640,640).cuda()
input_names = ['input']
output_names = ['output']
print(type(input_tensor))
torch.onnx.export(model, (input_tensor,), onnx_model_path, verbose=True, input_names=input_names, output_names=output_names,opset_version=10)
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表