-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
转换upsample层时遇到了问题 #2
Comments
onnx 的opset版本是9吗?或者你把模型给我,我给你看看。 |
opset应该是9,之前pytorch导出时没指定version应该是默认9。我另一个模型yolo在转换reshape节点时还出现了其他错误: 模型要怎么发给您呢?我上传个百度云可以么?谢谢大佬!! |
@RichardSong-dev upsample的bug修复了,源码已更新,你试试看,然后你的模型里面的reshape操作维度大于4维了,这个caffe不支持,所以你导出onnx时,需要把这部分去掉才行。 |
谢谢大佬,我去研究研究! |
@xxradon 大佬,昨天按照您的方法试了一下,已经可以转换成功了!但当我在pytorch中把upsample改为bilinear之后又出现了问题: 因为我还需要将caffe模型转化为另一种可部署在服务器上的格式,而转换工具只支持 模型链接 |
@RichardSong-dev 像你这种定制的caffe解析,需要自己手动修改源码,自己调试。 |
@xxradon 大佬,对于昨天的问题,我按照您的方式改了一下_operators.py代码: elif str(mode,encoding="gbk") == "linear":
scales = node.input_tensors.get(node.inputs[1])
scale = scales[2]
layer = myf("Upsample", node_name, [input_name], [output_name],
upsample_param=dict(
scale = int(scale)
)) 然后,使用https://github.com/Royzon/caffe_extension_layer 这个项目中的upsample layer重新编译了一下caffe。模型可以转换成功,但显示model output different。cos sim 大概在0.98-0.99左右。想请问大佬知道pytorch->onnx时bilinear具体使用的什么操作吗?谢谢大佬的回复! |
@RichardSong-dev 你可以看看这个https://www.zhihu.com/question/63890195?sort=created 还有onnx关于upsample的功能描述,https://github.com/onnx/onnx/blob/master/docs/Changelog.md#Upsample-9 ,cos sim 大概在0.98-0.99左右说明值已经比较相似了,但是两者的实现差距,这个你得看源码去理解其中的运算差异。 |
请问大佬,是怎么在自己的caffe版本中添加https://github.com/jnulzl/caffe_plus 这个项目中Upsample的,是需要重新编译吗? |
@bestzsq 把https://github.com/jnulzl/caffe_plus 这个项目中 optional UpsampleParameter upsample_param = 151; //数值根据你使用的caffe.proto中注释更改
/*
...
*/
message UpsampleParameter {
optional int32 height = 1 [default = 32];
optional int32 width = 2 [default = 32];
optional int32 height_scale = 3 [default = 2];
optional int32 width_scale = 4 [default = 2];
enum UpsampleOp {
NEAREST = 0;
BILINEAR = 1;
}
optional UpsampleOp mode = 5 [default = BILINEAR];
} 之后重新编译就可以了。 |
@RichardSong-dev 谢谢大佬。我昨天把整个caffe_plus项目编译了一遍,现在可以了 |
大佬你好, 我转换模型时提示: |
我尝试将pytorch版yolov3模型通过onnx转换为caffe模型。在转换upsample层时程序报错:
Traceback (most recent call last):
File "convertCaffe.py", line 122, in
convertToCaffe(graph, opset_version, prototxt_path, caffemodel_path)
File "convertCaffe.py", line 67, in convertToCaffe
layer = converter_fn(node,graph,err)
File "/root/ONNXToCaffe-master/onnx2caffe/_operators.py", line 362, in _convert_upsample
factor = int(node.attrs["height_scale"])
KeyError: 'height_scale'
upsample层参数如图所示:
于是我将_operators.py中第362行与370行注释掉来尝试解决,结果又出现如下错误:
Traceback (most recent call last):
File "convertCaffe.py", line 122, in
convertToCaffe(graph, opset_version, prototxt_path, caffemodel_path)
File "convertCaffe.py", line 79, in convertToCaffe
layers[id] = layer._to_proto()
File "/root/ONNXToCaffe-master/MyCaffe.py", line 100, in _to_proto
assign_proto(layer, k, v)
File "/root/ONNXToCaffe-master/MyCaffe.py", line 29, in assign_proto
is_repeated_field = hasattr(getattr(proto, name), 'extend')
AttributeError: upsample_param
python3.7.9 onnx1.8.0
求教该怎么解决!谢谢各位大佬!
The text was updated successfully, but these errors were encountered: