Skip to content
Model Compression CLI Tool for Keras.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin Fix count_total_params again Jun 13, 2017
example implement keras_compressor (#1) May 19, 2017
keras_compressor make compressor compatible to the keras API version 2.2.2 (#14) Dec 13, 2018
.gitignore specify tested keras version in readme (#7) Nov 7, 2017


Model compression CLI tool for keras.

How to use it


  • Python 3.5, 3.6
  • Keras
    • We tested on Keras 2.0.3 (TensorFlow backend)


$ git clone ${this repository}
$ cd ./keras_compressor
$ pip install .


Simple example:

$ model.h5 compressed.h5

With accuracy parameter error:

$ --error 0.001 model.h5 compressed.h5


$ --help                                                                               [impl_keras_compressor:keras_compressor]
Using TensorFlow backend.
usage: [-h] [--error 0.1]
                           [--log-level {CRITICAL,ERROR,WARNING,INFO,DEBUG}]
                           model.h5 compressed.h5

compress keras model

positional arguments:
  model.h5              target model, whose loss is specified by
  compressed.h5         compressed model path

optional arguments:
  -h, --help            show this help message and exit
  --error 0.1           layer-wise acceptable error. If this value is larger,
                        compressed model will be less accurate and achieve
                        better compression rate. Default: 0.1
                        log level. Default: INFO

How compress it

  • low-rank approximation
    • with SVD (matrix)
    • with Tucker (tensor)


In example directory, you will find model compression of VGG-like models using MNIST and CIFAR10 dataset.

$ cd ./keras_compressor/example/mnist/

$ python
-> outputs non-compressed model `model_raw.h5`

$ python
-> outputs compressed model `model_compressed.h5` from `model_raw.h5`

$ python
-> outputs finetuned and compressed model `model_finetuned.h5` from `model_compressed.h5`

$ python model_raw.h5
$ python model_compressed.h5
$ python model_finetuned.h5
-> output test accuracy and the number of model parameters
You can’t perform that action at this time.