PaddleSlim is a sub-module of PaddlePaddle frame, which is first issued in the 1.4 version PaddlePaddle. In PaddleSlim, the mainstream compression strategies including pruning, quantization and distillation are realized and mainly applied to image compression models. In subsequent versions, more compression stratigies will be added to support models in NLP field.
## Main Features
Paddle-Slim tool library has the following features:
### Easy Interface
- Manage configurable parameters intensively by configuring-file ways for convenience for experiment management.
- Based on training scripts of common models, model compression can be realized by adding only a few codes.
Refer to [Use Examples](https://github.com/PaddlePaddle/models/blob/develop/PaddleSlim/docs/demo.md) for more details
### Good Performance
- For MobileNetV1 model with less redundant information, the convolution core pruning strategy can still reduce the size of the model and maintain as little accuracy loss as possible.
- The distillation strategy can increase the accuracy of the origin model dramatically.
- Combination of the quantization strategy and the distillation strategy can reduce the size ande increase the accuracy of the model at the same time.
Refer to [Performance Data and ModelZoo](https://github.com/PaddlePaddle/models/blob/develop/PaddleSlim/docs/model_zoo.md) for more details
### Stronger and More Flexible functions
- Automate the pruning and compression process
- The pruning and compression strategies support more network structures
- The distillation strategy supports multipy ways, and users can customize the combination of losses
- Support rapid configuration of multiple compression strategies for combined use
Refer to [Use Introduction](https://github.com/PaddlePaddle/models/blob/develop/PaddleSlim/docs/usage.md) for more details.
## Introduction to Framework
The overall principle of the model compression tool is briefly introduced here to make you understand the use process.
**figure 1** shows the architecture of the model compression tool, which is a API-relying relation from top to bottom. The distillation, quantization and pruning modules all rely on the bottom paddle framework indirectly. At present, the model compression tool serves as a part of PaddlePaddle framework, so users who have installed paddle of ordinary version have to download and install paddle supporting model compression again for the compression function.
As **figure 1** shows, the top purple module is user interface. When calling the model compression function in Python scripts, we only need to construct a Compressor object. Please refer to [Use Document](https://github.com/PaddlePaddle/models/blob/develop/PaddleSlim/docs/usage.md) for more details.
We call every compression algorithms compression strategies, which are called during the process of training models iteratively to complete model compression, as is shown in **figure 2**. The logic is packaged in the tool for model compression, and users only need to provide network structures, data and optimizers for model training. Please refer to [Use Document](https://github.com/PaddlePaddle/models/blob/develop/PaddleSlim/docs/usage.md) for more details.
- Support networks of VGG, ResNet and MobileNet types
- Support users to customize the pruning range
### Quantification training
- Support dynamic and static quantization training
- Dynamic strategy: count the activated quantizaiton papameters dynamically in inference process
- Static strategy: use the same quantization parameters counted from training data for different inputs in inference process
- Support overall and Channel-Wise quantization for weights
- Support to save models in the format compatible with Paddle Mobile
### Distillation
- Support to add combined loss in any layer of the teacher network and the student network
- Support FSP loss
- Support L2 loss
- Support softmax with cross-entropy loss
### Other Functions
- Support to manage hyper-parameters of compression tasks by configuration files
- Support to use combination of multiple compression strategies
## Brief Experiment Results
Some experiment results of the PaddleSlim model compression tool library are listed in this section. To download more experiment data and pre-training moels, please refer to [Specific Experiment Results and ModelZoo](https://github.com/PaddlePaddle/models/blob/develop/PaddleSlim/docs/model_zoo.md)
### Quantification Training
The data set to assess the experiment is the ImageNet 1000 classes of data, and the top-1 accuracy is token as measurable indicator:
the compression framework support to export models of following format:
-**the model format of Paddle Fluid:** can be loaded and used by Paddle framework.
-**the model format of Paddle Mobile:** can only be used in quantification training strategy situation, compatible with [Paddle Mobile](https://github.com/PaddlePaddle/paddle-mobile) model format.