ncnn_Android_RobustVideoMatting
ncnn_Android_RobustVideoMatting copied to clipboard
onnx转ncnn的问题
pytorch模型转onnx,使用rvm作者给的代码,没报错,但是有警告:
onnx_helper.py:20: TracerWarning: Converting a tensor to a Pyth on number might cause the trace to be incorrect. We can't record the data flow of Python values, so this value wil l be treated as a constant in the future. This means that the trace might not generalize to other inputs! return F.interpolate(x, scale_factor=scale_factor.item(),
使用该onnx模型,进行简化,命令如下:
python -m onnxsim model.onnx model_sim.onnx --dynamic-input-shape --input-shape src:1,3,1280,720 r1i:1,16,256,144 r2i:1,20,128,72 r3i:1,40,64,36 r4i:1,64,32,18 downsample_ratio:1
报错如下
onnxruntime.capi.onnxruntime_pybind11_state.InvalidArgument: [ONNXRuntimeError] : 2 : INVALID_ARGUMENT : Non-zero status code returned while running Expand node. Name:'Expand_174' Status Message: invalid expand shape
请大神赐教。我用netron查看了onnx模型的网络图,找到了Expand_174节点,该节点是接收一个shape,然后对r4i进行操作(我去onnx的github上查看,说expand操作是广播)onnx中expand操作的解释 但是我仔细查看并打印了decoder.py里面相关位置的tensor形状,没有自动广播的情况
这个跟onnx的版本也有关系,会给你搞出很多莫名其妙的op,要不你试一下pnnx? 可以直接torchscript转ncnn,不会涉及onnx这个中间商。 https://github.com/Tencent/ncnn/tree/master/tools/pnnx
@queenmary55
@FeiGeChuanShu 感谢回复!我去试试pnnx
@FeiGeChuanShu 请教一下,使用pnnx进行转换的过程中,是否需要对原网络结构的代码进行修改,您在转换的时候有什么注意事项么,我尝试从torchscript用pnnx转ncnn报错如下 。。。。。。。。 ############# pass_level2 ############# pass_level3 ############# pass_level4 ############# pass_level5 make_slice_expression input 173 make_slice_expression end 174 terminate called after throwing an instance of 'std::out_of_range' what(): map::at Aborted (core dumped)
@queenmary55 问下你上面的问题了吗
@FengMu1995 没有解决。我感觉是level1的时候,就有不支持的算子,在encoder部分的featuremap形状就不太对,最后在decoder部分报错了,out of range。不知道怎么排查错误
@FengMu1995 方便留个邮箱联系下吗
@queenmary55 请问您后来如何转换成功?是否愿意分享一下?谢谢。即使我使用了onnxsim简化,最后再转换为ncnn时报以下错误(似乎onnxsim没有作用?): Unknown data type 0 Unsupported Resize scales and sizes are all empty! Unsupported split axis ! Shape not supported yet! Expand not supported yet! Shape not supported yet! Unknown data type 0 Shape not supported yet! Expand not supported yet! Shape not supported yet! Unknown data type 0 Shape not supported yet! Expand not supported yet! Shape not supported yet! Unknown data type 0 Shape not supported yet! Expand not supported yet! Shape not supported yet! Unknown data type 0 Unsupported split axis ! Shape not supported yet! Shape not supported yet! Unknown data type 0 Unsupported Resize scales and sizes are all empty! Shape not supported yet! Shape not supported yet! Unknown data type 0 Unsupported Resize scales and sizes are all empty!
Hi @FeiGeChuanShu How are you? Thanks for contributing to this project. I am going to use your NCNN model in Visual Studio C++ on Windows 10. But it is impossible to run your NCNN model. First, I see a message which shows that your ncnn model is too old. Could u share the method for converting the original rvm model to ncnn model? Thanks