keras模型优化与压缩

Keras的模型压缩CLI工具

hard_compressor

用于keras的模型压缩CLI工具。

如何使用它

环境要求

Python 3.5, 3.6
Keras

安装方法

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

模型压缩

示例

keras-compressor.py model.h5 compressed.h5

带有精度参数

keras-compressor.py --error 0.001 model.h5 compressed.h5

帮助

$ keras-compressor.py --help                                                                               
Using TensorFlow backend.
usage: keras-compressor.py [-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
                        `model.compile()`.
  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 {CRITICAL,ERROR,WARNING,INFO,DEBUG}
                        log level. Default: INFO
                       

压缩demo

在示例目录中,您将找到使用MNIST和CIFAR10数据集的类似VGG的模型的模型压缩。

$ cd ./keras_compressor/example/mnist/

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

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

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

$ python evaluate.py model_raw.h5
$ python evaluate.py model_compressed.h5
$ python evaluate.py model_finetuned.h5
-> output test accuracy and the number of model parameters

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值