对pytorch模型进行转换的时候报错: PytorchStreamReader failed locating file constants.pkl: file not found
收藏回复举报
对pytorch模型进行转换的时候报错: PytorchStreamReader failed locating file constants.pkl: file not found
t('forum.solved') 已解决
发表于2024-03-04 10:40:07
0 查看

系统环境: Ubuntu 20.04

MindSpore版本:  mindspore-lite-2.2.12-linux-x64    (从源码编译得到,编译时已开启   MSLITE_ENABLE_CONVERT_PYTORCH_MODEL = on)

已安装libtorch并配置环境变量:

export LD_LIBRARY_PATH=/home/ai/libtorch-2.0.1-cpu/lib:$LD_LIBRARY_PATH 

export LIB_TORCH_PATH=/home/ai/libtorch-2.0.1-cpu

pytorch权重文件: https://github.com/ultralytics/yolov5/releases/download/v7.0/yolov5s.pt

执行指令:./converter_lite --fmk=PYTORCH --modelFile=./yolov5s.pt --outputFile=model

报错日志:

 

[ERROR] LITE(1601974,7f615950cb80,converter_lite):2024-03-04-10:23:38.968.583 [mindspore/lite/tools/converter/converter.cc:1164] RunConverter] Exception occurred: PytorchStreamReader failed locating file constants.pkl: file not found 

Exception raised from valid at ../caffe2/serialize/inline_container.cc:178 (most recent call first): 

frame #0: c10::Error::Error(c10::SourceLocation, std::string) + 0x57 (0x7f615c871d77 in /home/ai/libtorch-2.0.1-cpu/lib/libc10.so) 

frame #1: c10::detail::torchCheckFail(char const*, char const*, unsigned int, std::string const&) + 0x64 (0x7f615c83babb in /home/ai/libtorch-2.0.1-cpu/lib/libc10.so) 

frame #2: caffe2::serialize::PyTorchStreamReader::valid(char const*, char const*) + 0x8e (0x7f616075c1de in /home/ai/libtorch-2.0.1-cpu/lib/libtorch_cpu.so) 

frame #3: caffe2::serialize::PyTorchStreamReader::getRecordID(std::string const&) + 0x46 (0x7f616075c3a6 in /home/ai/libtorch-2.0.1-cpu/lib/libtorch_cpu.so) 

frame #4: caffe2::serialize::PyTorchStreamReader::getRecord(std::string const&) + 0x5c (0x7f616075c46c in /home/ai/libtorch-2.0.1-cpu/lib/libtorch_cpu.so) 

frame #5: torch::jit::readArchiveAndTensors(std::string const&, std::string const&, std::string const&, c10::optional<std::function<c10::StrongTypePtr (c10::QualifiedName const&)> >, c10::optional<std::function<c10::intrusive_ptr<c10::ivalue::Object, c10::detail::intrusive_target_default_null_type<c10::ivalue::Object> > (c10::StrongTypePtr, c10::IValue)> >, c10::optional<c10::Device>, caffe2::serialize::PyTorchStreamReader&, c10::Type::SingletonOrSharedTypePtr<c10::Type> (*)(std::string const&), std::shared_ptr<torch::jit::DeserializationStorageContext>) + 0xa5 (0x7f61618af325 in /home/ai/libtorch-2.0.1-cpu/lib/libtorch_cpu.so) 

frame #6: <unknown function> + 0x4fd0fe7 (0x7f6161893fe7 in /home/ai/libtorch-2.0.1-cpu/lib/libtorch_cpu.so) 

frame #7: <unknown function> + 0x4fd4043 (0x7f6161897043 in /home/ai/libtorch-2.0.1-cpu/lib/libtorch_cpu.so) 

frame #8: torch::jit::import_ir_module(std::shared_ptr<torch::jit::CompilationUnit>, std::string const&, c10::optional<c10::Device>, std::unordered_map<std::string, std::string, std::hash<std::string>, std::equal_to<std::string>, std::allocator<std::pair<std::string const, std::string> > >&, bool, bool) + 0x3d6 (0x7f616189aed6 in /home/ai/libtorch-2.0.1-cpu/lib/libtorch_cpu.so) 

frame #9: torch::jit::import_ir_module(std::shared_ptr<torch::jit::CompilationUnit>, std::string const&, c10::optional<c10::Device>, bool) + 0x7f (0x7f616189b13f in /home/ai/libtorch-2.0.1-cpu/lib/libtorch_cpu.so) 

frame #10: torch::jit::load(std::string const&, c10::optional<c10::Device>, bool) + 0xac (0x7f616189b21c in /home/ai/libtorch-2.0.1-cpu/lib/libtorch_cpu.so) 

frame #11: mindspore::lite::PytorchModelParser::InitOriginModel(std::string const&) + 0x37b (0x7f6177aec96b in /home/ai/mindspore/mindspore-lite-2.2.12-linux-x64/tools/converter/lib/libmindspore_converter.so) 

frame #12: mindspore::lite::PytorchModelParser::Parse(mindspore::converter::ConverterParameters const&) + 0x414 (0x7f6177afbf94 in /home/ai/mindspore/mindspore-lite-2.2.12-linux-x64/tools/converter/lib/libmindspore_converter.so) 

frame #13: mindspore::lite::ConverterFuncGraph::Load3rdModelToFuncgraph(std::shared_ptr<mindspore::ConverterPara> const&) + 0x78a (0x7f6176f65ada in /home/ai/mindspore/mindspore-lite-2.2.12-linux-x64/tools/converter/lib/libmindspore_converter.so) 

frame #14: mindspore::lite::ConverterFuncGraph::Build(std::shared_ptr<mindspore::ConverterPara> const&) + 0x7c (0x7f6176f67d5c in /home/ai/mindspore/mindspore-lite-2.2.12-linux-x64/tools/converter/lib/libmindspore_converter.so) 

frame #15: mindspore::lite::ConverterImpl::HandleGraphCommon(std::shared_ptr<mindspore::ConverterPara> const&, void**, unsigned long*, bool, bool) + 0x147 (0x7f6176f59847 in /home/ai/mindspore/mindspore-lite-2.2.12-linux-x64/tools/converter/lib/libmindspore_converter.so) 

frame #16: mindspore::lite::ConverterImpl::Convert(std::shared_ptr<mindspore::ConverterPara> const&, void**, unsigned long*, bool) + 0x14c0 (0x7f6176f5b1c0 in /home/ai/mindspore/mindspore-lite-2.2.12-linux-x64/tools/converter/lib/libmindspore_converter.so) 

frame #17: mindspore::lite::RunConverter(std::shared_ptr<mindspore::ConverterPara> const&, void**, unsigned long*, bool) + 0x55 (0x7f6176f5b415 in /home/ai/mindspore/mindspore-lite-2.2.12-linux-x64/tools/converter/lib/libmindspore_converter.so) 

frame #18: mindspore::Converter::Convert() + 0x59 (0x7f6176f749f9 in /home/ai/mindspore/mindspore-lite-2.2.12-linux-x64/tools/converter/lib/libmindspore_converter.so) 

frame #19: <unknown function> + 0x17123 (0x55e9ff6f1123 in ./converter_lite) 

frame #20: __libc_start_main + 0xf3 (0x7f615c425083 in /usr/lib/x86_64-linux-gnu/libc.so.6) 

frame #21: <unknown function> + 0x17e0e (0x55e9ff6f1e0e in ./converter_lite) 

 

[ERROR] LITE(1601974,7f615950cb80,converter_lite):2024-03-04-10:23:38.968.646 [mindspore/lite/tools/converter/converter.cc:1168] RunConverter] Convert model failed 

[ERROR] LITE(1601974,7f615950cb80,converter_lite):2024-03-04-10:23:38.968.670 [mindspore/lite/tools/converter/cxx_api/converter.cc:374] Convert] Convert model failed, ret=Common error code. 

ERROR [mindspore/lite/tools/converter/converter_lite/main.cc:104] main] Convert failed. Ret: Common error code. 

Convert failed. Ret: Common error code. 

我要发帖子