mxnet模型轉換onnx折騰了很久,終於搞清楚失敗原因
轉換代碼參考: https://github.com/onnx/tutorials/blob/master/tutorials/MXNetONNXExport.ipynb
一開始的環境:
- windows 10
- visual studio 2019
- python37
- mxnet==1.4.1
pip install onnx 安裝的是最新的1.6.0版本
運行到 “onnx_mxnet.export_model” 這一句代碼的時候 提示invalid *** array,然後就不能轉換了
mxnet.base.MXNetError: [10:25:05] C:\Jenkins\workspace\mxnet-tag\mxnet\src\ndarray\ndarray.cc:1805: Check failed: fi->Read(data) Invalid NDArray file format
好嘛, 我查資料說是onnx1.2.1版本可以轉換成功,(也有說1.2.2,1.3.0都可以的) pip install onnx==1.2.1竟然失敗
好,我源碼安裝,參考https://github.com/onnx/onnx/readme.md 一樣失敗 源碼折騰了近兩天啊
要瘋了
終於找到資料這麼說的:
Hi thanks for reporting this. It looks like you are build onnx for python2.7 using vc9.0. We highly suggested you switch to python3.5/6 on Windows because 1)onnx is developed with c++11 standard so dated VC cannot support some functions. 2) if using new VC (can do it in a conda3.5/6 with a py2.7 environment), there could be potential CRT libs mismatch in later uses or development (python 2.7 on windows is made with dated VC). it may cause more problem later.
這個人的問題(https://github.com/onnx/onnx/issues/936)跟我的不太一樣,但是它提醒了我,我的vc版本和python版本過高
更新後的環境:
- windows 10
- visual studio 2017
- python36
- mxnet==1.4.1
- onnx==1.2.1 (pip install onnx==1.2.1)
安裝成功了
運行提示:
[10:20:49] C:\Jenkins\workspace\mxnet-tag\mxnet\src\ndarray\ndarray.cc:1805: Check failed: fi->Read(data) Invalid NDArray file format
錯誤一樣