将pytorch 模型转为 ncnn模型(vs 2019 )
文章目录
step 1 pth文件转为onnx文件
具体步骤可以参考:https://github.com/ultralytics/yolov5/blob/master/export.py
和https://blog.youkuaiyun.com/weixin_44753371/article/details/119328952的step1
step2:.onnx转ncnn模型
编译protobuf-3.4.0
下载 protobuf-3.4.0 https://github.com/google/protobuf/archive/v3.4.0.zip
cd <protobuf-root-dir>
mkdir build
cd build
cmake -G"NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=%cd%/install -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_MSVC_STATIC_RUNTIME=OFF ../cmake
nmake
nmake install
Build ncnn library
cd <ncnn-root-dir>
mkdir -p build
cd build
cmake -G"NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=%cd%/install -DProtobuf_INCLUDE_DIR=<protobuf-root-dir>/build/install/include -DProtobuf_LIBRARIES=<protobuf-root-dir>/build/install/lib/libprotobuf.lib -DProtobuf_PROTOC_EXECUTABLE=<protobuf-root-dir>/build/install/bin/protoc.exe ..
nmake
nmake install
或:
cd

该教程详细介绍了如何在Visual Studio 2019环境下将PyTorch模型转换为NCNN模型。首先,通过.pth文件转换为ONNX格式,然后编译protobuf-3.4.0和NCNN库,最后使用onnx2ncnn工具将ONNX模型转换为NCNN。过程中可能遇到nmake找不到、rc编译错误等问题,解决方法包括添加环境变量和修改CMake配置。完成转换后,将在NCNN的build目录下得到ncnn.bin和ncnn.param文件。
最低0.47元/天 解锁文章
2296

被折叠的 条评论
为什么被折叠?



