Install TensorFlow Model Optimization
Stay organized with collections
Save and categorize content based on your preferences.
It is recommended to create a Python virtual environment before proceeding to
the installation. Please see the TensorFlow installation
guide
for more information.
Stable Builds
To install the latest version, run the following:
# Installing with the `--upgrade` flag ensures you'll get the latest version.
pip install --user --upgrade tensorflow-model-optimization
For release details, see our
release notes.
For the required version of TensorFlow and other compatibility information, see
the API Compatibility Matrix section of the Overview page for the technique you
intend to use. For instance, for pruning, the Overview page is
here.
Since TensorFlow is not included as a dependency of the TensorFlow Model
Optimization package (in setup.py
), you must explicitly install the TensorFlow
package (tf-nightly
or tf-nightly-gpu
). This allows us to maintain one
package instead of separate packages for CPU and GPU-enabled TensorFlow.
Installing from Source
You can also install from source. This requires the
Bazel build system.
# 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
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2022-08-03 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2022-08-03 UTC."],[],[],null,["# Install TensorFlow Model Optimization\n\nIt is recommended to create a Python virtual environment before proceeding to\nthe installation. Please see the TensorFlow installation\n[guide](https://www.tensorflow.org/install/pip#2.-create-a-virtual-environment-recommended)\nfor more information.\n\n### Stable Builds\n\nTo install the latest version, run the following: \n\n # Installing with the `--upgrade` flag ensures you'll get the latest version.\n pip install --user --upgrade tensorflow-model-optimization\n\nFor release details, see our\n[release notes](https://github.com/tensorflow/model-optimization/releases).\n\nFor the required version of TensorFlow and other compatibility information, see\nthe API Compatibility Matrix section of the Overview page for the technique you\nintend to use. For instance, for pruning, the Overview page is\n[here](https://www.tensorflow.org/model_optimization/guide/pruning).\n\nSince TensorFlow is *not* included as a dependency of the TensorFlow Model\nOptimization package (in `setup.py`), you must explicitly install the TensorFlow\npackage (`tf-nightly` or `tf-nightly-gpu`). This allows us to maintain one\npackage instead of separate packages for CPU and GPU-enabled TensorFlow.\n\n### Installing from Source\n\nYou can also install from source. This requires the\n[Bazel](https://bazel.build/) build system. \n\n # To install dependencies on Ubuntu:\n # sudo apt-get install bazel git python-pip\n # For other platforms, see Bazel docs above.\n git clone https://github.com/tensorflow/model-optimization.git\n cd model-optimization\n bazel build --copt=-O3 --copt=-march=native :pip_pkg\n PKGDIR=$(mktemp -d)\n ./bazel-bin/pip_pkg $PKGDIR\n pip install --user --upgrade $PKGDIR/*.whl"]]