Optimize machine learning models
import tensorflow as tf import tensorflow_model_optimization as tfmot import tf_keras as keras model = keras.Sequential([...]) pruning_schedule = tfmot.sparsity.keras.PolynomialDecay( initial_sparsity=0.0, final_sparsity=0.5, begin_step=2000, end_step=4000) model_for_pruning = tfmot.sparsity.keras.prune_low_magnitude( model, pruning_schedule=pruning_schedule) ... model_for_pruning.fit(...)
The TensorFlow Model Optimization Toolkit is a suite of tools for optimizing ML models for deployment and execution. Among many uses, the toolkit supports techniques used to:
- Reduce latency and inference cost for cloud and edge devices (e.g. mobile, IoT).
- Deploy models to edge devices with restrictions on processing, memory, power-consumption, network usage, and model storage space.
- Enable execution on and optimize for existing hardware or new special purpose accelerators.
Choose the model and optimization tool depending on your task:
-
Improve performance with off-the-shelf models
In many cases, pre-optimized models can improve the efficiency of your application. -
Use the TensorFlow Model Optimization Toolkit
Try the post-training tools to optimize an already-trained TensorFlow model. -
Optimize further
Use training-time optimization tools and learn about the techniques.