ncnn PNNX无法转换torchvision.vit model

vlju58qv  于 2022-10-22  发布在  其他
关注(0)|答案(1)|浏览(324)

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

我使用的python代码如下:

import torch
import torchvision.models as models

model = models.vit_l_16(pretrained=True)
model = model.eval()

model_input = torch.rand(1, 3, 224, 224)
mod = torch.jit.trace(model, model_input, check_trace=False)

mod.save("torchvit_l_16.pt")

然后使用 https://github.com/pnnx/pnnx/releases 下载的windows版pnnx进行convert,command为

.\pnnx-20220720-windows\pnnx-20220720-windows\pnnx.exe torchvit_l_16.pt inputshape=[1,3,224,224]

然后报错:

pnnxparam = torchvit_l_16.pnnx.param
pnnxbin = torchvit_l_16.pnnx.bin
pnnxpy = torchvit_l_16_pnnx.py
ncnnparam = torchvit_l_16.ncnn.param
ncnnbin = torchvit_l_16.ncnn.bin
ncnnpy = torchvit_l_16_ncnn.py
optlevel = 2
device = cpu
inputshape = [1,3,224,224]f32
inputshape2 =
customop =
moduleop =
Load torchscript failed: version_ <= kMaxSupportedFileFormatVersionINTERNAL ASSERT FAILED at "..\\..\\caffe2\\serialize\\inline_container.cc":147, please report a bug to PyTorch. Attempted to read a PyTorch file with version 10, but the maximum supported version for reading is 6. Your PyTorch installation may be too old.
Exception raised from init at ..\..\caffe2\serialize\inline_container.cc:147 (most recent call first):
00007FFCE246A29200007FFCE246A230 c10.dll!c10::Error::Error [<unknown file> @ <unknown line number>]
00007FFCE2469D1E00007FFCE2469CD0 c10.dll!c10::detail::torchCheckFail [<unknown file> @ <unknown line number>]      
00007FFCE2469DCF00007FFCE2469D90 c10.dll!c10::detail::torchInternalAssertFail [<unknown file> @ <unknown line number>]
00007FFC84D9011200007FFC84D8F850 torch_cpu.dll!caffe2::serialize::PyTorchStreamReader::init [<unknown file> @ <unknown line number>]
00007FFC84D8E46B00007FFC84D8E3C0 torch_cpu.dll!caffe2::serialize::PyTorchStreamReader::PyTorchStreamReader [<unknown file> @ <unknown line number>]
00007FFC85FBD5CA00007FFC85FBD4C0 torch_cpu.dll!torch::jit::load [<unknown file> @ <unknown line number>]
00007FFC85FBD16300007FFC85FBD040 torch_cpu.dll!torch::jit::load [<unknown file> @ <unknown line number>]
00007FF68B946DFE00007FF68B945420 pnnx.exe!c10::ivalue::Future::waitAndThrow [<unknown file> @ <unknown line number>]
00007FF68BA7347C00007FF68B945420 pnnx.exe!c10::ivalue::Future::waitAndThrow [<unknown file> @ <unknown line number>]
00007FFD192354E000007FFD192354D0 KERNEL32.DLL!BaseThreadInitThunk [<unknown file> @ <unknown line number>]
00007FFD197C485B00007FFD197C4830 ntdll.dll!RtlUserThreadStart [<unknown file> @ <unknown line number>]

Please export model to torchscript as follows
------------------------------------------
import torch
import torchvision.models as models

net = models.resnet18(pretrained=True)
net = net.eval()

x = torch.rand(1, 3, 224, 224)
mod = torch.jit.trace(net, x)
mod.save("resnet18.pt")
------------------------------------------

context | 编译/运行环境 | バックグラウンド

torch-1.12.1, torchvision-0.13.1, windows 11

相关问题