[英]How can I convert onnx format to ptl format?
Here I already got my .onnx
format file: retinaface.onnx
, I want to convert it to PyTorch mobile supported format: .ptl
or .pt
, then I can do inference in Android platform.这里我已经得到了我的
.onnx
格式文件: retinaface.onnx
,我想将它转换为 PyTorch 移动支持的格式: .ptl
或.pt
,然后我可以在 Android 平台上进行推理。 But I failed to convert or to find relevant issues.但我未能转换或找到相关问题。
// I want to load directly but failed
mRetinafaceDector = LiteModuleLoader.load(mModelPath + "/retinaface.onnx");
Seems the LiteModuleLoader.load()
can only load .ptl
or .pt
, but in my hand I only have retinaface.onnx
format..似乎
LiteModuleLoader.load()
只能加载.ptl
或.pt
,但在我手中我只有retinaface.onnx
格式..
You can't load onnx model directly to pytorch as it's not supported yet.您无法将 onnx model 直接加载到 pytorch,因为它尚不受支持。
Fortunately you can use onnx2pytorch
tool to convert onnx to pytorch幸运的是,您可以使用
onnx2pytorch
工具将 onnx 转换为 pytorch
Firstly install it: https://github.com/ToriML/onnx2pytorch首先安装它: https://github.com/ToriML/onnx2pytorch
Then you can easily convert it using this code:然后您可以使用以下代码轻松转换它:
onnx_model = onnx.load(path_to_onnx_model)
pytorch_model = ConvertModel(onnx_model)
nevertheless, check this issue, it's about importing onnx directly in pytorch:尽管如此,检查这个问题,它是关于直接在 pytorch 中导入 onnx:
https://github.com/pytorch/pytorch/issues/21683 https://github.com/pytorch/pytorch/issues/21683
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.