建議先建立 Python 虛擬環境,再繼續安裝程序。如需詳細資訊,請參閱 TensorFlow 安裝指南。
穩定版本
如要安裝最新版本,請執行下列指令
# Installing with the `--upgrade` flag ensures you'll get the latest version.
pip install --user --upgrade tensorflow-model-optimization
如需版本詳細資料,請參閱我們的版本資訊。
如需 TensorFlow 的必要版本和其他相容性資訊,請參閱您打算使用的技術之「總覽」頁面的「API 相容性矩陣」一節。例如,如為剪枝,請參閱這裡的「總覽」頁面。
由於 TensorFlow 並未包含在 TensorFlow Model Optimization 套件的依附元件中 (在 setup.py
中),您必須明確安裝 TensorFlow 套件 (tf-nightly
或 tf-nightly-gpu
)。這樣一來,我們就能維護單一套件,而非 CPU 和啟用 GPU 的 TensorFlow 各自的套件。
從來源安裝
您也可以從來源安裝。這需要 Bazel 建構系統。
# To install dependencies on Ubuntu:
# sudo apt-get install bazel git python-pip
# For other platforms, see Bazel docs above.
git clone https://github.com/tensorflow/model-optimization.git
cd model-optimization
bazel build --copt=-O3 --copt=-march=native :pip_pkg
PKGDIR=$(mktemp -d)
./bazel-bin/pip_pkg $PKGDIR
pip install --user --upgrade $PKGDIR/*.whl