How do you prune a keras model?
Summary
- Train a tf. keras model for MNIST from scratch.
- Fine tune the model by applying the pruning API and see the accuracy.
- Create 3x smaller TF and TFLite models from pruning.
- Create a 10x smaller TFLite model from combining pruning and post-training quantization.
- See the persistence of accuracy from TF to TFLite.
How do you compress a model?
Model compression can be divided into two broad categories, Pruning : Removing redundant connections present in the architecture. Pruning involves cutting out unimportant weights (which are usually defined as weights with small absolute value).
How big is a compressed model of Keras?
The compressed 8-bit tensorflow lite model only takes 0.60 Mb compared to the original Keras model’s 12.52 Mb while maintaining comparable test accuracy. That’s totally x16 times size reduction. You can evaluate the accuracy of the converted TensorFlow Lite model like this where you feed the eval_model with the test dataset.
How to optimize for accuracy in keras model?
For details (including a code example), see own answer in What function defines accuracy in Keras when the loss is mean squared error (MSE)?; for a similar situation in scikit-learn, see own answer in this thread. without any metrics specified. We could of course use metrics=’mse’, but this is redundant and not really needed.
When to use Mae or Mae in keras model?
If I correctly understood the significance of the loss function to the model, it directs the model to be trained based on minimizing the loss value. So for example, if I want my model to be trained in order to have the least mean absolute error, i should use the MAE as the loss function.
How to compress your keras model X5 smaller with TensorFlow model optimization?
Now, simply using a generic file compression algorithm (e.g. zip), the Keras model will be reduced by x5 times. Here is what you get, x5 times smaller model. Tensorflow Lite is an example format you can use to deploy to mobile devices. To convert to a Tensorflow Lite graph, it is necessary to use the TFLiteConverter as below: