微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

将 Pytorch 预训练模型部署到 Movidius 神经计算棒

如何解决将 Pytorch 预训练模型部署到 Movidius 神经计算棒

我已经使用 Detectron2 训练了一个模型(这是 fast_rcnn_R_50_FPN_3x) 之后,我使用手电筒将模型保存在驱动器上:

model_save_name = 'model.pkl'
path = F"/content/drive/My Drive/{model_save_name}"
torch.save(trainer.model,path)

之后我尝试将其转换为 onnx ,我按照此 https://www.programmersought.com/article/29567352620/

但是在我在本地下载模型之后,当我在我的模型上应用以下代码时:

import torch,torchvision
device = torch.device("cpu")
model = torch.load("modelx.pkl",map_location=device)
model.eval()
batch_size = 1
input_shape = (1,224,224) # i also tried (3,224)
output_path="output"
input_data_shape = torch.randn(batch_size,*input_shape,device=device)
torch.onnx.export(model,input_data_shape,output_path,verbose=True)

它一直给我这个错误

/home/momo/Desktop/detectron2/detectron2/modeling/Meta_arch/rcnn.py:224: 
TracerWarning: Iterating over a tensor might cause the trace to be incorrect. Passing 
a tensor of different shape won't change the number of iterations executed (and might 
lead to errors or silently give incorrect results).
images = [x["image"].to(self.device) for x in batched_inputs]
Traceback (most recent call last):
File "Convert.py",line 10,in <module>
torch.onnx.export(model,verbose=True)
File "/home/momo/.local/lib/python3.8/site-packages/torch/onnx/__init__.py",line 275,in export return utils.export(model,args,f,export_params,verbose,training,File "/home/momo/.local/lib/python3.8/site-packages/torch/onnx/utils.py",line 88,in 
export_export(model,input_names,output_names,line 689,in _export_model_to_graph(model,line 458,in _model_to_graph
graph,params,torch_out,module = _create_jit_graph(model,line 422,in 
_create_jit_graph
graph,torch_out = _trace_and_get_graph_from_model(model,args)
File "/home/momo/.local/lib/python3.8/site-packages/torch/onnx/utils.py",line 373,in 
_trace_and_get_graph_from_model
torch.jit._get_trace_graph(model,strict=False,_force_outplace=False,_return_inputs_states=True)
File "/home/momo/.local/lib/python3.8/site-packages/torch/jit/_trace.py",line 1160,in _get_trace_graph
outs = ONNXTracedModule(f,strict,_force_outplace,return_inputs,_return_inputs_states)(*args,**kwargs)
File "/home/momo/.local/lib/python3.8/site-packages/torch/nn/modules/module.py",line 
1051,in _call_impl
return forward_call(*input,**kwargs)
File "/home/momo/.local/lib/python3.8/site-packages/torch/jit/_trace.py",line 127,in 
forward
graph,out = torch._C._create_graph_by_tracing(
File "/home/momo/.local/lib/python3.8/site-packages/torch/jit/_trace.py",line 118,in 
wrapper
outs.append(self.inner(*trace_inputs))
File "/home/momo/.local/lib/python3.8/site-packages/torch/nn/modules/module.py",line 
1039,in _slow_forward
result = self.forward(*input,**kwargs)
File "/home/momo/Desktop/detectron2/detectron2/modeling/Meta_arch/rcnn.py",line 146,in forward
return self.inference(batched_inputs)
File "/home/momo/Desktop/detectron2/detectron2/modeling/Meta_arch/rcnn.py",line 199,in inference
images = self.preprocess_image(batched_inputs)
File "/home/momo/Desktop/detectron2/detectron2/modeling/Meta_arch/rcnn.py",line 224,in preprocess_image
images = [x["image"].to(self.device) for x in batched_inputs]
 File "/home/momo/Desktop/detectron2/detectron2/modeling/Meta_arch/rcnn.py",in <listcomp>
images = [x["image"].to(self.device) for x in batched_inputs]
IndexError: too many indices for tensor of dimension 3

知道为什么吗?以及如何解决

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?