ncnn icon indicating copy to clipboard operation
ncnn copied to clipboard

pnnx怎么转换rvm mobilenetv3这种多输入模型到ncnn呢?

Open sankexin opened this issue 2 years ago • 1 comments

error log | 日志或报错信息 | ログ

terminate called after throwing an instance of 'c10::Error' what(): forward() is missing value for argument 'r1'. Declaration: forward(torch.model.model.MattingNetwork self, Tensor src, Tensor r1, Tensor r2, Tensor r3, Tensor r4, Tensor downsample_ratio) -> (Tensor[]) Exception raised from checkAndNormalizeInputs at /pytorch/aten/src/ATen/core/function_schema_inl.h:239 (most recent call first): frame #0: c10::Error::Error(c10::SourceLocation, std::string) + 0x42 (0x7fdf348a9a22 in /usr/local/lib/python3.7/site-packages/torch/lib/libc10.so) frame #1: c10::detail::torchCheckFail(char const*, char const*, unsigned int, std::string const&) + 0x5b (0x7fdf348a63db in /usr/local/lib/python3.7/site-packages/torch/lib/libc10.so) frame #2: + 0xf182ed (0x7fdf21fb72ed in /usr/local/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so) frame #3: torch::jit::GraphFunction::operator()(std::vector<c10::IValue, std::allocatorc10::IValue >, std::unordered_map<std::string, c10::IValue, std::hashstd::string, std::equal_tostd::string, std::allocator<std::pair<std::string const, c10::IValue> > > const&) + 0x2d (0x7fdf24627fcd in /usr/local/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so) frame #4: torch::jit::Method::operator()(std::vector<c10::IValue, std::allocatorc10::IValue >, std::unordered_map<std::string, c10::IValue, std::hashstd::string, std::equal_tostd::string, std::allocator<std::pair<std::string const, c10::IValue> > > const&) + 0x138 (0x7fdf246355f8 in /usr/local/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so) frame #5: + 0x8ee83 (0x561c35707e83 in ./build/src/pnnx) frame #6: + 0x8ca5f (0x561c35705a5f in ./build/src/pnnx) frame #7: + 0x6db62 (0x561c356e6b62 in ./build/src/pnnx) frame #8: + 0x3c56d (0x561c356b556d in ./build/src/pnnx) frame #9: __libc_start_main + 0xe7 (0x7fdedda05c87 in /lib/x86_64-linux-gnu/libc.so.6) frame #10: + 0x3a9da (0x561c356b39da in ./build/src/pnnx)

model | 模型 | モデル

  1. original model rvm_mobilenetv3_fp32.zip

how to reproduce | 复现步骤 | 再現方法

1.使用转换命令为:./build/src/pnnx rvm_mobilenetv3_fp32.pt inputshape=[1,3,1080,1920] 2.模型的输入本来应该是六个:src = torch.randn(1, 3, 1080, 1920).to("cpu")、rec = (torch.zeros([1, 1, 1, 1]).to("cpu"),) * 4、downsample_ratio = torch.tensor([0.25]) 3.

sankexin avatar Aug 09 '22 06:08 sankexin

直接上代码吧 https://github.com/Tencent/ncnn/blob/acbaaa665b327a60f529f57f8ef15f6c7ebc8ffe/tools/pnnx/src/main.cpp#L167-L168

https://github.com/Tencent/ncnn/blob/acbaaa665b327a60f529f57f8ef15f6c7ebc8ffe/tools/pnnx/src/main.cpp#L208-L210

目前代码里面,只支持最多指定两个 input shape.

要支持多于两个,你需要修改如下代码:

https://github.com/Tencent/ncnn/blob/acbaaa665b327a60f529f57f8ef15f6c7ebc8ffe/tools/pnnx/src/main.cpp#L248-L252

在 252 行后面,依次添加对 inputshape3, inputshape4, ... 的处理。

csukuangfj avatar Aug 12 '22 02:08 csukuangfj