【.pt模型转换为.onnx模型】模型转换 英特尔神经计算棒 树莓派

背景:树莓派要用英特尔神经计算棒,先要将pytorch训练生成的.pt文件转换为ONNX,再转换为IR,本来直接在树莓派上的原生树莓派系统尝试,明明已经显示输出了模型详细信息,可文件夹中没有出现.onnx文件,于是直接拿windows系统新建有pytorch的环境来尝试,尝试成功。

转换代码

注意点:要根据你的代码进行修改,修改最初的包等

import torch
from models.with_mobilenet import PoseEstimationWithMobileNet
from modules.load_state import load_state
from action_detect.net import NetV2

def convert_onnx():
    print('start!!!')
    
    device = 'cuda' if torch.cuda.is_available() else 'cpu'
    #model_path = '/home/pi/xg_openpose_fall_detect-master/action_detect/checkPoint/action.pt' #这是我们要转换的模型
    #backone = mobilenetv3_large(width_mult=0.75)#mobilenetv3_small()  mobilenetv3_small(width_mult=0.75)  mobilenetv3_large(width_mult=0.75)
    model = NetV2().to(device)
    checkpoint = torch.load(r'E:/xg_openpose_fall_detect-master/action_detect/checkPoint/action.pt', map_location='cpu')
    model.load_state_dict(checkpoint)
    #model.load_state_dict(torch.load(model_path, map_location=device)['model'])

    model.to(device)
    model.eval()
    dummy_input = torch.randn(1, 16384).to(device)#输入大小   #data type nchw
    #onnx_path = '/home/pi/xg_openpose_fall_detect-master/action_detect/checkPoint/action.onnx'
    onnx_path = 'E:/xg_openpose_fall_detect-master/action_detect/checkPoint/action.onnx'
    print("----- pt模型导出为onnx模型 -----")
    output_name = "action.onnx"
    torch.onnx.export(model, dummy_input,onnx_path,export_params=True, input_names=['input'], output_names=['output'])
    print('finish!!!')
    

if __name__ == "__main__" :
    convert_onnx()
    
    

 结果

并保存在定义位置 

  • 2
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Clark-dj

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值