onnx 使用初體驗

需要使用 pytorch, caffe2, coreml, onnx.
由於 caffe2 只支持 python2, 使用 python2.7.14來作爲虛擬環境來編譯 pytorch的時候,報錯:

clang: error: invalid deployment target for -stdlib=libc++ (requires OS X 10.7 or later)
clang: error: invalid deployment target for -stdlib=libc++ (requires OS X 10.7 or later)
error: command '/usr/bin/clang' failed with exit status 1

clang error 可以添加
故選擇使用 anaconda2, 依次安裝依賴。

需要注意的是,由於已經有 anaconda3 的環境,在虛擬環境中使用 conda 命令的時候使用的依然是 anaconda3 的環境。如果在虛擬環境中需要使用 conda的時候,帶一下anaconda2的路徑即可。
各種路徑衝突,沒找到更好的辦法,只能在 conda info 中先用 anaconda2的路徑覆蓋 anaconda3 的路徑。

1. 安裝 onnx

github tutorial.

conda_path/conda install -c ezyang onnx

然後,檢驗是否安裝成功:

python -c 'import onnx'
ImportError: No module named onnx

好的,安裝失敗。

在覆蓋了conda的路徑之後,使用 conda 的方法來安裝 onnx.

conda install -c ezyang onnx

由於在下載 mkl的時候速度太慢了,可以前往 anaconda cloud 手動下載安裝 mkl.

python -c 'import onnx'

無報錯提示,安裝成功。

2. 安裝 onnx-coreml

github tutorial.

pip install -U onnx-coreml

順利安裝成功。

3. 安裝 pytorch

如果需要onnx相關依賴,需要從源碼安裝。
github tutorial.

Install optional dependencies
On mac OS
export CMAKE_PREFIX_PATH=[anaconda root directory]
conda install numpy pyyaml setuptools cmake cffi

Get the PyTorch source
git clone –recursive https://github.com/pytorch/pytorch

cd pytorch
MACOSX_DEPLOYMENT_TARGET=10.9 CC=clang CXX=clang++ python setup.py install

在電腦風扇封裝轉之後,安裝完成。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章