ONNX是facebook提出的一個 Open Neural Network Exchange協議,能夠讓訓練好的模型在不同的框架間進行交互。
ONNX的安裝相對來說不是特別麻煩,麻煩的是其依賴庫的安裝。ONNX依賴於pybind11。
首先依賴庫的安裝
sudo pip install pytest #pytest
sudo pip install numpy #numpy
sudo pip install scipy #scipy
下載pybind11源碼
git clone https://github.com/pybind/pybind11.git
如果你需要eigen庫的話,還需要先安裝eigen,這里我選擇的是無eigen的方式
新建一個編譯出來的文件夾
mkdir build
cd build
cmake ..
make -j4
sudo make install
這里有個問題,如果你同時存在python2.x和python3.x版本的話,默認選擇的是python3.x版本的,但是我現在的整個環境是python2.7.12,所以就必須禁用掉Python3.x,大家都說禁用,其實就是讓自動尋找方式找不到python3.x。
采用的方式是在/usr/bin中所有找到的python3.x相關的文件都移動到另一個文件夾內,然后開始編譯
裝好了pybind11之后(源碼版本編譯ONNX必須手動編譯pybind11,使用pip install pybind11並不管用)
編譯安裝onnx
git clone https://github.com/onnx/onnx.git
cd ./onnx
python setup.py build
sudo python setup.py install
這里很有可能會出現cmake提示 Protobuf compiler not found 的問題,因此需要安裝合適的protobuf編譯器
sudo apt-get install libprotobuf-dev protobuf-compiler