提交 11377e3c 编写于 作者: W wanghaoshuang

Update pages.

上级 95f07a0e
......@@ -128,7 +128,7 @@ SANAS(Simulated Annealing Neural Architecture Search)是基于模拟退火
- **tokens(list):** - 一组tokens。tokens的长度和范围取决于搜索空间。
**返回:**
根据传入的token得到一个模型结构实例。
根据传入的token得到一个模型结构实例列表
**示例代码:**
......@@ -153,8 +153,10 @@ SANAS(Simulated Annealing Neural Architecture Search)是基于模拟退火
**示例代码:**
.. code-block:: python
import paddle.fluid as fluid
from paddleslim.nas import SANAS
config = [('MobileNetV2Space')]
sanas = SANAS(configs=config)
print(sanas.current_info())
# 多进程蒸馏
# 大规模可扩展知识蒸馏框架 Pantheon
## Teacher
......@@ -100,7 +100,8 @@ pantheon.Teacher.start\_knowledge\_service(feed\_list, schema, program, reader\_
- **times (int):** The maximum repeated serving times, default 1. Whenever
the public method **get\_knowledge\_generator()** in **Student**
object called once, the serving times will be added one,
until reaching the maximum and ending the service.
until reaching the maximum and ending the service. Only
valid in online mode, and will be ignored in offline mode.
**Return:** None
......
......@@ -378,7 +378,7 @@ load_sensitivities
}
}
sensitivities_file = "sensitive_api_demo.data"
with open(sensitivities_file, 'w') as f:
with open(sensitivities_file, 'wb') as f:
pickle.dump(sen, f)
sensitivities = load_sensitivities(sensitivities_file)
print(sensitivities)
......
......@@ -17,3 +17,4 @@ API Documents
paddleslim.nas.one_shot.rst
paddleslim.pantheon.rst
search_space_en.rst
table_latency_en.md
# Table about hardware lantency
The table about hardware latency is used to evaluate the inference time in special environment and inference engine. The following text used to introduce the format that PaddleSlim support.
## Introduce
The table about hardware latency saved all possible operations, one operation in the table including type and parameters, such as: type can be `conv2d`, and corresponding parameters can be the size of feature map, number of kernel, and the size of kernel.
The latency of every operation depends on hardware and inference engine.
## Overview format
The table about hardware latency saved in the way of file or multi-line string.
The first line of the table about hardware latency saved the information about version, every line in the following represents a operation and its latency.
## Version
The information about version split by comma in the english format, and the detail is hardware, inference engine and timestamp.
- ** hardware: ** Used to mark the environment of hardware, including type of architecture, version and so on.
- ** inference engine: ** Used to mark inference engine, including the name of inference engine, version, optimize options and so on.
- ** timestamp: ** Used to mark the time of this table created.
## Operation
The information about operation split by comma in the english format, the information about operation and latency split by tabs.
### conv2d
**format**
```text
op_type,flag_bias,flag_relu,n_in,c_in,h_in,w_in,c_out,groups,kernel,padding,stride,dilation\tlatency
```
**introduce**
- **op_type(str)** - The type of this op.
- **flag_bias (int)** - Whether has bias or not(0: donot has bias, 1: has bias).
- **flag_relu (int)** - Whether has relu or not(0: donot has relu, 1: has relu).
- **n_in (int)** - The batch size of input.
- **c_in (int)** - The number of channel about input.
- **h_in (int)** - The height of input feature map.
- **w_in (int)** - The width of input feature map.
- **c_out (int)** - The number of channel about output.
- **groups (int)** - The group of conv2d.
- **kernel (int)** - The size of kernel.
- **padding (int)** - The size of padding.
- **stride (int)** - The size of stride.
- **dilation (int)** - The size of dilation.
- **latency (float)** - The latency of this op.
### activaiton
**format**
```text
op_type,n_in,c_in,h_in,w_in\tlatency
```
**introduce**
- **op_type(str)** - The type of this op.
- **n_in (int)** - The batch size of input.
- **c_in (int)** - The number of channel about input.
- **h_in (int)** - The height of input feature map.
- **w_in (int)** - The width of input feature map.
- **latency (float)** - The latency of this op.
### batch_norm
**format**
```text
op_type,active_type,n_in,c_in,h_in,w_in\tlatency
```
**introduce**
- **op_type(str)** - The type of this op.
- **active_type (string|None)** - The type of activation function, including relu, prelu, sigmoid, relu6, tanh.
- **n_in (int)** - The batch size of input.
- **c_in (int)** - The number of channel about input.
- **h_in (int)** - The height of input feature map.
- **w_in (int)** - The width of input feature map.
- **latency (float)** - The latency of this op.
### eltwise
**format**
```text
op_type,n_in,c_in,h_in,w_in\tlatency
```
**introduce**
- **op_type(str)** - The type of this op.
- **n_in (int)** - The batch size of input.
- **c_in (int)** - The number of channel about input.
- **h_in (int)** - The height of input feature map.
- **w_in (int)** - The width of input feature map.
- **latency (float)** - The latency of this op.
### pooling
**format**
```text
op_type,flag_global_pooling,n_in,c_in,h_in,w_in,kernel,padding,stride,ceil_mode,pool_type\tlatency
```
**introduce**
- **op_type(str)** - The type of this op.
- **flag_global_pooling (int)** - Whether is global pooling or not(0: is not global, 1: is global pooling).
- **n_in (int)** - The batch size of input.
- **c_in (int)** - The number of channel about input.
- **h_in (int)** - The height of input feature map.
- **w_in (int)** - The width of input feature map.
- **kernel (int)** - The size of kernel.
- **padding (int)** - The size of padding.
- **stride (int)** - The size of stride.
- **ceil_mode (int)** - Whether to compute height and width by using ceil function(0: use floor function, 1: use ceil function).
- **pool_type (int)** - The type of pooling(1: max pooling 2: average pooling including padding 3: average pooling excluding padding).
- **latency (float)** - The latency of this op.
### softmax
**format**
```text
op_type,axis,n_in,c_in,h_in,w_in\tlatency
```
**introduce**
- **op_type(str)** - The type of this op.
- **axis (int)** - The index to compute softmax, index in the range of [-1, rank-1], `rank` is the rank of input.
- **n_in (int)** - The batch size of input.
- **c_in (int)** - The number of channel about input.
- **h_in (int)** - The height of input feature map.
- **w_in (int)** - The width of input feature map.
- **latency (float)** - The latency of this op.
......@@ -3,8 +3,8 @@
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Welcome to use PaddleSlim.
========
Index
==============
.. toctree::
:maxdepth: 1
......@@ -16,3 +16,5 @@ Welcome to use PaddleSlim.
tutorials/index_en
api_en/index_en
model_zoo_en.md
.. mdinclude:: intro_en.md
# Install
安装PaddleSlim前,请确认已正确安装Paddle1.6版本或更新版本。Paddle安装请参考:[Paddle安装教程](https://www.paddlepaddle.org.cn/install/quick)。
Please ensure you have installed PaddlePaddle1.7+. [How to install PaddlePaddle](https://www.paddlepaddle.org.cn/install/quick)。
- 安装develop版本
- Install by pip
```bash
git clone https://github.com/PaddlePaddle/PaddleSlim.git
cd PaddleSlim
python setup.py install
pip install paddleslim -i https://pypi.org/simple
```
- 安装官方发布的最新版本
- Install from source
```bash
pip install paddleslim -i https://pypi.org/simple
git clone https://github.com/PaddlePaddle/PaddleSlim.git
cd PaddleSlim
python setup.py install
```
- 安装历史版本
- History packages
请点击[pypi.org](https://pypi.org/project/paddleslim/#history)查看可安装历史版本。
History packages is available in [pypi.org](https://pypi.org/project/paddleslim/#history).
# 介绍
PaddleSlim是一个模型压缩工具库,包含模型剪裁、定点量化、知识蒸馏、超参搜索和模型结构搜索等一系列模型压缩策略。
# PaddleSlim简介
对于业务用户,PaddleSlim提供完整的模型压缩解决方案,可用于图像分类、检测、分割等各种类型的视觉场景。
同时也在持续探索NLP领域模型的压缩方案。另外,PaddleSlim提供且在不断完善各种压缩策略在经典开源任务的benchmark,
以便业务用户参考。
对于模型压缩算法研究者或开发者,PaddleSlim提供各种压缩策略的底层辅助接口,方便用户复现、调研和使用最新论文方法。
PaddleSlim会从底层能力、技术咨询合作和业务场景等角度支持开发者进行模型压缩策略相关的创新工作。
PaddleSlim是PaddlePaddle框架的一个子模块,主要用于压缩图像领域模型。在PaddleSlim中,不仅实现了目前主流的网络剪枝、量化、蒸馏三种压缩策略,还实现了超参数搜索和小模型网络结构搜索功能。在后续版本中,会添加更多的压缩策略,以及完善对NLP领域模型的支持。
## 功能
- 模型剪裁
- 支持通道均匀模型剪裁(uniform pruning)
- 基于敏感度的模型剪裁
- 基于进化算法的自动模型剪裁三种方式
- 卷积通道均匀剪裁
- 基于敏感度的卷积通道剪裁
- 基于进化算法的自动剪裁
- 量化训练
- 定点量化
- 在线量化训练(training aware)
- 离线量化(post training)
- 支持对权重全局量化和Channel-Wise量化
- 知识蒸馏
- 支持单进程知识蒸馏
- 支持多进程分布式知识蒸馏
- 神经网络结构自动搜索(NAS)
- 支持One-Shot网络结构自动搜索(Ont-Shot-NAS)
- 支持基于进化算法的轻量神经网络结构自动搜索(Light-NAS)
- 支持基于进化算法的轻量神经网络结构自动搜索
- 支持One-Shot网络结构自动搜索
- 支持 FLOPS / 硬件延时约束
- 支持多平台模型延时评估
- 支持用户自定义搜索算法和搜索空间
## 部分压缩策略效果
### 分类模型
数据: ImageNet2012; 模型: MobileNetV1;
|压缩策略 |精度收益(baseline: 70.91%) |模型大小(baseline: 17.0M)|
|:---:|:---:|:---:|
| 知识蒸馏(ResNet50)| **+1.06%** | |
| 知识蒸馏(ResNet50) + int8量化训练 |**+1.10%**| **-71.76%**|
| 剪裁(FLOPs-50%) + int8量化训练|**-1.71%**|**-86.47%**|
### 图像检测模型
#### 数据:Pascal VOC;模型:MobileNet-V1-YOLOv3
| 压缩方法 | mAP(baseline: 76.2%) | 模型大小(baseline: 94MB) |
| :---------------------: | :------------: | :------------:|
| 知识蒸馏(ResNet34-YOLOv3) | **+2.8%** | |
| 剪裁 FLOPs -52.88% | **+1.4%** | **-67.76%** |
|知识蒸馏(ResNet34-YOLOv3)+剪裁(FLOPs-69.57%)| **+2.6%**|**-67.00%**|
#### 数据:COCO;模型:MobileNet-V1-YOLOv3
| 压缩方法 | mAP(baseline: 29.3%) | 模型大小|
| :---------------------: | :------------: | :------:|
| 知识蒸馏(ResNet34-YOLOv3) | **+2.1%** | |
| 知识蒸馏(ResNet34-YOLOv3)+剪裁(FLOPs-67.56%) | **-0.3%** | **-66.90%**|
### 搜索
数据:ImageNet2012; 模型:MobileNetV2
|硬件环境 | 推理耗时 | Top1准确率(baseline:71.90%) |
|:---------------:|:---------:|:--------------------:|
| RK3288 | **-23%** | +0.07% |
| Android cellphone | **-20%** | +0.16% |
| iPhone 6s | **-17%** | +0.32% |
# Introduction
PaddleSlim is a toolkit for model compression. It contains a collection of compression strategies, such as pruning, fixed point quantization, knowledge distillation, hyperparameter searching and neural architecture search.
# Introduction
PaddleSlim provides solutions of compression on computer vision models, such as image classification, object detection and semantic segmentation. Meanwhile, PaddleSlim Keeps exploring advanced compression strategies for language model. Furthermore, benckmark of compression strategies on some open tasks is available for your reference.
PaddleSlim also provides auxiliary and primitive API for developer and researcher to survey, implement and apply the method in latest papers. PaddleSlim will support developer in ability of framework and technology consulting.
## Features
### Pruning
- Uniform pruning of convolution
- Sensitivity-based prunning
- Automated pruning based evolution search strategy
- Support pruning of various deep architectures such as VGG, ResNet, and MobileNet.
- Support self-defined range of pruning, i.e., layers to be pruned.
### Fixed Point Quantization
- **Training aware**
- Dynamic strategy: During inference, we quantize models with hyperparameters dynamically estimated from small batches of samples.
- Static strategy: During inference, we quantize models with the same hyperparameters estimated from training data.
- Support layer-wise and channel-wise quantization.
- **Post training**
### Knowledge Distillation
- **Naive knowledge distillation:** transfers dark knowledge by merging the teacher and student model into the same Program
- **Paddle large-scale scalable knowledge distillation framework Pantheon:** a universal solution for knowledge distillation, more flexible than the naive knowledge distillation, and easier to scale to the large-scale applications.
- Decouple the teacher and student models --- they run in different processes in the same or different nodes, and transfer knowledge via TCP/IP ports or local files;
- Friendly to assemble multiple teacher models and each of them can work in either online or offline mode independently;
- Merge knowledge from different teachers and make batch data for the student model automatically;
- Support the large-scale knowledge prediction of teacher models on multiple devices.
### Neural Architecture Search
- Neural architecture search based on evolution strategy.
- Support distributed search.
- One-Shot neural architecture search.
- Support FLOPs and latency constrained search.
- Support the latency estimation on different hardware and platforms.
## Performance
### Image Classification
Dataset: ImageNet2012; Model: MobileNetV1;
|Method |Accuracy(baseline: 70.91%) |Model Size(baseline: 17.0M)|
|:---:|:---:|:---:|
| Knowledge Distillation(ResNet50)| **+1.06%** | |
| Knowledge Distillation(ResNet50) + int8 quantization |**+1.10%**| **-71.76%**|
| Pruning(FLOPs-50%) + int8 quantization|**-1.71%**|**-86.47%**|
### Object Detection
#### Dataset: Pascal VOC; Model: MobileNet-V1-YOLOv3
As a submodule of PaddlePaddle framework, PaddleSlim is an open-source library for deep model compression and architecture search. PaddleSlim supports current popular deep compression techniques such as pruning, quantization, and knowledge distillation. Further, it also automates the search of hyperparameters and the design of lightweight deep architectures. In the future, we will develop more practically useful compression techniques for industrial-level applications and transfer these techniques to models in NLP.
| Method | mAP(baseline: 76.2%) | Model Size(baseline: 94MB) |
| :---------------------: | :------------: | :------------:|
| Knowledge Distillation(ResNet34-YOLOv3) | **+2.8%** | |
| Pruning(FLOPs -52.88%) | **+1.4%** | **-67.76%** |
|Knowledge DistillationResNet34-YOLOv3)+Pruning(FLOPs-69.57%)| **+2.6%**|**-67.00%**|
## Methods
#### Dataset: COCO; Model: MobileNet-V1-YOLOv3
- Pruning
- Uniform pruning
- Sensitivity-based pruning
- Automated model pruning
| Method | mAP(baseline: 29.3%) | Model Size|
| :---------------------: | :------------: | :------:|
| Knowledge Distillation(ResNet34-YOLOv3) | **+2.1%** |-|
| Knowledge Distillation(ResNet34-YOLOv3)+Pruning(FLOPs-67.56%) | **-0.3%** | **-66.90%**|
- Quantization
- Training-aware quantization: Quantize models with hyperparameters dynamically estimated from small batches of samples.
- Training-aware quantization: Quantize models with the same hyperparameters estimated from training data.
- Support global quantization of weights and Channel-Wise quantization
### NAS
- Knowledge Distillation
- Single-process knowledge distillation
- Multi-process distributed knowledge distillation
Dataset: ImageNet2012; Model: MobileNetV2
- Network Architecture Search(NAS)
- Simulated Annealing (SA)-based lightweight network architecture search method.(Light-NAS)
- One-Shot network structure automatic search. (One-Shot-NAS)
- PaddleSlim supports FLOPs and latency constrained search.
- PaddleSlim supports the latency estimation on different hardware and platforms.
|Device | Infer time cost | Top1 accuracy(baseline:71.90%) |
|:---------------:|:---------:|:--------------------:|
| RK3288 | **-23%** | +0.07% |
| Android cellphone | **-20%** | +0.16% |
| iPhone 6s | **-17%** | +0.32% |
# 模型库
## 1. 图分类
## 1. 图分类
数据集:ImageNet1000类
......@@ -16,7 +16,7 @@
| MobileNetV2 | quant_aware |72.05%/90.63% (-0.1%/-0.02%)| 4.0 | - | [下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/MobileNetV2_quant_aware.tar) |
|ResNet50|-|76.50%/93.00%| 99 | 2.71 | [下载链接](http://paddle-imagenet-models-name.bj.bcebos.com/ResNet50_pretrained.tar) |
|ResNet50|quant_post|76.33%/93.02% (-0.17%/+0.02%)| 25.1| 1.19 | [下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/ResNet50_quant_post.tar) |
|ResNet50|quant_aware| 76.48%/93.11% (-0.02%/+0.11%)| 25.1 | 1.17 | [下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/ResNet50_quant_awre.tar) |
|ResNet50|quant_aware| 76.48%/93.11% (-0.02%/+0.11%)| 25.1 | 1.17 | [下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/ResNet50_quant_awre.tar) |
分类模型Lite时延(ms)
......@@ -57,20 +57,27 @@
### 1.2 剪裁
| 模型 | 压缩方法 | Top-1/Top-5 Acc | 模型体积(MB) | GFLOPs | 下载 |
|:--:|:---:|:--:|:--:|:--:|:--:|
| MobileNetV1 | Baseline | 70.99%/89.68% | 17 | 1.11 | [下载链接](http://paddle-imagenet-models-name.bj.bcebos.com/MobileNetV1_pretrained.tar) |
| MobileNetV1 | uniform -50% | 69.4%/88.66% (-1.59%/-1.02%) | 9 | 0.56 | [下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/MobileNetV1_uniform-50.tar) |
| MobileNetV1 | sensitive -30% | 70.4%/89.3% (-0.59%/-0.38%) | 12 | 0.74 | [下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/MobileNetV1_sensitive-30.tar) |
| MobileNetV1 | sensitive -50% | 69.8% / 88.9% (-1.19%/-0.78%) | 9 | 0.56 | [下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/MobileNetV1_sensitive-50.tar) |
| MobileNetV2 | - | 72.15%/90.65% | 15 | 0.59 | [下载链接](https://paddle-imagenet-models-name.bj.bcebos.com/MobileNetV2_pretrained.tar) |
| MobileNetV2 | uniform -50% | 65.79%/86.11% (-6.35%/-4.47%) | 11 | 0.296 | [下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/MobileNetV2_uniform-50.tar) |
| ResNet34 | - | 72.15%/90.65% | 84 | 7.36 | [下载链接](https://paddle-imagenet-models-name.bj.bcebos.com/ResNet34_pretrained.tar) |
| ResNet34 | uniform -50% | 70.99%/89.95% (-1.36%/-0.87%) | 41 | 3.67 | [下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/ResNet34_uniform-50.tar) |
| ResNet34 | auto -55.05% | 70.24%/89.63% (-2.04%/-1.06%) | 33 | 3.31 | [下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/ResNet34_auto-55.tar) |
PaddleLite推理耗时说明:
环境:Qualcomm SnapDragon 845 + armv8
速度指标:Thread1/Thread2/Thread4耗时
PaddleLite版本: v2.3
| 模型 | 压缩方法 | Top-1/Top-5 Acc | 模型体积(MB) | GFLOPs |PaddleLite推理耗时|TensorRT推理速度(FPS)| 下载 |
|:--:|:---:|:--:|:--:|:--:|:--:|:--:|:--:|
| MobileNetV1 | Baseline | 70.99%/89.68% | 17 | 1.11 |66.052\35.8014\19.5762|-| [下载链接](http://paddle-imagenet-models-name.bj.bcebos.com/MobileNetV1_pretrained.tar) |
| MobileNetV1 | uniform -50% | 69.4%/88.66% (-1.59%/-1.02%) | 9 | 0.56 | 33.5636\18.6834\10.5076|-|[下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/MobileNetV1_uniform-50.tar) |
| MobileNetV1 | sensitive -30% | 70.4%/89.3% (-0.59%/-0.38%) | 12 | 0.74 | 46.5958\25.3098\13.6982|-|[下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/MobileNetV1_sensitive-30.tar) |
| MobileNetV1 | sensitive -50% | 69.8% / 88.9% (-1.19%/-0.78%) | 9 | 0.56 |37.9892\20.7882\11.3144|-| [下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/MobileNetV1_sensitive-50.tar) |
| MobileNetV2 | - | 72.15%/90.65% | 15 | 0.59 |41.7874\23.375\13.3998|-| [下载链接](https://paddle-imagenet-models-name.bj.bcebos.com/MobileNetV2_pretrained.tar) |
| MobileNetV2 | uniform -50% | 65.79%/86.11% (-6.35%/-4.47%) | 11 | 0.296 |23.8842\13.8698\8.5572|-| [下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/MobileNetV2_uniform-50.tar) |
| ResNet34 | - | 72.15%/90.65% | 84 | 7.36 |217.808\139.943\96.7504|342.32| [下载链接](https://paddle-imagenet-models-name.bj.bcebos.com/ResNet34_pretrained.tar) |
| ResNet34 | uniform -50% | 70.99%/89.95% (-1.36%/-0.87%) | 41 | 3.67 |114.787\75.0332\51.8438|452.41| [下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/ResNet34_uniform-50.tar) |
| ResNet34 | auto -55.05% | 70.24%/89.63% (-2.04%/-1.06%) | 33 | 3.31 |105.924\69.3222\48.0246|457.25| [下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/ResNet34_auto-55.tar) |
### 1.3 蒸馏
......@@ -85,10 +92,25 @@
|ResNet101|teacher|77.56%/93.64%| 173 | [下载链接](http://paddle-imagenet-models-name.bj.bcebos.com/ResNet101_pretrained.tar) |
| ResNet50 | ResNet101 distill | 77.29%/93.65% (+0.79%/+0.65%) | 99 | [下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/ResNet50_distilled.tar) |
!!! note "Note"
注意:带"_vd"后缀代表该预训练模型使用了Mixup,Mixup相关介绍参考[mixup: Beyond Empirical Risk Minimization](https://arxiv.org/abs/1710.09412)
<a name="trans1">[1]</a>:带_vd后缀代表该预训练模型使用了Mixup,Mixup相关介绍参考[mixup: Beyond Empirical Risk Minimization](https://arxiv.org/abs/1710.09412)
### 1.4 搜索
数据集: ImageNet1000
| 模型 | 压缩方法 | Top-1/Top-5 Acc | 模型体积(MB) | GFLOPs | 下载 |
|:--:|:---:|:--:|:--:|:--:|:--:|
| MobileNetV2 | - | 72.15%/90.65% | 15 | 0.59 | [下载链接](https://paddle-imagenet-models-name.bj.bcebos.com/MobileNetV2_pretrained.tar) |
| MobileNetV2 | SANAS | 71.518%/90.208% (-0.632%/-0.442%) | 14 | 0.295 | [下载链接](https://paddlemodels.cdn.bcebos.com/PaddleSlim/MobileNetV2_sanas.tar) |
数据集: Cifar10
| 模型 |压缩方法 | Acc | 模型参数(MB) | 下载 |
|:---:|:--:|:--:|:--:|:--:|
| Darts | - | 97.135% | 3.767 | - |
| Darts_SA(基于Darts搜索空间) | SANAS | 97.276%(+0.141%) | 3.344(-11.2%) | - |
Note: MobileNetV2_NAS 的token是:[4, 4, 5, 1, 1, 2, 1, 1, 0, 2, 6, 2, 0, 3, 4, 5, 0, 4, 5, 5, 1, 4, 8, 0, 0]. Darts_SA的token是:[5, 5, 0, 5, 5, 10, 7, 7, 5, 7, 7, 11, 10, 12, 10, 0, 5, 3, 10, 8].
## 2. 目标检测
......@@ -99,8 +121,8 @@
| 模型 | 压缩方法 | 数据集 | Image/GPU | 输入608 Box AP | 输入416 Box AP | 输入320 Box AP | 模型体积(MB) | TensorRT时延(V100, ms) | 下载 |
| :----------------------------: | :---------: | :----: | :-------: | :------------: | :------------: | :------------: | :------------: | :----------: |:----------: |
| MobileNet-V1-YOLOv3 | - | COCO | 8 | 29.3 | 29.3 | 27.1 | 95 | - | [下载链接](https://paddlemodels.bj.bcebos.com/object_detection/yolov3_mobilenet_v1.tar) |
| MobileNet-V1-YOLOv3 | quant_post | COCO | 8 | 27.9 (-1.4)| 28.0 (-1.3) | 26.0 (-1.0) | 25 | - | [下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/yolov3_mobilenetv1_coco_quant_post.tar) |
| MobileNet-V1-YOLOv3 | quant_aware | COCO | 8 | 28.1 (-1.2)| 28.2 (-1.1) | 25.8 (-1.2) | 26.3 | - | [下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/yolov3_mobilenet_coco_quant_aware.tar) |
| MobileNet-V1-YOLOv3 | quant_post | COCO | 8 | 27.9 (-1.4)| 28.0 (-1.3) | 26.0 (-1.0) | 25 | - | [下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/yolov3_mobilenetv1_coco_quant_post.tar) |
| MobileNet-V1-YOLOv3 | quant_aware | COCO | 8 | 28.1 (-1.2)| 28.2 (-1.1) | 25.8 (-1.2) | 26.3 | - | [下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/yolov3_mobilenet_coco_quant_aware.tar) |
| R34-YOLOv3 | - | COCO | 8 | 36.2 | 34.3 | 31.4 | 162 | - | [下载链接](https://paddlemodels.bj.bcebos.com/object_detection/yolov3_r34.tar) |
| R34-YOLOv3 | quant_post | COCO | 8 | 35.7 (-0.5) | - | - | 42.7 | - | [下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/yolov3_r34_coco_quant_post.tar) |
| R34-YOLOv3 | quant_aware | COCO | 8 | 35.2 (-1.0) | 33.3 (-1.0) | 30.3 (-1.1)| 44 | - | [下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/yolov3_r34_coco_quant_aware.tar) |
......@@ -127,20 +149,29 @@
### 2.2 剪裁
数据集:Pasacl VOC & COCO 2017
| 模型 | 压缩方法 | 数据集 | Image/GPU | 输入608 Box AP | 输入416 Box AP | 输入320 Box AP | 模型体积(MB) | GFLOPs (608*608) | 下载 |
| :----------------------------: | :---------------: | :--------: | :-------: | :------------: | :------------: | :------------: | :----------: | :--------------: | :----------------------------------------------------------: |
| MobileNet-V1-YOLOv3 | Baseline | Pascal VOC | 8 | 76.2 | 76.7 | 75.3 | 94 | 40.49 | [下载链接](https://paddlemodels.bj.bcebos.com/object_detection/yolov3_mobilenet_v1_voc.tar) |
| MobileNet-V1-YOLOv3 | sensitive -52.88% | Pascal VOC | 8 | 77.6 (+1.4) | 77.7 (1.0) | 75.5 (+0.2) | 31 | 19.08 | [下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/yolov3_mobilenet_v1_voc_prune.tar) |
| MobileNet-V1-YOLOv3 | - | COCO | 8 | 29.3 | 29.3 | 27.0 | 95 | 41.35 | [下载链接](https://paddlemodels.bj.bcebos.com/object_detection/yolov3_mobilenet_v1.tar) |
| MobileNet-V1-YOLOv3 | sensitive -51.77% | COCO | 8 | 26.0 (-3.3) | 25.1 (-4.2) | 22.6 (-4.4) | 32 | 19.94 | [下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/yolov3_mobilenet_v1_prune.tar) |
| R50-dcn-YOLOv3 | - | COCO | 8 | 39.1 | - | - | 177 | 89.60 | [下载链接](https://paddlemodels.bj.bcebos.com/object_detection/yolov3_r50vd_dcn.tar) |
| R50-dcn-YOLOv3 | sensitive -9.37% | COCO | 8 | 39.3 (+0.2) | - | - | 150 | 81.20 | [下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/yolov3_r50vd_dcn_prune.tar) |
| R50-dcn-YOLOv3 | sensitive -24.68% | COCO | 8 | 37.3 (-1.8) | - | - | 113 | 67.48 | [下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/yolov3_r50vd_dcn_prune578.tar) |
| R50-dcn-YOLOv3 obj365_pretrain | - | COCO | 8 | 41.4 | - | - | 177 | 89.60 | [下载链接](https://paddlemodels.bj.bcebos.com/object_detection/yolov3_r50vd_dcn_obj365_pretrained_coco.tar) |
| R50-dcn-YOLOv3 obj365_pretrain | sensitive -9.37% | COCO | 8 | 40.5 (-0.9) | - | - | 150 | 81.20 | [下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/yolov3_r50vd_dcn_obj365_pretrained_coco_prune.tar) |
| R50-dcn-YOLOv3 obj365_pretrain | sensitive -24.68% | COCO | 8 | 37.8 (-3.3) | - | - | 113 | 67.48 | [下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/yolov3_r50vd_dcn_obj365_pretrained_coco_prune578.tar) |
PaddleLite推理耗时说明:
环境:Qualcomm SnapDragon 845 + armv8
速度指标:Thread1/Thread2/Thread4耗时
PaddleLite版本: v2.3
| 模型 | 压缩方法 | 数据集 | Image/GPU | 输入608 Box AP | 输入416 Box AP | 输入320 Box AP | 模型体积(MB) | GFLOPs (608*608) | PaddleLite推理耗时(ms)(608*608) | TensorRT推理速度(FPS)(608*608) | 下载 |
| :----------------------------: | :---------------: | :--------: | :-------: | :------------: | :------------: | :------------: | :----------: | :--------------: | :--------------: | :--------------: | :-----------------------------------: |
| MobileNet-V1-YOLOv3 | Baseline | Pascal VOC | 8 | 76.2 | 76.7 | 75.3 | 94 | 40.49 | 1238\796.943\520.101|60.04| [下载链接](https://paddlemodels.bj.bcebos.com/object_detection/yolov3_mobilenet_v1_voc.tar) |
| MobileNet-V1-YOLOv3 | sensitive -52.88% | Pascal VOC | 8 | 77.6 (+1.4) | 77.7 (1.0) | 75.5 (+0.2) | 31 | 19.08 | 602.497\353.759\222.427 |99.36| [下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/yolov3_mobilenet_v1_voc_prune.tar) |
| MobileNet-V1-YOLOv3 | - | COCO | 8 | 29.3 | 29.3 | 27.0 | 95 | 41.35 |-|-| [下载链接](https://paddlemodels.bj.bcebos.com/object_detection/yolov3_mobilenet_v1.tar) |
| MobileNet-V1-YOLOv3 | sensitive -51.77% | COCO | 8 | 26.0 (-3.3) | 25.1 (-4.2) | 22.6 (-4.4) | 32 | 19.94 |-|73.93| [下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/yolov3_mobilenet_v1_prune.tar) |
| R50-dcn-YOLOv3 | - | COCO | 8 | 39.1 | - | - | 177 | 89.60 |-|27.68| [下载链接](https://paddlemodels.bj.bcebos.com/object_detection/yolov3_r50vd_dcn.tar) |
| R50-dcn-YOLOv3 | sensitive -9.37% | COCO | 8 | 39.3 (+0.2) | - | - | 150 | 81.20 |-|30.08| [下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/yolov3_r50vd_dcn_prune.tar) |
| R50-dcn-YOLOv3 | sensitive -24.68% | COCO | 8 | 37.3 (-1.8) | - | - | 113 | 67.48 |-|34.32| [下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/yolov3_r50vd_dcn_prune578.tar) |
| R50-dcn-YOLOv3 obj365_pretrain | - | COCO | 8 | 41.4 | - | - | 177 | 89.60 |-|-| [下载链接](https://paddlemodels.bj.bcebos.com/object_detection/yolov3_r50vd_dcn_obj365_pretrained_coco.tar) |
| R50-dcn-YOLOv3 obj365_pretrain | sensitive -9.37% | COCO | 8 | 40.5 (-0.9) | - | - | 150 | 81.20 |-|-| [下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/yolov3_r50vd_dcn_obj365_pretrained_coco_prune.tar) |
| R50-dcn-YOLOv3 obj365_pretrain | sensitive -24.68% | COCO | 8 | 37.8 (-3.3) | - | - | 113 | 67.48 |-|-| [下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/yolov3_r50vd_dcn_obj365_pretrained_coco_prune578.tar) |
### 2.3 蒸馏
......@@ -157,6 +188,18 @@
| MobileNet-V1-YOLOv3 | ResNet34-YOLOv3 distill | COCO | 8 | 31.4 (+2.1) | 30.0 (+0.7) | 27.1 (+0.1) | 95 | [下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/yolov3_mobilenetv1_coco_distilled.tar) |
### 2.4 搜索
数据集:WIDER-FACE
| 模型 | 压缩方法 | Image/GPU | 输入尺寸 | Easy/Medium/Hard | 模型体积(KB) | 硬件延时(ms)| 下载 |
| :------------: | :---------: | :-------: | :------: | :-----------------------------: | :------------: | :------------: | :----------------------------------------------------------: |
| BlazeFace | - | 8 | 640 | 91.5/89.2/79.7 | 815 | 71.862 | [下载链接](https://paddlemodels.bj.bcebos.com/object_detection/blazeface_original.tar) |
| BlazeFace-NAS | - | 8 | 640 | 83.7/80.7/65.8 | 244 | 21.117 |[下载链接](https://paddlemodels.bj.bcebos.com/object_detection/blazeface_nas.tar) |
| BlazeFace-NASV2 | SANAS | 8 | 640 | 87.0/83.7/68.5 | 389 | 22.558 | [下载链接](https://paddlemodels.bj.bcebos.com/object_detection/blazeface_nas2.tar) |
Note: 硬件延时时间是利用提供的硬件延时表得到的,硬件延时表是在855芯片上基于PaddleLite测试的结果。BlazeFace-NASV2的详细配置在[这里](https://github.com/PaddlePaddle/PaddleDetection/blob/master/configs/face_detection/blazeface_nas_v2.yml).
## 3. 图像分割
数据集:Cityscapes
......@@ -201,8 +244,16 @@
### 3.2 剪裁
| 模型 | 压缩方法 | mIoU | 模型体积(MB) | GFLOPs | 下载 |
| :-------: | :---------------: | :-----------: | :------------: | :----: | :----------------------------------------------------------: |
| fast-scnn | baseline | 69.64 | 11 | 14.41 | [下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/fast_scnn_cityscape.tar) |
| fast-scnn | uniform -17.07% | 69.58 (-0.06) | 8.5 | 11.95 | [下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/fast_scnn_cityscape_uniform-17.tar) |
| fast-scnn | sensitive -47.60% | 66.68 (-2.96) | 5.7 | 7.55 | [下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/fast_scnn_cityscape_sensitive-47.tar) |
PaddleLite推理耗时说明:
环境:Qualcomm SnapDragon 845 + armv8
速度指标:Thread1/Thread2/Thread4耗时
PaddleLite版本: v2.3
| 模型 | 压缩方法 | mIoU | 模型体积(MB) | GFLOPs | PaddleLite推理耗时 | TensorRT推理速度(FPS) | 下载 |
| :-------: | :---------------: | :-----------: | :------------: | :----: | :------------: | :----: | :--------------------------------------: |
| fast-scnn | baseline | 69.64 | 11 | 14.41 | 1226.36\682.96\415.664 |39.53| [下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/fast_scnn_cityscape.tar) |
| fast-scnn | uniform -17.07% | 69.58 (-0.06) | 8.5 | 11.95 | 1140.37\656.612\415.888 |42.01| [下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/fast_scnn_cityscape_uniform-17.tar) |
| fast-scnn | sensitive -47.60% | 66.68 (-2.96) | 5.7 | 7.55 | 866.693\494.467\291.748 |51.48| [下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/fast_scnn_cityscape_sensitive-47.tar) |
此差异已折叠。
# SANAS进阶版实验教程-压缩DARTS产出模型
## 收益情况
利用DARTS搜索出来的最终模型结构(以下简称为DARTS_model)构造相应的搜索空间,根据PaddleSlim提供的SANAS搜索方法进行搜索实验,最终得到的模型结构(以下简称为DARTS_SA)相比DARTS_model的精度提升<font color=green>0.141%</font>,模型大小下降<font color=green>11.2%</font>。
## 搜索教程
本教程展示了如何在DARTS_model基础上利用SANAS进行搜索实验,并得到DARTS_SA的结果。
本教程包含以下步骤:
1. 构造搜索空间
2. 导入依赖包并定义全局变量
3. 初始化SANAS实例
4. 定义计算模型参数量的函数
5. 定义网络输入数据的函数
6. 定义造program的函数
7. 定义训练函数
8. 定义预测函数
9. 启动搜索
9.1 获取下一个模型结构
9.2 构造相应的训练和预测program
9.3 添加搜索限制
9.4 定义环境
9.5 定义输入数据
9.6 启动训练和评估
9.7 回传当前模型的得分reward
10. 利用demo下的脚本启动搜索
11. 利用demo下的脚本启动最终实验
### 1. 构造搜索空间
进行搜索实验之前,首先需要根据DARTS_model的模型特点构造相应的搜索空间,本次实验仅会对DARTS_model的通道数进行搜索,搜索的目的是得到一个精度更高并且模型参数更少的模型。
定义如下搜索空间:
- 通道数`filter_num`: 定义了每个卷积操作的通道数变化区间。取值区间为:`[4, 8, 12, 16, 20, 36, 54, 72, 90, 108, 144, 180, 216, 252]`
按照通道数来区分DARTS_model中block的话,则DARTS_model中共有3个block,第一个block仅包含6个normal cell,之后的两个block每个block都包含和一个reduction cell和6个normal cell,共有20个cell。在构造搜索空间的时候我们定义每个cell中的所有卷积操作都使用相同的通道数,共有20位token。
完整的搜索空间可以参考[基于DARTS_model的搜索空间](../../../paddleslim/nas/search_space/darts_space.py)
### 2. 引入依赖包并定义全局变量
```python
import numpy as np
import paddle
import paddle.fluid as fluid
from paddleslim.nas import SANAS
BATCH_SIZE=96
SERVER_ADDRESS = ""
PORT = 8377
SEARCH_STEPS = 300
RETAIN_EPOCH=30
MAX_PARAMS=3.77
IMAGE_SHAPE=[3, 32, 32]
AUXILIARY = True
AUXILIARY_WEIGHT= 0.4
TRAINSET_NUM = 50000
LR = 0.025
MOMENTUM = 0.9
WEIGHT_DECAY = 0.0003
DROP_PATH_PROBILITY = 0.2
```
### 3. 初始化SANAS实例
首先需要初始化SANAS示例。
```python
config = [('DartsSpace')]
sa_nas = SANAS(config, server_addr=(SERVER_ADDRESS, PORT), search_steps=SEARCH_STEPS, is_server=True)
```
### 4. 定义计算模型参数量的函数
根据输入的program计算当前模型中的参数量。本教程使用模型参数量作为搜索的限制条件。
```python
def count_parameters_in_MB(all_params, prefix='model'):
parameters_number = 0
for param in all_params:
if param.name.startswith(
prefix) and param.trainable and 'aux' not in param.name:
parameters_number += np.prod(param.shape)
return parameters_number / 1e6
```
### 5. 定义网络输入数据的函数
根据输入图片的尺寸定义网络中的输入,其中包括图片输入、标签输入和在训练过程中需要随机丢弃单元的比例和掩膜。
```python
def create_data_loader(IMAGE_SHAPE, is_train):
image = fluid.data(
name="image", shape=[None] + IMAGE_SHAPE, dtype="float32")
label = fluid.data(name="label", shape=[None, 1], dtype="int64")
data_loader = fluid.io.DataLoader.from_generator(
feed_list=[image, label],
capacity=64,
use_double_buffer=True,
iterable=True)
drop_path_prob = ''
drop_path_mask = ''
if is_train:
drop_path_prob = fluid.data(
name="drop_path_prob", shape=[BATCH_SIZE, 1], dtype="float32")
drop_path_mask = fluid.data(
name="drop_path_mask",
shape=[BATCH_SIZE, 20, 4, 2],
dtype="float32")
return data_loader, image, label, drop_path_prob, drop_path_mask
```
### 6. 定义构造program的函数
根据输入的模型结构、输入图片尺寸和当前program是否是训练模式构造program。
```python
def build_program(main_program, startup_program, IMAGE_SHAPE, archs, is_train):
with fluid.program_guard(main_program, startup_program):
data_loader, data, label, drop_path_prob, drop_path_mask = create_data_loader(
IMAGE_SHAPE, is_train)
logits, logits_aux = archs(data, drop_path_prob, drop_path_mask,
is_train, 10)
top1 = fluid.layers.accuracy(input=logits, label=label, k=1)
top5 = fluid.layers.accuracy(input=logits, label=label, k=5)
loss = fluid.layers.reduce_mean(
fluid.layers.softmax_with_cross_entropy(logits, label))
if is_train:
if AUXILIARY:
loss_aux = fluid.layers.reduce_mean(
fluid.layers.softmax_with_cross_entropy(logits_aux, label))
loss = loss + AUXILIARY_WEIGHT * loss_aux
step_per_epoch = int(TRAINSET_NUM / BATCH_SIZE)
learning_rate = fluid.layers.cosine_decay(LR, step_per_epoch, RETAIN_EPOCH)
fluid.clip.set_gradient_clip(
clip=fluid.clip.GradientClipByGlobalNorm(clip_norm=5.0))
optimizer = fluid.optimizer.MomentumOptimizer(
learning_rate,
MOMENTUM,
regularization=fluid.regularizer.L2DecayRegularizer(
WEIGHT_DECAY))
optimizer.minimize(loss)
outs = [loss, top1, top5, learning_rate]
else:
outs = [loss, top1, top5]
return outs, data_loader
```
### 7. 定义训练函数
```python
def train(main_prog, exe, epoch_id, train_loader, fetch_list):
loss = []
top1 = []
top5 = []
for step_id, data in enumerate(train_loader()):
devices_num = len(data)
if DROP_PATH_PROBILITY > 0:
feed = []
for device_id in range(devices_num):
image = data[device_id]['image']
label = data[device_id]['label']
drop_path_prob = np.array(
[[DROP_PATH_PROBILITY * epoch_id / RETAIN_EPOCH]
for i in range(BATCH_SIZE)]).astype(np.float32)
drop_path_mask = 1 - np.random.binomial(
1, drop_path_prob[0],
size=[BATCH_SIZE, 20, 4, 2]).astype(np.float32)
feed.append({
"image": image,
"label": label,
"drop_path_prob": drop_path_prob,
"drop_path_mask": drop_path_mask
})
else:
feed = data
loss_v, top1_v, top5_v, lr = exe.run(
main_prog, feed=feed, fetch_list=[v.name for v in fetch_list])
loss.append(loss_v)
top1.append(top1_v)
top5.append(top5_v)
if step_id % 10 == 0:
print(
"Train Epoch {}, Step {}, Lr {:.8f}, loss {:.6f}, acc_1 {:.6f}, acc_5 {:.6f}".
format(epoch_id, step_id, lr[0], np.mean(loss), np.mean(top1), np.mean(top5)))
return np.mean(top1)
```
### 8. 定义预测函数
```python
def valid(main_prog, exe, epoch_id, valid_loader, fetch_list):
loss = []
top1 = []
top5 = []
for step_id, data in enumerate(valid_loader()):
loss_v, top1_v, top5_v = exe.run(
main_prog, feed=data, fetch_list=[v.name for v in fetch_list])
loss.append(loss_v)
top1.append(top1_v)
top5.append(top5_v)
if step_id % 10 == 0:
print(
"Valid Epoch {}, Step {}, loss {:.6f}, acc_1 {:.6f}, acc_5 {:.6f}".
format(epoch_id, step_id, np.mean(loss), np.mean(top1), np.mean(top5)))
return np.mean(top1)
```
### 9. 启动搜索实验
以下步骤拆解说明了如何获得当前模型结构以及获得当前模型结构之后应该有的步骤。
#### 9.1 获取下一个模型结构
根据上面的SANAS实例中的函数获取下一个模型结构。
```python
archs = sa_nas.next_archs()[0]
```
#### 9.2 构造训练和预测program
根据上一步中获得的模型结构分别构造训练program和预测program。
```python
train_program = fluid.Program()
test_program = fluid.Program()
startup_program = fluid.Program()
train_fetch_list, train_loader = build_program(train_program, startup_program, IMAGE_SHAPE, archs, is_train=True)
test_fetch_list, test_loader = build_program(test_program, startup_program, IMAGE_SHAPE, archs, is_train=False)
test_program = test_program.clone(for_test=True)
```
#### 9.3 添加搜索限制
本教程以模型参数量为限制条件。首先计算一下当前program的参数量,如果超出限制条件,则终止本次模型结构的训练,获取下一个模型结构。
```python
current_params = count_parameters_in_MB(
train_program.global_block().all_parameters(), 'cifar10')
```
#### 9.4 定义环境
定义数据和模型的环境并初始化参数。
```python
place = fluid.CPUPlace()
exe = fluid.Executor(place)
exe.run(startup_program)
```
#### 9.5 定义输入数据
由于本示例中对cifar10中的图片进行了一些额外的预处理操作,和[快速开始](../quick_start/nas_tutorial.md)示例中的reader不同,所以需要自定义cifar10的reader,不能直接调用paddle中封装好的`paddle.dataset.cifar10`的reader。自定义cifar10的reader文件位于[demo/nas](../../../demo/nas/darts_cifar10_reader.py)中。
**注意:**本示例为了简化代码直接调用`paddle.dataset.cifar10`定义训练数据和预测数据,实际训练需要使用自定义cifar10的reader。
```python
train_reader = paddle.batch(paddle.reader.shuffle(paddle.dataset.cifar.train10(cycle=False), buf_size=1024), batch_size=BATCH_SIZE, drop_last=True)
test_reader = paddle.batch(paddle.dataset.cifar.test10(cycle=False), batch_size=BATCH_SIZE, drop_last=False)
train_loader.set_sample_list_generator(train_reader, places=place)
test_loader.set_sample_list_generator(test_reader, places=place)
```
#### 9.6 启动训练和评估
```python
for epoch_id in range(RETAIN_EPOCH):
train_top1 = train(train_program, exe, epoch_id, train_loader, train_fetch_list)
print("TRAIN: Epoch {}, train_acc {:.6f}".format(epoch_id, train_top1))
valid_top1 = valid(test_program, exe, epoch_id, test_loader, test_fetch_list)
print("TEST: Epoch {}, valid_acc {:.6f}".format(epoch_id, valid_top1))
valid_top1_list.append(valid_top1)
```
#### 9.7 回传当前模型的得分reward
本教程利用最后两个epoch的准确率均值作为最终的得分回传给SANAS。
```python
sa_nas.reward(float(valid_top1_list[-1] + valid_top1_list[-2]) / 2)
```
### 10. 利用demo下的脚本启动搜索
搜索文件位于: [darts_sanas_demo](https://github.com/PaddlePaddle/PaddleSlim/tree/develop/demo/nas/darts_nas.py),搜索过程中限制模型参数量为不大于3.77M。
```python
cd demo/nas/
python darts_nas.py
```
### 11. 利用demo下的脚本启动最终实验
最终实验文件位于: [darts_sanas_demo](https://github.com/PaddlePaddle/PaddleSlim/tree/develop/demo/nas/darts_nas.py),最终实验需要训练600epoch。以下示例输入token为`[5, 5, 0, 5, 5, 10, 7, 7, 5, 7, 7, 11, 10, 12, 10, 0, 5, 3, 10, 8]`。
```python
cd demo/nas/
python darts_nas.py --token 5 5 0 5 5 10 7 7 5 7 7 11 10 12 10 0 5 3 10 8 --retain_epoch 600
```
# Pruning of image classification model - sensitivity
In this tutorial, you will learn how to use [sensitivity API of PaddleSlim](https://paddlepaddle.github.io/PaddleSlim/api/prune_api/#sensitivity) by a demo of MobileNetV1 model on MNIST dataset。
This tutorial following workflow:
1. Import dependency
2. Build model
3. Define data reader
4. Define function for test
5. Training model
6. Get names of parameter
7. Compute sensitivities
8. Pruning model
## 1. Import dependency
PaddleSlim dependents on Paddle1.7. Please ensure that you have installed paddle correctly. Import Paddle and PaddleSlim as below:
```python
import paddle
import paddle.fluid as fluid
import paddleslim as slim
```
## 2. Build model
This section will build a classsification model based `MobileNetV1` for MNIST task. The shape of the input is `[1, 28, 28]` and the output number is 10.
To make the code simple, we define a function in package `paddleslim.models` to build classification model.
Excute following code to build a model,
```python
exe, train_program, val_program, inputs, outputs = slim.models.image_classification("MobileNet", [1, 28, 28], 10, use_gpu=True)
place = fluid.CUDAPlace(0)
```
>Note:The functions in paddleslim.models is just used in tutorials or demos.
## 3 Define data reader
MNIST dataset is used for making the demo can be executed quickly. It defines some functions for downloading and reading MNIST dataset in package `paddle.dataset.mnist`.
Show as below:
```python
import paddle.dataset.mnist as reader
train_reader = paddle.batch(
reader.train(), batch_size=128, drop_last=True)
test_reader = paddle.batch(
reader.test(), batch_size=128, drop_last=True)
data_feeder = fluid.DataFeeder(inputs, place)
```
## 4. Define test function
To get the performance of model on test dataset after pruning a convolution layer, we define a test function as below:
```python
import numpy as np
def test(program):
acc_top1_ns = []
acc_top5_ns = []
for data in test_reader():
acc_top1_n, acc_top5_n, _ = exe.run(
program,
feed=data_feeder.feed(data),
fetch_list=outputs)
acc_top1_ns.append(np.mean(acc_top1_n))
acc_top5_ns.append(np.mean(acc_top5_n))
print("Final eva - acc_top1: {}; acc_top5: {}".format(
np.mean(np.array(acc_top1_ns)), np.mean(np.array(acc_top5_ns))))
return np.mean(np.array(acc_top1_ns))
```
## 5. Training model
Sensitivity analysis is dependent on pretrained model. So we should train the model defined in section 2 for some epochs. One epoch training is enough for this simple demo while more epochs may be necessary for other model. Or you can load pretrained model from filesystem.
Training model as below:
```python
for data in train_reader():
acc1, acc5, loss = exe.run(train_program, feed=data_feeder.feed(data), fetch_list=outputs)
print(np.mean(acc1), np.mean(acc5), np.mean(loss))
```
Get the performance using the test function defined in section 4:
```python
test(val_program)
```
## 6. Get names of parameters
```python
params = []
for param in train_program.global_block().all_parameters():
if "_sep_weights" in param.name:
params.append(param.name)
print(params)
params = params[:5]
```
## 7. Compute sensitivities
### 7.1 Compute in single process
Apply sensitivity analysis on pretrained model by calling [sensitivity API](https://paddlepaddle.github.io/PaddleSlim/api/prune_api/#sensitivity).
The sensitivities will be appended into the file given by option `sensitivities_file` during computing.
The information in this file won`t be computed repeatedly.
Remove the file `sensitivities_0.data` in current directory:
```python
!rm -rf sensitivities_0.data
```
Apart from the parameters to be analyzed, it also support for setting the ratios that each convolutoin will be pruned.
If one model losses 90% accuracy on test dataset when its single convolution layer is pruned by 40%, then we can set `pruned_ratios` to `[0.1, 0.2, 0.3, 0.4]`.
The granularity of `pruned_ratios` should be small to get more reasonable sensitivities. But small granularity of `pruned_ratios` will slow down the computing.
```python
sens_0 = slim.prune.sensitivity(
val_program,
place,
params,
test,
sensitivities_file="sensitivities_0.data",
pruned_ratios=[0.1, 0.2])
print(sens_0)
```
### 7.2 Expand sensitivities
We can expand `pruned_ratios` to `[0.1, 0.2, 0.3]` based the sensitivities generated in section 7.1.
```python
sens_0 = slim.prune.sensitivity(
val_program,
place,
params,
test,
sensitivities_file="sensitivities_0.data",
pruned_ratios=[0.3])
print(sens_0)
```
### 7.3 Computing sensitivity in multi-process
The time cost of computing sensitivities is dependent on the count of parameters and the speed of model evaluation on test dataset. We can speed up computing by multi-process.
Split `pruned_ratios` into multi-process, and merge the sensitivities from multi-process.
#### 7.3.1 Computing in each process
We have compute the sensitivities when `pruned_ratios=[0.1, 0.2, 0.3]` and saved the sensitivities into file named `sensitivities_0.data`.
在另一个进程中,The we start a task by setting `pruned_ratios=[0.4]` in another process and save result into file named `sensitivities_1.data`. Show as below:
```python
sens_1 = slim.prune.sensitivity(
val_program,
place,
params,
test,
sensitivities_file="sensitivities_1.data",
pruned_ratios=[0.4])
print(sens_1)
```
#### 7.3.2 Load sensitivity file generated in multi-process
```python
s_0 = slim.prune.load_sensitivities("sensitivities_0.data")
s_1 = slim.prune.load_sensitivities("sensitivities_1.data")
print(s_0)
print(s_1)
```
#### 7.3.3 Merge sensitivies
```python
s = slim.prune.merge_sensitive([s_0, s_1])
print(s)
```
## 8. Pruning model
Pruning model according to the sensitivities generated in section 7.3.3.
### 8.1 Get pruning ratios
Get a group of ratios by calling [get_ratios_by_loss](https://paddlepaddle.github.io/PaddleSlim/api/prune_api/#get_ratios_by_loss) fuction:
```python
loss = 0.01
ratios = slim.prune.get_ratios_by_loss(s_0, loss)
print(ratios)
```
### 8.2 Pruning training network
```python
pruner = slim.prune.Pruner()
print("FLOPs before pruning: {}".format(slim.analysis.flops(train_program)))
pruned_program, _, _ = pruner.prune(
train_program,
fluid.global_scope(),
params=ratios.keys(),
ratios=ratios.values(),
place=place)
print("FLOPs after pruning: {}".format(slim.analysis.flops(pruned_program)))
```
### 8.3 Pruning test network
Note:The `only_graph` should be set to True while pruning test network. [Pruner API](https://paddlepaddle.github.io/PaddleSlim/api/prune_api/#pruner)
```python
pruner = slim.prune.Pruner()
print("FLOPs before pruning: {}".format(slim.analysis.flops(val_program)))
pruned_val_program, _, _ = pruner.prune(
val_program,
fluid.global_scope(),
params=ratios.keys(),
ratios=ratios.values(),
place=place,
only_graph=True)
print("FLOPs after pruning: {}".format(slim.analysis.flops(pruned_val_program)))
```
Get accuracy of pruned model on test dataset:
```python
test(pruned_val_program)
```
### 8.4 Training pruned model
Training pruned model:
```python
for data in train_reader():
acc1, acc5, loss = exe.run(pruned_program, feed=data_feeder.feed(data), fetch_list=outputs)
print(np.mean(acc1), np.mean(acc5), np.mean(loss))
```
Get accuracy of model after training:
```python
test(pruned_val_program)
```
......@@ -3,9 +3,13 @@
========
.. toctree::
:maxdepth: 2
:caption: Contents:
:maxdepth: 1
image_classification_sensitivity_analysis_tutorial.md
image_classification_nas_quick_start.ipynb
darts_nas_turorial.md
paddledetection_slim_distillation_tutorial.md
paddledetection_slim_nas_tutorial.md
paddledetection_slim_pruing_tutorial.md
paddledetection_slim_prune_dist_tutorial.md
paddledetection_slim_quantization_tutorial.md
paddledetection_slim_sensitivy_tutorial.md
......@@ -4,5 +4,5 @@ Aadvanced Tutorials
.. toctree::
:maxdepth: 1
sensitivity_tutorial_en.md
image_classification_sensitivity_analysis_tutorial_en.md
# 目标检测模型蒸馏教程
教程内容请参考:https://github.com/PaddlePaddle/PaddleDetection/blob/release/0.2/slim/distillation/README.md
## 示例结果
### MobileNetV1-YOLO-V3-VOC
| FLOPS |输入尺寸|每张GPU图片个数|推理时间(fps)|Box AP|下载|
|:-:|:-:|:-:|:-:|:-:|:-:|
|baseline|608 |16|104.291|76.2|[下载链接](https://paddlemodels.bj.bcebos.com/object_detection/yolov3_mobilenet_v1_voc.tar)|
|蒸馏后|608 |16|106.914|79.0|[下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/yolov3_mobilenetv1_voc_distilled.tar)|
|baseline|416 |16|-|76.7|[下载链接](https://paddlemodels.bj.bcebos.com/object_detection/yolov3_mobilenet_v1_voc.tar)|
|蒸馏后|416 |16|-|78.2|[下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/yolov3_mobilenetv1_voc_distilled.tar)|
|baseline|320 |16|-|75.3|[下载链接](https://paddlemodels.bj.bcebos.com/object_detection/yolov3_mobilenet_v1_voc.tar)|
|蒸馏后|320 |16|-|75.5|[下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/yolov3_mobilenetv1_voc_distilled.tar)|
> 蒸馏后的结果用ResNet34-YOLO-V3做teacher,4GPU总batch_size64训练90000 iter得到
### MobileNetV1-YOLO-V3-COCO
| FLOPS |输入尺寸|每张GPU图片个数|推理时间(fps)|Box AP|下载|
|:-:|:-:|:-:|:-:|:-:|:-:|
|baseline|608 |16|78.302|29.3|[下载链接](https://paddlemodels.bj.bcebos.com/object_detection/yolov3_mobilenet_v1_voc.tar)|
|蒸馏后|608 |16|78.523|31.4|[下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/yolov3_mobilenetv1_coco_distilled.tar)|
|baseline|416 |16|-|29.3|[下载链接](https://paddlemodels.bj.bcebos.com/object_detection/yolov3_mobilenet_v1_voc.tar)|
|蒸馏后|416 |16|-|30.0|[下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/yolov3_mobilenetv1_coco_distilled.tar)|
|baseline|320 |16|-|27.0|[下载链接](https://paddlemodels.bj.bcebos.com/object_detection/yolov3_mobilenet_v1_voc.tar)|
|蒸馏后|320 |16|-|27.1|[下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/yolov3_mobilenetv1_coco_distilled.tar)|
> 蒸馏后的结果用ResNet34-YOLO-V3做teacher,4GPU总batch_size64训练600000 iter得到
# 人脸检测模型小模型结构搜索教程
教程内容请参考:https://github.com/PaddlePaddle/PaddleDetection/blob/release/0.2/slim/nas/README.md
## 概述
我们选取人脸检测的BlazeFace模型作为神经网络搜索示例,该示例使用PaddleSlim 辅助完成神经网络搜索实验。
基于PaddleSlim进行搜索实验过程中,搜索限制条件可以选择是浮点运算数(FLOPs)限制还是硬件延时(latency)限制,硬件延时限制需要提供延时表。本示例提供一份基于blazeface搜索空间的硬件延时表,名称是latency_855.txt(基于PaddleLite在骁龙855上测试的延时),可以直接用该表进行blazeface的硬件延时搜索实验。
# 目标检测模型卷积通道剪裁教程
请参考:https://github.com/PaddlePaddle/PaddleDetection/blob/release/0.2/slim/prune/README.md
# 目标检测模型蒸馏剪裁教程
教程内容请参考:https://github.com/PaddlePaddle/PaddleDetection/blob/release/0.2/slim/extensions/distill_pruned_model/README.md
## 概述
该文档介绍如何使用PaddleSlim的蒸馏接口和卷积通道剪裁接口对检测库中的模型进行卷积层的通道剪裁并使用较高精度模型对其蒸馏。
# 目标检测模型定点量化教程
教程内容请参考:https://github.com/PaddlePaddle/PaddleDetection/blob/release/0.2/slim/quantization/README.md
## 示例结果
### 训练策略
- 量化策略`post`为使用离线量化得到的模型,`aware`为在线量化训练得到的模型。
### YOLOv3 on COCO
| 骨架网络 | 预训练权重 | 量化策略 | 输入尺寸 | Box AP | 下载 |
| :----------------| :--------: | :------: | :------: |:------: | :-----------------------------------------------------: |
| MobileNetV1 | ImageNet | post | 608 | 27.9 | [下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/yolov3_mobilenetv1_coco_quant_post.tar) |
| MobileNetV1 | ImageNet | post | 416 | 28.0 | [下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/yolov3_mobilenetv1_coco_quant_post.tar) |
| MobileNetV1 | ImageNet | post | 320 | 26.0 | [下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/yolov3_mobilenetv1_coco_quant_post.tar) |
| MobileNetV1 | ImageNet | aware | 608 | 28.1 | [下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/yolov3_mobilenetv1_coco_quant_aware.tar) |
| MobileNetV1 | ImageNet | aware | 416 | 28.2 | [下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/yolov3_mobilenetv1_coco_quant_aware.tar) |
| MobileNetV1 | ImageNet | aware | 320 | 25.8 | [下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/yolov3_mobilenetv1_coco_quant_aware.tar) |
| ResNet34 | ImageNet | post | 608 | 35.7 | [下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/yolov3_r34_coco_quant_post.tar) |
| ResNet34 | ImageNet | aware | 608 | 35.2 | [下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/yolov3_r34_coco_quant_aware.tar) |
| ResNet34 | ImageNet | aware | 416 | 33.3 | [下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/yolov3_r34_coco_quant_aware.tar) |
| ResNet34 | ImageNet | aware | 320 | 30.3 | [下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/yolov3_r34_coco_quant_aware.tar) |
| R50vd-dcn | object365 | aware | 608 | 40.6 | [下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/yolov3_r50vd_dcn_obj365_pretrained_coco_quant_aware.tar) |
| R50vd-dcn | object365 | aware | 416 | 37.5 | [下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/yolov3_r50vd_dcn_obj365_pretrained_coco_quant_aware.tar) |
| R50vd-dcn | object365 | aware | 320 | 34.1 | [下载链接](https://paddlemodels.bj.bcebos.com/PaddleSlim/yolov3_r50vd_dcn_obj365_pretrained_coco_quant_aware.tar) |
# 目标检测模型敏感度分析教程
教程内容请参考:https://github.com/PaddlePaddle/PaddleDetection/blob/release/0.2/slim/sensitive/README.md
此差异已折叠。
......@@ -83,7 +83,7 @@
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../index_en.html">English Documents</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intro.html">PaddleSlim简介</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intro.html">介绍</a></li>
<li class="toctree-l1"><a class="reference internal" href="../install.html">安装</a></li>
<li class="toctree-l1"><a class="reference internal" href="../quick_start/index.html">快速开始</a></li>
<li class="toctree-l1"><a class="reference internal" href="../tutorials/index.html">进阶教程</a></li>
......@@ -96,7 +96,7 @@
</li>
<li class="toctree-l2"><a class="reference internal" href="nas_api.html">SA-NAS</a></li>
<li class="toctree-l2"><a class="reference internal" href="one_shot_api.html">OneShotNAS</a></li>
<li class="toctree-l2"><a class="reference internal" href="pantheon_api.html">多进程蒸馏</a></li>
<li class="toctree-l2"><a class="reference internal" href="pantheon_api.html">大规模可扩展知识蒸馏框架 Pantheon</a></li>
<li class="toctree-l2"><a class="reference internal" href="prune_api.html">卷积层通道剪裁</a></li>
<li class="toctree-l2"><a class="reference internal" href="quantization_api.html">量化</a></li>
<li class="toctree-l2"><a class="reference internal" href="single_distiller_api.html">简单蒸馏</a></li>
......
......@@ -35,7 +35,7 @@
<link rel="search" title="搜索" href="../search.html"/>
<link rel="top" title="PaddleSlim 1.0 文档" href="../index.html"/>
<link rel="next" title="模型分析" href="analysis_api.html"/>
<link rel="prev" title="图像分类模型通道剪裁-敏感度分析" href="../tutorials/image_classification_sensitivity_analysis_tutorial.html"/>
<link rel="prev" title="目标检测模型敏感度分析教程" href="../tutorials/paddledetection_slim_sensitivy_tutorial.html"/>
<script src="../_static/js/modernizr.min.js"></script>
......@@ -82,7 +82,7 @@
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../index_en.html">English Documents</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intro.html">PaddleSlim简介</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intro.html">介绍</a></li>
<li class="toctree-l1"><a class="reference internal" href="../install.html">安装</a></li>
<li class="toctree-l1"><a class="reference internal" href="../quick_start/index.html">快速开始</a></li>
<li class="toctree-l1"><a class="reference internal" href="../tutorials/index.html">进阶教程</a></li>
......@@ -90,7 +90,7 @@
<li class="toctree-l2"><a class="reference internal" href="analysis_api.html">模型分析</a></li>
<li class="toctree-l2"><a class="reference internal" href="nas_api.html">SA-NAS</a></li>
<li class="toctree-l2"><a class="reference internal" href="one_shot_api.html">OneShotNAS</a></li>
<li class="toctree-l2"><a class="reference internal" href="pantheon_api.html">多进程蒸馏</a></li>
<li class="toctree-l2"><a class="reference internal" href="pantheon_api.html">大规模可扩展知识蒸馏框架 Pantheon</a></li>
<li class="toctree-l2"><a class="reference internal" href="prune_api.html">卷积层通道剪裁</a></li>
<li class="toctree-l2"><a class="reference internal" href="quantization_api.html">量化</a></li>
<li class="toctree-l2"><a class="reference internal" href="single_distiller_api.html">简单蒸馏</a></li>
......@@ -151,7 +151,7 @@
<li class="toctree-l1"><a class="reference internal" href="analysis_api.html">模型分析</a></li>
<li class="toctree-l1"><a class="reference internal" href="nas_api.html">SA-NAS</a></li>
<li class="toctree-l1"><a class="reference internal" href="one_shot_api.html">OneShotNAS</a></li>
<li class="toctree-l1"><a class="reference internal" href="pantheon_api.html">多进程蒸馏</a></li>
<li class="toctree-l1"><a class="reference internal" href="pantheon_api.html">大规模可扩展知识蒸馏框架 Pantheon</a></li>
<li class="toctree-l1"><a class="reference internal" href="prune_api.html">卷积层通道剪裁</a></li>
<li class="toctree-l1"><a class="reference internal" href="quantization_api.html">量化</a></li>
<li class="toctree-l1"><a class="reference internal" href="single_distiller_api.html">简单蒸馏</a></li>
......@@ -171,7 +171,7 @@
<a href="analysis_api.html" class="btn btn-neutral float-right" title="模型分析" accesskey="n">Next <span class="fa fa-arrow-circle-right"></span></a>
<a href="../tutorials/image_classification_sensitivity_analysis_tutorial.html" class="btn btn-neutral" title="图像分类模型通道剪裁-敏感度分析" accesskey="p"><span class="fa fa-arrow-circle-left"></span> Previous</a>
<a href="../tutorials/paddledetection_slim_sensitivy_tutorial.html" class="btn btn-neutral" title="目标检测模型敏感度分析教程" accesskey="p"><span class="fa fa-arrow-circle-left"></span> Previous</a>
</div>
......
......@@ -83,7 +83,7 @@
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../index_en.html">English Documents</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intro.html">PaddleSlim简介</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intro.html">介绍</a></li>
<li class="toctree-l1"><a class="reference internal" href="../install.html">安装</a></li>
<li class="toctree-l1"><a class="reference internal" href="../quick_start/index.html">快速开始</a></li>
<li class="toctree-l1"><a class="reference internal" href="../tutorials/index.html">进阶教程</a></li>
......@@ -95,7 +95,7 @@
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="one_shot_api.html">OneShotNAS</a></li>
<li class="toctree-l2"><a class="reference internal" href="pantheon_api.html">多进程蒸馏</a></li>
<li class="toctree-l2"><a class="reference internal" href="pantheon_api.html">大规模可扩展知识蒸馏框架 Pantheon</a></li>
<li class="toctree-l2"><a class="reference internal" href="prune_api.html">卷积层通道剪裁</a></li>
<li class="toctree-l2"><a class="reference internal" href="quantization_api.html">量化</a></li>
<li class="toctree-l2"><a class="reference internal" href="single_distiller_api.html">简单蒸馏</a></li>
......@@ -263,7 +263,7 @@
<li><strong>tokens(list):</strong> - 一组tokens。tokens的长度和范围取决于搜索空间。</li>
</ul>
<p><strong>返回:</strong>
根据传入的token得到一个模型结构实例。</p>
根据传入的token得到一个模型结构实例列表</p>
<p><strong>示例代码:</strong></p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">paddle.fluid</span> <span class="k">as</span> <span class="nn">fluid</span>
<span class="kn">from</span> <span class="nn">paddleslim.nas</span> <span class="kn">import</span> <span class="n">SANAS</span>
......@@ -284,6 +284,13 @@
<p><strong>返回:</strong>
搜索过程中最好的token,reward和当前训练的token,形式为dict。</p>
<p><strong>示例代码:</strong></p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">paddle.fluid</span> <span class="k">as</span> <span class="nn">fluid</span>
<span class="kn">from</span> <span class="nn">paddleslim.nas</span> <span class="kn">import</span> <span class="n">SANAS</span>
<span class="n">config</span> <span class="o">=</span> <span class="p">[(</span><span class="s1">&#39;MobileNetV2Space&#39;</span><span class="p">)]</span>
<span class="n">sanas</span> <span class="o">=</span> <span class="n">SANAS</span><span class="p">(</span><span class="n">configs</span><span class="o">=</span><span class="n">config</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="n">sanas</span><span class="o">.</span><span class="n">current_info</span><span class="p">())</span>
</pre></div>
</div>
</div></blockquote>
</div>
</div>
......
......@@ -35,7 +35,7 @@
<link rel="search" title="搜索" href="../search.html"/>
<link rel="top" title="PaddleSlim 1.0 文档" href="../index.html"/>
<link rel="up" title="API文档" href="index.html"/>
<link rel="next" title="多进程蒸馏" href="pantheon_api.html"/>
<link rel="next" title="大规模可扩展知识蒸馏框架 Pantheon" href="pantheon_api.html"/>
<link rel="prev" title="SA-NAS" href="nas_api.html"/>
......@@ -83,7 +83,7 @@
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../index_en.html">English Documents</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intro.html">PaddleSlim简介</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intro.html">介绍</a></li>
<li class="toctree-l1"><a class="reference internal" href="../install.html">安装</a></li>
<li class="toctree-l1"><a class="reference internal" href="../quick_start/index.html">快速开始</a></li>
<li class="toctree-l1"><a class="reference internal" href="../tutorials/index.html">进阶教程</a></li>
......@@ -96,7 +96,7 @@
<li class="toctree-l3"><a class="reference internal" href="#supermnasnet">SuperMnasnet</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="pantheon_api.html">多进程蒸馏</a></li>
<li class="toctree-l2"><a class="reference internal" href="pantheon_api.html">大规模可扩展知识蒸馏框架 Pantheon</a></li>
<li class="toctree-l2"><a class="reference internal" href="prune_api.html">卷积层通道剪裁</a></li>
<li class="toctree-l2"><a class="reference internal" href="quantization_api.html">量化</a></li>
<li class="toctree-l2"><a class="reference internal" href="single_distiller_api.html">简单蒸馏</a></li>
......@@ -331,7 +331,7 @@ return x, acc</div></blockquote>
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
<a href="pantheon_api.html" class="btn btn-neutral float-right" title="多进程蒸馏" accesskey="n">Next <span class="fa fa-arrow-circle-right"></span></a>
<a href="pantheon_api.html" class="btn btn-neutral float-right" title="大规模可扩展知识蒸馏框架 Pantheon" accesskey="n">Next <span class="fa fa-arrow-circle-right"></span></a>
<a href="nas_api.html" class="btn btn-neutral" title="SA-NAS" accesskey="p"><span class="fa fa-arrow-circle-left"></span> Previous</a>
......
......@@ -8,7 +8,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>多进程蒸馏 &mdash; PaddleSlim 1.0 文档</title>
<title>大规模可扩展知识蒸馏框架 Pantheon &mdash; PaddleSlim 1.0 文档</title>
......@@ -83,7 +83,7 @@
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../index_en.html">English Documents</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intro.html">PaddleSlim简介</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intro.html">介绍</a></li>
<li class="toctree-l1"><a class="reference internal" href="../install.html">安装</a></li>
<li class="toctree-l1"><a class="reference internal" href="../quick_start/index.html">快速开始</a></li>
<li class="toctree-l1"><a class="reference internal" href="../tutorials/index.html">进阶教程</a></li>
......@@ -91,7 +91,7 @@
<li class="toctree-l2"><a class="reference internal" href="analysis_api.html">模型分析</a></li>
<li class="toctree-l2"><a class="reference internal" href="nas_api.html">SA-NAS</a></li>
<li class="toctree-l2"><a class="reference internal" href="one_shot_api.html">OneShotNAS</a></li>
<li class="toctree-l2 current"><a class="current reference internal" href="#">多进程蒸馏</a><ul>
<li class="toctree-l2 current"><a class="current reference internal" href="#">大规模可扩展知识蒸馏框架 Pantheon</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#teacher">Teacher</a></li>
<li class="toctree-l3"><a class="reference internal" href="#student">Student</a></li>
</ul>
......@@ -137,7 +137,7 @@
<li><a href="index.html">API文档</a> &raquo;</li>
<li>多进程蒸馏</li>
<li>大规模可扩展知识蒸馏框架 Pantheon</li>
<li class="wy-breadcrumbs-aside">
......@@ -151,8 +151,8 @@
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<div class="section" id="id1">
<h1>多进程蒸馏<a class="headerlink" href="#id1" title="永久链接至标题"></a></h1>
<div class="section" id="pantheon">
<h1>大规模可扩展知识蒸馏框架 Pantheon<a class="headerlink" href="#pantheon" title="永久链接至标题"></a></h1>
<div class="section" id="teacher">
<h2>Teacher<a class="headerlink" href="#teacher" title="永久链接至标题"></a></h2>
<p>pantheon.Teacher() <a class="reference external" href="https://github.com/PaddlePaddle/PaddleSlim/blob/develop/paddleslim/pantheon/teacher.py#L78">source</a></p>
......@@ -164,8 +164,10 @@
</ul>
<p><strong>Return:</strong> An object of class Teacher</p>
<p>pantheon.Teacher.start() <a class="reference external" href="https://github.com/PaddlePaddle/PaddleSlim/blob/develop/paddleslim/pantheon/teacher.py#L133">source</a></p>
<p>: Start teacher service, sychronize with student and launch the thread
to monitor commands from student.</p>
<dl class="docutils">
<dt>: Start teacher service, sychronize with student and launch the thread</dt>
<dd>to monitor commands from student.</dd>
</dl>
<p><strong>Args:</strong> None</p>
<p><strong>Return:</strong> None</p>
<p>pantheon.Teacher.send(data) <a class="reference external" href="https://github.com/PaddlePaddle/PaddleSlim/blob/develop/paddleslim/pantheon/teacher.py#L181">source</a></p>
......@@ -190,49 +192,68 @@ to monitor commands from student.</p>
</ul>
<p><strong>Return:</strong> None</p>
<p>pantheon.Teacher.start_knowledge_service(feed_list, schema, program, reader_config, exe, buf_size=10, times=1) <a class="reference external" href="https://github.com/PaddlePaddle/PaddleSlim/blob/develop/paddleslim/pantheon/teacher.py#L259">source</a></p>
<p>: Start the knowledge service to generate and transfer knowledge data. In GPU mode, the devices to execute knowledge prediction will be determined by the
environment variable <strong>FLAGS_selected_gpus</strong>, or by <strong>CUDA_VISIBLE_DEVICES</strong> if it is not set, and by <strong>CPU_NUM</strong> (default 1) in CPU mode. Only supported in static graph.</p>
<p><strong>Args:</strong></p>
<dl class="docutils">
<dt>: Start the knowledge service to generate and transfer knowledge data. In GPU mode, the devices to execute knowledge prediction will be determined by the</dt>
<dd><blockquote class="first">
<div>environment variable <strong>FLAGS_selected_gpus</strong>, or by <strong>CUDA_VISIBLE_DEVICES</strong> if it is not set, and by <strong>CPU_NUM</strong> (default 1) in CPU mode. Only supported in static graph.</div></blockquote>
<p class="last"><strong>Args:</strong></p>
</dd>
</dl>
<ul>
<li><p class="first"><strong>feed_list (list):</strong> - A list of feed Variables or their names for the
input teacher Program.</p>
.. code-block:: guess</p>
<blockquote>
<div><p>input teacher Program.</p>
</div></blockquote>
</li>
<li><p class="first"><strong>schema (dict):</strong> - A dict to specify keys and fetched Variablesto generate knowledge.</p>
<li><p class="first"><strong>schema (dict):</strong> - A dict to specify keys and fetched Variables
.. code-block:: guess</p>
<blockquote>
<div><p>to generate knowledge.</p>
</div></blockquote>
</li>
<li><p class="first"><strong>program (fluid.Program):</strong> - Inference Program of the teacher model.</p>
</li>
<li><p class="first"><strong>reader_config (dict):</strong> - The config for data reader. Support all the three types of generators used by <a class="reference external" href="https://www.paddlepaddle.org.cn/documentation/docs/en/api/io/PyReader.html">fluid.io.PyReader</a> and <a class="reference external" href="https://www.paddlepaddle.org.cn/documentation/docs/en/api/io/DataLoader.html#dataloader">fluid.io.DataLoader</a>, and their configs contain the key-value pair of the generator type and a generator object, plus other necessary argument pairs. See the following:</p>
<ol class="simple">
<blockquote>
<div><ol class="arabic simple">
<li><strong>sample generator:</strong></li>
</ol>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">reader_config</span><span class="o">=</span><span class="p">{</span><span class="s2">&quot;sample_generator&quot;</span><span class="p">:</span> <span class="n">some_sample_generator</span><span class="p">,</span>
<span class="s2">&quot;batch_size&quot;</span><span class="p">:</span> <span class="n">batch_size</span><span class="p">,</span> <span class="s2">&quot;drop_last&quot;</span><span class="p">:</span> <span class="n">drop_last</span><span class="p">}</span>
<span class="c1"># drop_last set to True by default</span>
</div></blockquote>
<div class="highlight-guess"><div class="highlight"><pre><span></span> <span class="n">reader_config</span><span class="o">=</span><span class="err">{</span><span class="ss">&quot;sample_generator&quot;</span><span class="p">:</span> <span class="n">some_sample_generator</span><span class="p">,</span>
<span class="ss">&quot;batch_size&quot;</span><span class="p">:</span> <span class="n">batch_size</span><span class="p">,</span> <span class="ss">&quot;drop_last&quot;</span><span class="p">:</span> <span class="n">drop_last</span><span class="err">}</span>
<span class="o">#</span> <span class="n">drop_last</span> <span class="k">set</span> <span class="k">to</span> <span class="k">True</span> <span class="k">by</span> <span class="k">default</span>
<span class="mi">2</span><span class="p">)</span> <span class="o">**</span><span class="n">sample</span> <span class="n">list</span> <span class="n">generator</span><span class="p">:</span><span class="o">**</span>
</pre></div>
</div>
<ol class="simple">
<li><strong>sample list generator:</strong></li>
</ol>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">reader_config</span><span class="o">=</span><span class="p">{</span><span class="s2">&quot;sample_list_generator&quot;</span><span class="p">:</span> <span class="n">some_sample_list_generator</span><span class="p">}</span>
<div class="highlight-guess"><div class="highlight"><pre><span></span> <span class="n">reader_config</span><span class="o">=</span><span class="err">{</span><span class="ss">&quot;sample_list_generator&quot;</span><span class="p">:</span> <span class="n">some_sample_list_generator</span><span class="err">}</span>
<span class="mi">3</span><span class="p">)</span> <span class="o">**</span><span class="n">batch</span> <span class="n">generator</span><span class="p">:</span><span class="o">**</span>
</pre></div>
</div>
<ol class="simple">
<li><strong>batch generator:</strong></li>
</ol>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">reader_config</span><span class="o">=</span><span class="p">{</span><span class="s2">&quot;batch_generator&quot;</span><span class="p">:</span> <span class="n">some_batch_genrator</span><span class="p">}</span>
<div class="highlight-guess"><div class="highlight"><pre><span></span> <span class="n">reader_config</span><span class="o">=</span><span class="err">{</span><span class="ss">&quot;batch_generator&quot;</span><span class="p">:</span> <span class="n">some_batch_genrator</span><span class="err">}</span>
<span class="n">The</span> <span class="n">trial</span> <span class="k">to</span> <span class="n">parse</span> <span class="n">config</span> <span class="n">will</span> <span class="n">be</span> <span class="k">in</span> <span class="n">the</span> <span class="k">order</span> <span class="k">of</span> <span class="mi">1</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="mi">3</span><span class="p">),</span> <span class="k">and</span> <span class="k">any</span> <span class="n">other</span> <span class="n">unrelated</span> <span class="n">keys</span> <span class="k">in</span> <span class="n">these</span> <span class="n">configs</span> <span class="n">will</span> <span class="n">be</span> <span class="n">ignored</span><span class="p">.</span>
</pre></div>
</div>
<p>The trial to parse config will be in the order of 1) -&gt; 3), and any other unrelated keys in these configs will be ignored.</p>
</li>
<li><p class="first"><strong>exe (fluid.Executor):</strong> The executor to run the input program.</p>
</li>
<li><p class="first"><strong>buf_size (int):</strong> The size of buffers for data reader and knowledge
writer on each device.</p>
.. code-block:: guess</p>
<blockquote>
<div><p>writer on each device.</p>
</div></blockquote>
</li>
<li><p class="first"><strong>times (int):</strong> The maximum repeated serving times, default 1. Whenever
the public method <strong>get_knowledge_generator()</strong> in <strong>Student</strong>
.. code-block:: guess</p>
<blockquote>
<div><p>the public method <strong>get_knowledge_generator()</strong> in <strong>Student</strong>
object called once, the serving times will be added one,
until reaching the maximum and ending the service.</p>
until reaching the maximum and ending the service. Only
valid in online mode, and will be ignored in offline mode.</p>
</div></blockquote>
</li>
</ul>
<p><strong>Return:</strong> None</p>
......@@ -271,15 +292,21 @@ until reaching the maximum and ending the service.</p>
<span class="n">exe</span><span class="o">=</span><span class="n">exe</span><span class="p">)</span>
</pre></div>
</div>
<p>!!! note &#8220;Note&#8220;
This example should be run with the example of class <strong>Student</strong>.</p>
<dl class="docutils">
<dt>!!! note &#8220;Note&#8221;</dt>
<dd>This example should be run with the example of class <strong>Student</strong>.</dd>
</dl>
</div>
<div class="section" id="student">
<h2>Student<a class="headerlink" href="#student" title="永久链接至标题"></a></h2>
<p>pantheon.Student(merge_strategy=None) <a class="reference external" href="https://github.com/PaddlePaddle/PaddleSlim/blob/develop/paddleslim/pantheon/student.py#L34">source</a></p>
<p>: The class defined for the student model. Receive knowledge data from
teacher model and carry out knowledge merging.</p>
<p><strong>Args:</strong></p>
<dl class="docutils">
<dt>: The class defined for the student model. Receive knowledge data from</dt>
<dd><blockquote class="first">
<div>teacher model and carry out knowledge merging.</div></blockquote>
<p class="last"><strong>Args:</strong></p>
</dd>
</dl>
<ul class="simple">
<li><strong>merge_strategy (dict|None):</strong> - A dict whose keys are the common schemas shared by different teachers, and each corresponding value specifies the merging strategy for different schemas respectively, supporting <strong>sum</strong> and <strong>mean</strong> now.</li>
</ul>
......@@ -289,11 +316,11 @@ teacher model and carry out knowledge merging.</p>
<p><strong>Args:</strong></p>
<ul class="simple">
<li><strong>in_path (str|None):</strong> The input file path. Default None.</li>
<li><strong>in_address (str|None):</strong> The input IP address, in the format &#8220;&lt;IP_address&gt;:&lt;IP_port&gt;&#8220; (e.g. &#8220;127.0.0.1:8080&#8220;). Default None.</li>
<li><strong>in_address (str|None):</strong> The input IP address, in the format &#8220;&amp;lt;IP_address&amp;gt;:&amp;lt;IP_port&amp;gt;&#8221; (e.g. &#8220;127.0.0.1:8080&#8221;). Default None.</li>
</ul>
<p><strong>Return:</strong> None</p>
<p>pantheon.Student.start() <a class="reference external" href="https://github.com/PaddlePaddle/PaddleSlim/blob/develop/paddleslim/pantheon/student.py#L213">source</a></p>
<p>: End teachers&#8216; registration and synchronize with all of them.</p>
<p>: End teachers&#8217; registration and synchronize with all of them.</p>
<p><strong>Args:</strong> None</p>
<p><strong>Return:</strong> None</p>
<p>pantheon.Student.send(self, data, teacher_ids=None) <a class="reference external" href="https://github.com/PaddlePaddle/PaddleSlim/blob/develop/paddleslim/pantheon/student.py#L240">source</a></p>
......@@ -306,7 +333,8 @@ teacher model and carry out knowledge merging.</p>
<p><strong>Return:</strong> None</p>
<p>pantheon.Student.recv(teacher_id) <a class="reference external" href="https://github.com/PaddlePaddle/PaddleSlim/blob/develop/paddleslim/pantheon/student.py#L262">source</a></p>
<p>: Receive data from one teacher.</p>
<p><strong>Args:</strong></p>
<blockquote>
<div><strong>Args:</strong></div></blockquote>
<ul class="simple">
<li><strong>teacher_id (int):</strong> - The id of teacher that receives data from.</li>
</ul>
......@@ -315,25 +343,31 @@ teacher model and carry out knowledge merging.</p>
<li>The received data object.</li>
</ul>
<p>pantheon.Student.get_knowledge_desc() <a class="reference external" href="https://github.com/PaddlePaddle/PaddleSlim/blob/develop/paddleslim/pantheon/student.py#L283">source</a></p>
<p>: Get description for knowledge, including shape, data type and lod level for each schema.</p>
<blockquote>
<div><p>: Get description for knowledge, including shape, data type and lod level for each schema.</p>
<p><strong>Args:</strong> None</p>
<p><strong>Return:</strong></p>
</div></blockquote>
<ul class="simple">
<li>Knowledge description, which is a dict.</li>
</ul>
<p>pantheon.Student.get_knowledge_qsize() <a class="reference external" href="https://github.com/PaddlePaddle/PaddleSlim/blob/develop/paddleslim/pantheon/student.py#L318">source</a></p>
<p>: Get the real-time size of knowledge queue. If this size is denoted as
<strong>qsize</strong>, it means that there are <strong>qsize</strong> batch knowledge data
<blockquote>
<div><dl class="docutils">
<dt>: Get the real-time size of knowledge queue. If this size is denoted as</dt>
<dd><strong>qsize</strong>, it means that there are <strong>qsize</strong> batch knowledge data
already pushed into knowledge queue and waiting for the knowledge
generator to pop out. It&#8216;s dynamic and limited up to 100, the capacity
of the knowledge queue.</p>
generator to pop out. It&#8217;s dynamic and limited up to 100, the capacity
of the knowledge queue.</dd>
</dl>
<p><strong>Args:</strong> None</p>
<p><strong>Return:</strong></p>
</div></blockquote>
<ul class="simple">
<li>The real-time size of knowledge queue.</li>
</ul>
<p>pantheon.Student.get_knowledge_generator(batch_size, drop_last=False) <a class="reference external" href="https://github.com/PaddlePaddle/PaddleSlim/blob/develop/paddleslim/pantheon/student.py#L334">source</a></p>
<p>: Get the generator for knowledge data, return None if last generator doesn&#8216;t finish yet.</p>
<p>: Get the generator for knowledge data, return None if last generator doesn&#8217;t finish yet.</p>
<p><strong>Args:</strong></p>
<ul class="simple">
<li><strong>batch_size (int):</strong> - The batch size of returned knowledge data.</li>
......@@ -364,8 +398,10 @@ of the knowledge queue.</p>
<span class="c1"># do something else</span>
</pre></div>
</div>
<p>!!! note &#8220;Note&#8220;
This example should be run with the example of class <strong>Teacher</strong>.</p>
<dl class="docutils">
<dt>!!! note &#8220;Note&#8221;</dt>
<dd>This example should be run with the example of class <strong>Teacher</strong>.</dd>
</dl>
</div>
</div>
......
......@@ -36,7 +36,7 @@
<link rel="top" title="PaddleSlim 1.0 文档" href="../index.html"/>
<link rel="up" title="API文档" href="index.html"/>
<link rel="next" title="量化" href="quantization_api.html"/>
<link rel="prev" title="多进程蒸馏" href="pantheon_api.html"/>
<link rel="prev" title="大规模可扩展知识蒸馏框架 Pantheon" href="pantheon_api.html"/>
<script src="../_static/js/modernizr.min.js"></script>
......@@ -83,7 +83,7 @@
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../index_en.html">English Documents</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intro.html">PaddleSlim简介</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intro.html">介绍</a></li>
<li class="toctree-l1"><a class="reference internal" href="../install.html">安装</a></li>
<li class="toctree-l1"><a class="reference internal" href="../quick_start/index.html">快速开始</a></li>
<li class="toctree-l1"><a class="reference internal" href="../tutorials/index.html">进阶教程</a></li>
......@@ -91,7 +91,7 @@
<li class="toctree-l2"><a class="reference internal" href="analysis_api.html">模型分析</a></li>
<li class="toctree-l2"><a class="reference internal" href="nas_api.html">SA-NAS</a></li>
<li class="toctree-l2"><a class="reference internal" href="one_shot_api.html">OneShotNAS</a></li>
<li class="toctree-l2"><a class="reference internal" href="pantheon_api.html">多进程蒸馏</a></li>
<li class="toctree-l2"><a class="reference internal" href="pantheon_api.html">大规模可扩展知识蒸馏框架 Pantheon</a></li>
<li class="toctree-l2 current"><a class="current reference internal" href="#">卷积层通道剪裁</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#pruner">Pruner</a></li>
<li class="toctree-l3"><a class="reference internal" href="#sensitivity">sensitivity</a></li>
......@@ -499,7 +499,7 @@
<span class="p">}</span>
<span class="p">}</span>
<span class="n">sensitivities_file</span> <span class="o">=</span> <span class="s2">&quot;sensitive_api_demo.data&quot;</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">sensitivities_file</span><span class="p">,</span> <span class="s1">&#39;w&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">sensitivities_file</span><span class="p">,</span> <span class="s1">&#39;wb&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
<span class="n">pickle</span><span class="o">.</span><span class="n">dump</span><span class="p">(</span><span class="n">sen</span><span class="p">,</span> <span class="n">f</span><span class="p">)</span>
<span class="n">sensitivities</span> <span class="o">=</span> <span class="n">load_sensitivities</span><span class="p">(</span><span class="n">sensitivities_file</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="n">sensitivities</span><span class="p">)</span>
......@@ -553,7 +553,7 @@
<a href="quantization_api.html" class="btn btn-neutral float-right" title="量化" accesskey="n">Next <span class="fa fa-arrow-circle-right"></span></a>
<a href="pantheon_api.html" class="btn btn-neutral" title="多进程蒸馏" accesskey="p"><span class="fa fa-arrow-circle-left"></span> Previous</a>
<a href="pantheon_api.html" class="btn btn-neutral" title="大规模可扩展知识蒸馏框架 Pantheon" accesskey="p"><span class="fa fa-arrow-circle-left"></span> Previous</a>
</div>
......
......@@ -83,7 +83,7 @@
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../index_en.html">English Documents</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intro.html">PaddleSlim简介</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intro.html">介绍</a></li>
<li class="toctree-l1"><a class="reference internal" href="../install.html">安装</a></li>
<li class="toctree-l1"><a class="reference internal" href="../quick_start/index.html">快速开始</a></li>
<li class="toctree-l1"><a class="reference internal" href="../tutorials/index.html">进阶教程</a></li>
......@@ -91,7 +91,7 @@
<li class="toctree-l2"><a class="reference internal" href="analysis_api.html">模型分析</a></li>
<li class="toctree-l2"><a class="reference internal" href="nas_api.html">SA-NAS</a></li>
<li class="toctree-l2"><a class="reference internal" href="one_shot_api.html">OneShotNAS</a></li>
<li class="toctree-l2"><a class="reference internal" href="pantheon_api.html">多进程蒸馏</a></li>
<li class="toctree-l2"><a class="reference internal" href="pantheon_api.html">大规模可扩展知识蒸馏框架 Pantheon</a></li>
<li class="toctree-l2"><a class="reference internal" href="prune_api.html">卷积层通道剪裁</a></li>
<li class="toctree-l2 current"><a class="current reference internal" href="#">量化</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#id2">量化配置</a></li>
......
......@@ -83,7 +83,7 @@
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../index_en.html">English Documents</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intro.html">PaddleSlim简介</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intro.html">介绍</a></li>
<li class="toctree-l1"><a class="reference internal" href="../install.html">安装</a></li>
<li class="toctree-l1"><a class="reference internal" href="../quick_start/index.html">快速开始</a></li>
<li class="toctree-l1"><a class="reference internal" href="../tutorials/index.html">进阶教程</a></li>
......@@ -91,7 +91,7 @@
<li class="toctree-l2"><a class="reference internal" href="analysis_api.html">模型分析</a></li>
<li class="toctree-l2"><a class="reference internal" href="nas_api.html">SA-NAS</a></li>
<li class="toctree-l2"><a class="reference internal" href="one_shot_api.html">OneShotNAS</a></li>
<li class="toctree-l2"><a class="reference internal" href="pantheon_api.html">多进程蒸馏</a></li>
<li class="toctree-l2"><a class="reference internal" href="pantheon_api.html">大规模可扩展知识蒸馏框架 Pantheon</a></li>
<li class="toctree-l2"><a class="reference internal" href="prune_api.html">卷积层通道剪裁</a></li>
<li class="toctree-l2"><a class="reference internal" href="quantization_api.html">量化</a></li>
<li class="toctree-l2"><a class="reference internal" href="single_distiller_api.html">简单蒸馏</a></li>
......
......@@ -83,7 +83,7 @@
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../index_en.html">English Documents</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intro.html">PaddleSlim简介</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intro.html">介绍</a></li>
<li class="toctree-l1"><a class="reference internal" href="../install.html">安装</a></li>
<li class="toctree-l1"><a class="reference internal" href="../quick_start/index.html">快速开始</a></li>
<li class="toctree-l1"><a class="reference internal" href="../tutorials/index.html">进阶教程</a></li>
......@@ -91,7 +91,7 @@
<li class="toctree-l2"><a class="reference internal" href="analysis_api.html">模型分析</a></li>
<li class="toctree-l2"><a class="reference internal" href="nas_api.html">SA-NAS</a></li>
<li class="toctree-l2"><a class="reference internal" href="one_shot_api.html">OneShotNAS</a></li>
<li class="toctree-l2"><a class="reference internal" href="pantheon_api.html">多进程蒸馏</a></li>
<li class="toctree-l2"><a class="reference internal" href="pantheon_api.html">大规模可扩展知识蒸馏框架 Pantheon</a></li>
<li class="toctree-l2"><a class="reference internal" href="prune_api.html">卷积层通道剪裁</a></li>
<li class="toctree-l2"><a class="reference internal" href="quantization_api.html">量化</a></li>
<li class="toctree-l2 current"><a class="current reference internal" href="#">简单蒸馏</a><ul>
......
......@@ -83,7 +83,7 @@
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../index_en.html">English Documents</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intro.html">PaddleSlim简介</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intro.html">介绍</a></li>
<li class="toctree-l1"><a class="reference internal" href="../install.html">安装</a></li>
<li class="toctree-l1"><a class="reference internal" href="../quick_start/index.html">快速开始</a></li>
<li class="toctree-l1"><a class="reference internal" href="../tutorials/index.html">进阶教程</a></li>
......@@ -91,7 +91,7 @@
<li class="toctree-l2"><a class="reference internal" href="analysis_api.html">模型分析</a></li>
<li class="toctree-l2"><a class="reference internal" href="nas_api.html">SA-NAS</a></li>
<li class="toctree-l2"><a class="reference internal" href="one_shot_api.html">OneShotNAS</a></li>
<li class="toctree-l2"><a class="reference internal" href="pantheon_api.html">多进程蒸馏</a></li>
<li class="toctree-l2"><a class="reference internal" href="pantheon_api.html">大规模可扩展知识蒸馏框架 Pantheon</a></li>
<li class="toctree-l2"><a class="reference internal" href="prune_api.html">卷积层通道剪裁</a></li>
<li class="toctree-l2"><a class="reference internal" href="quantization_api.html">量化</a></li>
<li class="toctree-l2"><a class="reference internal" href="single_distiller_api.html">简单蒸馏</a></li>
......
......@@ -35,7 +35,7 @@
<link rel="search" title="Search" href="../search.html"/>
<link rel="top" title="PaddleSlim 1.0 documentation" href="../index.html"/>
<link rel="next" title="paddleslim.analysis package" href="paddleslim.analysis.html"/>
<link rel="prev" title="Pruning of image classification model - sensitivity" href="../tutorials/sensitivity_tutorial_en.html"/>
<link rel="prev" title="Pruning of image classification model - sensitivity" href="../tutorials/image_classification_sensitivity_analysis_tutorial_en.html"/>
<script src="../_static/js/modernizr.min.js"></script>
......@@ -95,6 +95,7 @@
<li class="toctree-l2"><a class="reference internal" href="paddleslim.nas.one_shot.html">paddleslim.nas.one_shot package</a></li>
<li class="toctree-l2"><a class="reference internal" href="paddleslim.pantheon.html">paddleslim.pantheon package</a></li>
<li class="toctree-l2"><a class="reference internal" href="search_space_en.html">search space</a></li>
<li class="toctree-l2"><a class="reference internal" href="table_latency_en.html">Table about hardware lantency</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../model_zoo_en.html">Model Zoo</a></li>
......@@ -154,6 +155,7 @@
<li class="toctree-l1"><a class="reference internal" href="paddleslim.nas.one_shot.html">paddleslim.nas.one_shot package</a></li>
<li class="toctree-l1"><a class="reference internal" href="paddleslim.pantheon.html">paddleslim.pantheon package</a></li>
<li class="toctree-l1"><a class="reference internal" href="search_space_en.html">search space</a></li>
<li class="toctree-l1"><a class="reference internal" href="table_latency_en.html">Table about hardware lantency</a></li>
</ul>
</div>
</div>
......@@ -168,7 +170,7 @@
<a href="paddleslim.analysis.html" class="btn btn-neutral float-right" title="paddleslim.analysis package" accesskey="n">Next <span class="fa fa-arrow-circle-right"></span></a>
<a href="../tutorials/sensitivity_tutorial_en.html" class="btn btn-neutral" title="Pruning of image classification model - sensitivity" accesskey="p"><span class="fa fa-arrow-circle-left"></span> Previous</a>
<a href="../tutorials/image_classification_sensitivity_analysis_tutorial_en.html" class="btn btn-neutral" title="Pruning of image classification model - sensitivity" accesskey="p"><span class="fa fa-arrow-circle-left"></span> Previous</a>
</div>
......
......@@ -102,6 +102,7 @@
<li class="toctree-l2"><a class="reference internal" href="paddleslim.nas.one_shot.html">paddleslim.nas.one_shot package</a></li>
<li class="toctree-l2"><a class="reference internal" href="paddleslim.pantheon.html">paddleslim.pantheon package</a></li>
<li class="toctree-l2"><a class="reference internal" href="search_space_en.html">search space</a></li>
<li class="toctree-l2"><a class="reference internal" href="table_latency_en.html">Table about hardware lantency</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../model_zoo_en.html">Model Zoo</a></li>
......
......@@ -100,6 +100,7 @@
<li class="toctree-l2"><a class="reference internal" href="paddleslim.nas.one_shot.html">paddleslim.nas.one_shot package</a></li>
<li class="toctree-l2"><a class="reference internal" href="paddleslim.pantheon.html">paddleslim.pantheon package</a></li>
<li class="toctree-l2"><a class="reference internal" href="search_space_en.html">search space</a></li>
<li class="toctree-l2"><a class="reference internal" href="table_latency_en.html">Table about hardware lantency</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../model_zoo_en.html">Model Zoo</a></li>
......
......@@ -104,6 +104,7 @@
<li class="toctree-l2"><a class="reference internal" href="paddleslim.nas.one_shot.html">paddleslim.nas.one_shot package</a></li>
<li class="toctree-l2"><a class="reference internal" href="paddleslim.pantheon.html">paddleslim.pantheon package</a></li>
<li class="toctree-l2"><a class="reference internal" href="search_space_en.html">search space</a></li>
<li class="toctree-l2"><a class="reference internal" href="table_latency_en.html">Table about hardware lantency</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../model_zoo_en.html">Model Zoo</a></li>
......
......@@ -101,6 +101,7 @@
</li>
<li class="toctree-l2"><a class="reference internal" href="paddleslim.pantheon.html">paddleslim.pantheon package</a></li>
<li class="toctree-l2"><a class="reference internal" href="search_space_en.html">search space</a></li>
<li class="toctree-l2"><a class="reference internal" href="table_latency_en.html">Table about hardware lantency</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../model_zoo_en.html">Model Zoo</a></li>
......
......@@ -102,6 +102,7 @@
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="search_space_en.html">search space</a></li>
<li class="toctree-l2"><a class="reference internal" href="table_latency_en.html">Table about hardware lantency</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../model_zoo_en.html">Model Zoo</a></li>
......@@ -270,7 +271,8 @@ writer on each device.</li>
<li><strong>times</strong> (<em>int</em>) &#8211; The maximum repeated serving times. Default 1. Whenever
the public method &#8216;get_knowledge_generator()&#8217; in Student
object called once, the serving times will be added one,
until reaching the maximum and ending the service.</li>
until reaching the maximum and ending the service. Only
valid in online mode, and will be ignored in offline mode.</li>
</ul>
</td>
</tr>
......@@ -697,7 +699,8 @@ writer on each device.</li>
<li><strong>times</strong> (<em>int</em>) &#8211; The maximum repeated serving times. Default 1. Whenever
the public method &#8216;get_knowledge_generator()&#8217; in Student
object called once, the serving times will be added one,
until reaching the maximum and ending the service.</li>
until reaching the maximum and ending the service. Only
valid in online mode, and will be ignored in offline mode.</li>
</ul>
</td>
</tr>
......
......@@ -105,6 +105,7 @@
<li class="toctree-l2"><a class="reference internal" href="paddleslim.nas.one_shot.html">paddleslim.nas.one_shot package</a></li>
<li class="toctree-l2"><a class="reference internal" href="paddleslim.pantheon.html">paddleslim.pantheon package</a></li>
<li class="toctree-l2"><a class="reference internal" href="search_space_en.html">search space</a></li>
<li class="toctree-l2"><a class="reference internal" href="table_latency_en.html">Table about hardware lantency</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../model_zoo_en.html">Model Zoo</a></li>
......
......@@ -101,6 +101,7 @@
<li class="toctree-l2"><a class="reference internal" href="paddleslim.nas.one_shot.html">paddleslim.nas.one_shot package</a></li>
<li class="toctree-l2"><a class="reference internal" href="paddleslim.pantheon.html">paddleslim.pantheon package</a></li>
<li class="toctree-l2"><a class="reference internal" href="search_space_en.html">search space</a></li>
<li class="toctree-l2"><a class="reference internal" href="table_latency_en.html">Table about hardware lantency</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../model_zoo_en.html">Model Zoo</a></li>
......
......@@ -35,7 +35,7 @@
<link rel="search" title="Search" href="../search.html"/>
<link rel="top" title="PaddleSlim 1.0 documentation" href="../index.html"/>
<link rel="up" title="API Documents" href="index_en.html"/>
<link rel="next" title="Model Zoo" href="../model_zoo_en.html"/>
<link rel="next" title="Table about hardware lantency" href="table_latency_en.html"/>
<link rel="prev" title="paddleslim.pantheon package" href="paddleslim.pantheon.html"/>
......@@ -101,6 +101,7 @@
<li class="toctree-l3"><a class="reference internal" href="#how-to-write-yourself-search-space">How to write yourself search space</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="table_latency_en.html">Table about hardware lantency</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../model_zoo_en.html">Model Zoo</a></li>
......@@ -280,7 +281,7 @@ return bn</dd>
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
<a href="../model_zoo_en.html" class="btn btn-neutral float-right" title="Model Zoo" accesskey="n">Next <span class="fa fa-arrow-circle-right"></span></a>
<a href="table_latency_en.html" class="btn btn-neutral float-right" title="Table about hardware lantency" accesskey="n">Next <span class="fa fa-arrow-circle-right"></span></a>
<a href="paddleslim.pantheon.html" class="btn btn-neutral" title="paddleslim.pantheon package" accesskey="p"><span class="fa fa-arrow-circle-left"></span> Previous</a>
......
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Table about hardware lantency &mdash; PaddleSlim 1.0 documentation</title>
<link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
<link rel="index" title="Index"
href="../genindex.html"/>
<link rel="search" title="Search" href="../search.html"/>
<link rel="top" title="PaddleSlim 1.0 documentation" href="../index.html"/>
<link rel="up" title="API Documents" href="index_en.html"/>
<link rel="next" title="Model Zoo" href="../model_zoo_en.html"/>
<link rel="prev" title="search space" href="search_space_en.html"/>
<script src="../_static/js/modernizr.min.js"></script>
</head>
<body class="wy-body-for-nav" role="document">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search">
<a href="../index_en.html" class="icon icon-home"> PaddleSlim
</a>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../index.html">中文文档</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intro_en.html">Introduction</a></li>
<li class="toctree-l1"><a class="reference internal" href="../install_en.html">Install</a></li>
<li class="toctree-l1"><a class="reference internal" href="../quick_start/index_en.html">Quick Start</a></li>
<li class="toctree-l1"><a class="reference internal" href="../tutorials/index_en.html">Aadvanced Tutorials</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="index_en.html">API Documents</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="paddleslim.analysis.html">paddleslim.analysis package</a></li>
<li class="toctree-l2"><a class="reference internal" href="paddleslim.prune.html">paddleslim.prune package</a></li>
<li class="toctree-l2"><a class="reference internal" href="paddleslim.dist.html">paddleslim.dist package</a></li>
<li class="toctree-l2"><a class="reference internal" href="paddleslim.quant.html">paddleslim.quant package</a></li>
<li class="toctree-l2"><a class="reference internal" href="paddleslim.nas.html">paddleslim.nas package</a></li>
<li class="toctree-l2"><a class="reference internal" href="paddleslim.nas.one_shot.html">paddleslim.nas.one_shot package</a></li>
<li class="toctree-l2"><a class="reference internal" href="paddleslim.pantheon.html">paddleslim.pantheon package</a></li>
<li class="toctree-l2"><a class="reference internal" href="search_space_en.html">search space</a></li>
<li class="toctree-l2 current"><a class="current reference internal" href="#">Table about hardware lantency</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#introduce">Introduce</a></li>
<li class="toctree-l3"><a class="reference internal" href="#overview-format">Overview format</a></li>
<li class="toctree-l3"><a class="reference internal" href="#version">Version</a></li>
<li class="toctree-l3"><a class="reference internal" href="#operation">Operation</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#conv2d">conv2d</a></li>
<li class="toctree-l4"><a class="reference internal" href="#activaiton">activaiton</a></li>
<li class="toctree-l4"><a class="reference internal" href="#batch-norm">batch_norm</a></li>
<li class="toctree-l4"><a class="reference internal" href="#eltwise">eltwise</a></li>
<li class="toctree-l4"><a class="reference internal" href="#pooling">pooling</a></li>
<li class="toctree-l4"><a class="reference internal" href="#softmax">softmax</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../model_zoo_en.html">Model Zoo</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" role="navigation" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../index_en.html">PaddleSlim</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../index_en.html">Docs</a> &raquo;</li>
<li><a href="index_en.html">API Documents</a> &raquo;</li>
<li>Table about hardware lantency</li>
<li class="wy-breadcrumbs-aside">
<a href="../_sources/api_en/table_latency_en.md.txt" rel="nofollow"> View page source</a>
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<div class="section" id="table-about-hardware-lantency">
<h1>Table about hardware lantency<a class="headerlink" href="#table-about-hardware-lantency" title="Permalink to this headline"></a></h1>
<p>The table about hardware latency is used to evaluate the inference time in special environment and inference engine. The following text used to introduce the format that PaddleSlim support.</p>
<div class="section" id="introduce">
<h2>Introduce<a class="headerlink" href="#introduce" title="Permalink to this headline"></a></h2>
<p>The table about hardware latency saved all possible operations, one operation in the table including type and parameters, such as: type can be <code class="docutils literal"><span class="pre">conv2d</span></code>, and corresponding parameters can be the size of feature map, number of kernel, and the size of kernel.
The latency of every operation depends on hardware and inference engine.</p>
</div>
<div class="section" id="overview-format">
<h2>Overview format<a class="headerlink" href="#overview-format" title="Permalink to this headline"></a></h2>
<p>The table about hardware latency saved in the way of file or multi-line string.
The first line of the table about hardware latency saved the information about version, every line in the following represents a operation and its latency.</p>
</div>
<div class="section" id="version">
<h2>Version<a class="headerlink" href="#version" title="Permalink to this headline"></a></h2>
<p>The information about version split by comma in the english format, and the detail is hardware, inference engine and timestamp.</p>
<ul class="simple">
<li>** hardware: ** Used to mark the environment of hardware, including type of architecture, version and so on.</li>
<li>** inference engine: ** Used to mark inference engine, including the name of inference engine, version, optimize options and so on.</li>
<li>** timestamp: ** Used to mark the time of this table created.</li>
</ul>
</div>
<div class="section" id="operation">
<h2>Operation<a class="headerlink" href="#operation" title="Permalink to this headline"></a></h2>
<p>The information about operation split by comma in the english format, the information about operation and latency split by tabs.</p>
<div class="section" id="conv2d">
<h3>conv2d<a class="headerlink" href="#conv2d" title="Permalink to this headline"></a></h3>
<p><strong>format</strong></p>
<div class="highlight-text"><div class="highlight"><pre><span></span>op_type,flag_bias,flag_relu,n_in,c_in,h_in,w_in,c_out,groups,kernel,padding,stride,dilation\tlatency
</pre></div>
</div>
<p><strong>introduce</strong></p>
<ul class="simple">
<li><strong>op_type(str)</strong> - The type of this op.</li>
<li><strong>flag_bias (int)</strong> - Whether has bias or not(0: donot has bias, 1: has bias).</li>
<li><strong>flag_relu (int)</strong> - Whether has relu or not(0: donot has relu, 1: has relu).</li>
<li><strong>n_in (int)</strong> - The batch size of input.</li>
<li><strong>c_in (int)</strong> - The number of channel about input.</li>
<li><strong>h_in (int)</strong> - The height of input feature map.</li>
<li><strong>w_in (int)</strong> - The width of input feature map.</li>
<li><strong>c_out (int)</strong> - The number of channel about output.</li>
<li><strong>groups (int)</strong> - The group of conv2d.</li>
<li><strong>kernel (int)</strong> - The size of kernel.</li>
<li><strong>padding (int)</strong> - The size of padding.</li>
<li><strong>stride (int)</strong> - The size of stride.</li>
<li><strong>dilation (int)</strong> - The size of dilation.</li>
<li><strong>latency (float)</strong> - The latency of this op.</li>
</ul>
</div>
<div class="section" id="activaiton">
<h3>activaiton<a class="headerlink" href="#activaiton" title="Permalink to this headline"></a></h3>
<p><strong>format</strong></p>
<div class="highlight-text"><div class="highlight"><pre><span></span>op_type,n_in,c_in,h_in,w_in\tlatency
</pre></div>
</div>
<p><strong>introduce</strong></p>
<ul class="simple">
<li><strong>op_type(str)</strong> - The type of this op.</li>
<li><strong>n_in (int)</strong> - The batch size of input.</li>
<li><strong>c_in (int)</strong> - The number of channel about input.</li>
<li><strong>h_in (int)</strong> - The height of input feature map.</li>
<li><strong>w_in (int)</strong> - The width of input feature map.</li>
<li><strong>latency (float)</strong> - The latency of this op.</li>
</ul>
</div>
<div class="section" id="batch-norm">
<h3>batch_norm<a class="headerlink" href="#batch-norm" title="Permalink to this headline"></a></h3>
<p><strong>format</strong></p>
<div class="highlight-text"><div class="highlight"><pre><span></span>op_type,active_type,n_in,c_in,h_in,w_in\tlatency
</pre></div>
</div>
<p><strong>introduce</strong></p>
<ul class="simple">
<li><strong>op_type(str)</strong> - The type of this op.</li>
<li><strong>active_type (string|None)</strong> - The type of activation function, including relu, prelu, sigmoid, relu6, tanh.</li>
<li><strong>n_in (int)</strong> - The batch size of input.</li>
<li><strong>c_in (int)</strong> - The number of channel about input.</li>
<li><strong>h_in (int)</strong> - The height of input feature map.</li>
<li><strong>w_in (int)</strong> - The width of input feature map.</li>
<li><strong>latency (float)</strong> - The latency of this op.</li>
</ul>
</div>
<div class="section" id="eltwise">
<h3>eltwise<a class="headerlink" href="#eltwise" title="Permalink to this headline"></a></h3>
<p><strong>format</strong></p>
<div class="highlight-text"><div class="highlight"><pre><span></span>op_type,n_in,c_in,h_in,w_in\tlatency
</pre></div>
</div>
<p><strong>introduce</strong></p>
<ul class="simple">
<li><strong>op_type(str)</strong> - The type of this op.</li>
<li><strong>n_in (int)</strong> - The batch size of input.</li>
<li><strong>c_in (int)</strong> - The number of channel about input.</li>
<li><strong>h_in (int)</strong> - The height of input feature map.</li>
<li><strong>w_in (int)</strong> - The width of input feature map.</li>
<li><strong>latency (float)</strong> - The latency of this op.</li>
</ul>
</div>
<div class="section" id="pooling">
<h3>pooling<a class="headerlink" href="#pooling" title="Permalink to this headline"></a></h3>
<p><strong>format</strong></p>
<div class="highlight-text"><div class="highlight"><pre><span></span>op_type,flag_global_pooling,n_in,c_in,h_in,w_in,kernel,padding,stride,ceil_mode,pool_type\tlatency
</pre></div>
</div>
<p><strong>introduce</strong></p>
<ul class="simple">
<li><strong>op_type(str)</strong> - The type of this op.</li>
<li><strong>flag_global_pooling (int)</strong> - Whether is global pooling or not(0: is not global, 1: is global pooling).</li>
<li><strong>n_in (int)</strong> - The batch size of input.</li>
<li><strong>c_in (int)</strong> - The number of channel about input.</li>
<li><strong>h_in (int)</strong> - The height of input feature map.</li>
<li><strong>w_in (int)</strong> - The width of input feature map.</li>
<li><strong>kernel (int)</strong> - The size of kernel.</li>
<li><strong>padding (int)</strong> - The size of padding.</li>
<li><strong>stride (int)</strong> - The size of stride.</li>
<li><strong>ceil_mode (int)</strong> - Whether to compute height and width by using ceil function(0: use floor function, 1: use ceil function).</li>
<li><strong>pool_type (int)</strong> - The type of pooling(1: max pooling 2: average pooling including padding 3: average pooling excluding padding).</li>
<li><strong>latency (float)</strong> - The latency of this op.</li>
</ul>
</div>
<div class="section" id="softmax">
<h3>softmax<a class="headerlink" href="#softmax" title="Permalink to this headline"></a></h3>
<p><strong>format</strong></p>
<div class="highlight-text"><div class="highlight"><pre><span></span>op_type,axis,n_in,c_in,h_in,w_in\tlatency
</pre></div>
</div>
<p><strong>introduce</strong></p>
<ul class="simple">
<li><strong>op_type(str)</strong> - The type of this op.</li>
<li><strong>axis (int)</strong> - The index to compute softmax, index in the range of [-1, rank-1], <code class="docutils literal"><span class="pre">rank</span></code> is the rank of input.</li>
<li><strong>n_in (int)</strong> - The batch size of input.</li>
<li><strong>c_in (int)</strong> - The number of channel about input.</li>
<li><strong>h_in (int)</strong> - The height of input feature map.</li>
<li><strong>w_in (int)</strong> - The width of input feature map.</li>
<li><strong>latency (float)</strong> - The latency of this op.</li>
</ul>
</div>
</div>
</div>
</div>
</div>
<footer>
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
<a href="../model_zoo_en.html" class="btn btn-neutral float-right" title="Model Zoo" accesskey="n">Next <span class="fa fa-arrow-circle-right"></span></a>
<a href="search_space_en.html" class="btn btn-neutral" title="search space" accesskey="p"><span class="fa fa-arrow-circle-left"></span> Previous</a>
</div>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2020, paddleslim.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT:'../',
VERSION:'1.0',
COLLAPSE_INDEX:false,
FILE_SUFFIX:'.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script type="text/javascript" src="../_static/js/theme.js"></script>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.StickyNav.enable();
});
</script>
</body>
</html>
\ No newline at end of file
......@@ -8,7 +8,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>欢迎使用PaddleSlim &mdash; PaddleSlim 1.0 文档</title>
<title>首页 &mdash; PaddleSlim 1.0 文档</title>
......@@ -81,7 +81,7 @@
<ul>
<li class="toctree-l1"><a class="reference internal" href="index_en.html">English Documents</a></li>
<li class="toctree-l1"><a class="reference internal" href="intro.html">PaddleSlim简介</a></li>
<li class="toctree-l1"><a class="reference internal" href="intro.html">介绍</a></li>
<li class="toctree-l1"><a class="reference internal" href="install.html">安装</a></li>
<li class="toctree-l1"><a class="reference internal" href="quick_start/index.html">快速开始</a></li>
<li class="toctree-l1"><a class="reference internal" href="tutorials/index.html">进阶教程</a></li>
......@@ -118,7 +118,7 @@
<ul class="wy-breadcrumbs">
<li><a href="#">Docs</a> &raquo;</li>
<li>欢迎使用PaddleSlim</li>
<li>首页</li>
<li class="wy-breadcrumbs-aside">
......@@ -132,12 +132,12 @@
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<div class="section" id="paddleslim">
<h1>欢迎使用PaddleSlim<a class="headerlink" href="#paddleslim" title="永久链接至标题"></a></h1>
<div class="section" id="id1">
<h1>首页<a class="headerlink" href="#id1" title="永久链接至标题"></a></h1>
<div class="toctree-wrapper compound">
<ul>
<li class="toctree-l1"><a class="reference internal" href="index_en.html">English Documents</a></li>
<li class="toctree-l1"><a class="reference internal" href="intro.html">PaddleSlim简介</a></li>
<li class="toctree-l1"><a class="reference internal" href="intro.html">介绍</a></li>
<li class="toctree-l1"><a class="reference internal" href="install.html">安装</a></li>
<li class="toctree-l1"><a class="reference internal" href="quick_start/index.html">快速开始</a></li>
<li class="toctree-l1"><a class="reference internal" href="tutorials/index.html">进阶教程</a></li>
......@@ -146,6 +146,168 @@
<li class="toctree-l1"><a class="reference internal" href="algo/algo.html">算法原理</a></li>
</ul>
</div>
</div>
<div class="section" id="id2">
<h1>介绍<a class="headerlink" href="#id2" title="永久链接至标题"></a></h1>
<p>PaddleSlim是一个模型压缩工具库,包含模型剪裁、定点量化、知识蒸馏、超参搜索和模型结构搜索等一系列模型压缩策略。</p>
<p>对于业务用户,PaddleSlim提供完整的模型压缩解决方案,可用于图像分类、检测、分割等各种类型的视觉场景。
同时也在持续探索NLP领域模型的压缩方案。另外,PaddleSlim提供且在不断完善各种压缩策略在经典开源任务的benchmark,
以便业务用户参考。</p>
<p>对于模型压缩算法研究者或开发者,PaddleSlim提供各种压缩策略的底层辅助接口,方便用户复现、调研和使用最新论文方法。
PaddleSlim会从底层能力、技术咨询合作和业务场景等角度支持开发者进行模型压缩策略相关的创新工作。</p>
<div class="section" id="id3">
<h2>功能<a class="headerlink" href="#id3" title="永久链接至标题"></a></h2>
<ul class="simple">
<li>模型剪裁<ul>
<li>卷积通道均匀剪裁</li>
<li>基于敏感度的卷积通道剪裁</li>
<li>基于进化算法的自动剪裁</li>
</ul>
</li>
<li>定点量化<ul>
<li>在线量化训练(training aware)</li>
<li>离线量化(post training)</li>
</ul>
</li>
<li>知识蒸馏<ul>
<li>支持单进程知识蒸馏</li>
<li>支持多进程分布式知识蒸馏</li>
</ul>
</li>
<li>神经网络结构自动搜索(NAS)<ul>
<li>支持基于进化算法的轻量神经网络结构自动搜索</li>
<li>支持One-Shot网络结构自动搜索</li>
<li>支持 FLOPS / 硬件延时约束</li>
<li>支持多平台模型延时评估</li>
<li>支持用户自定义搜索算法和搜索空间</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="id4">
<h2>部分压缩策略效果<a class="headerlink" href="#id4" title="永久链接至标题"></a></h2>
<div class="section" id="id5">
<h3>分类模型<a class="headerlink" href="#id5" title="永久链接至标题"></a></h3>
<p>数据: ImageNet2012; 模型: MobileNetV1;</p>
<table border="1" class="docutils">
<colgroup>
<col width="33%" />
<col width="33%" />
<col width="33%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">压缩策略</th>
<th class="head">精度收益(baseline: 70.91%)</th>
<th class="head">模型大小(baseline: 17.0M)</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>知识蒸馏(ResNet50)</td>
<td><strong>+1.06%</strong></td>
<td>&#160;</td>
</tr>
<tr class="row-odd"><td>知识蒸馏(ResNet50) + int8量化训练</td>
<td><strong>+1.10%</strong></td>
<td><strong>-71.76%</strong></td>
</tr>
<tr class="row-even"><td>剪裁(FLOPs-50%) + int8量化训练</td>
<td><strong>-1.71%</strong></td>
<td><strong>-86.47%</strong></td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="id6">
<h3>图像检测模型<a class="headerlink" href="#id6" title="永久链接至标题"></a></h3>
<div class="section" id="pascal-voc-mobilenet-v1-yolov3">
<h4>数据:Pascal VOC;模型:MobileNet-V1-YOLOv3<a class="headerlink" href="#pascal-voc-mobilenet-v1-yolov3" title="永久链接至标题"></a></h4>
<table border="1" class="docutils">
<colgroup>
<col width="33%" />
<col width="33%" />
<col width="33%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">压缩方法</th>
<th class="head">mAP(baseline: 76.2%)</th>
<th class="head">模型大小(baseline: 94MB)</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>知识蒸馏(ResNet34-YOLOv3)</td>
<td><strong>+2.8%</strong></td>
<td>&#160;</td>
</tr>
<tr class="row-odd"><td>剪裁 FLOPs -52.88%</td>
<td><strong>+1.4%</strong></td>
<td><strong>-67.76%</strong></td>
</tr>
<tr class="row-even"><td>知识蒸馏(ResNet34-YOLOv3)+剪裁(FLOPs-69.57%)</td>
<td><strong>+2.6%</strong></td>
<td><strong>-67.00%</strong></td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="coco-mobilenet-v1-yolov3">
<h4>数据:COCO;模型:MobileNet-V1-YOLOv3<a class="headerlink" href="#coco-mobilenet-v1-yolov3" title="永久链接至标题"></a></h4>
<table border="1" class="docutils">
<colgroup>
<col width="33%" />
<col width="33%" />
<col width="33%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">压缩方法</th>
<th class="head">mAP(baseline: 29.3%)</th>
<th class="head">模型大小</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>知识蒸馏(ResNet34-YOLOv3)</td>
<td><strong>+2.1%</strong></td>
<td>&#160;</td>
</tr>
<tr class="row-odd"><td>知识蒸馏(ResNet34-YOLOv3)+剪裁(FLOPs-67.56%)</td>
<td><strong>-0.3%</strong></td>
<td><strong>-66.90%</strong></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="section" id="id7">
<h3>搜索<a class="headerlink" href="#id7" title="永久链接至标题"></a></h3>
<p>数据:ImageNet2012; 模型:MobileNetV2</p>
<table border="1" class="docutils">
<colgroup>
<col width="33%" />
<col width="33%" />
<col width="33%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">硬件环境</th>
<th class="head">推理耗时</th>
<th class="head">Top1准确率(baseline:71.90%)</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>RK3288</td>
<td><strong>-23%</strong></td>
<td>+0.07%</td>
</tr>
<tr class="row-odd"><td>Android cellphone</td>
<td><strong>-20%</strong></td>
<td>+0.16%</td>
</tr>
<tr class="row-even"><td>iPhone 6s</td>
<td><strong>-17%</strong></td>
<td>+0.32%</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
......
......@@ -8,7 +8,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Welcome to use PaddleSlim. &mdash; PaddleSlim 1.0 documentation</title>
<title>Index &mdash; PaddleSlim 1.0 documentation</title>
......@@ -117,7 +117,7 @@
<ul class="wy-breadcrumbs">
<li><a href="#">Docs</a> &raquo;</li>
<li>Welcome to use PaddleSlim.</li>
<li>Index</li>
<li class="wy-breadcrumbs-aside">
......@@ -131,8 +131,8 @@
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<div class="section" id="welcome-to-use-paddleslim">
<h1>Welcome to use PaddleSlim.<a class="headerlink" href="#welcome-to-use-paddleslim" title="Permalink to this headline"></a></h1>
<div class="section" id="index">
<h1>Index<a class="headerlink" href="#index" title="Permalink to this headline"></a></h1>
<div class="toctree-wrapper compound">
<ul>
<li class="toctree-l1"><a class="reference internal" href="index.html">中文文档</a></li>
......@@ -144,6 +144,187 @@
<li class="toctree-l1"><a class="reference internal" href="model_zoo_en.html">Model Zoo</a></li>
</ul>
</div>
</div>
<div class="section" id="introduction">
<h1>Introduction<a class="headerlink" href="#introduction" title="Permalink to this headline"></a></h1>
<p>PaddleSlim is a toolkit for model compression. It contains a collection of compression strategies, such as pruning, fixed point quantization, knowledge distillation, hyperparameter searching and neural architecture search.</p>
<p>PaddleSlim provides solutions of compression on computer vision models, such as image classification, object detection and semantic segmentation. Meanwhile, PaddleSlim Keeps exploring advanced compression strategies for language model. Furthermore, benckmark of compression strategies on some open tasks is available for your reference.</p>
<p>PaddleSlim also provides auxiliary and primitive API for developer and researcher to survey, implement and apply the method in latest papers. PaddleSlim will support developer in ability of framework and technology consulting.</p>
<div class="section" id="features">
<h2>Features<a class="headerlink" href="#features" title="Permalink to this headline"></a></h2>
<div class="section" id="pruning">
<h3>Pruning<a class="headerlink" href="#pruning" title="Permalink to this headline"></a></h3>
<ul class="simple">
<li>Uniform pruning of convolution</li>
<li>Sensitivity-based prunning</li>
<li>Automated pruning based evolution search strategy</li>
<li>Support pruning of various deep architectures such as VGG, ResNet, and MobileNet.</li>
<li>Support self-defined range of pruning, i.e., layers to be pruned.</li>
</ul>
</div>
<div class="section" id="fixed-point-quantization">
<h3>Fixed Point Quantization<a class="headerlink" href="#fixed-point-quantization" title="Permalink to this headline"></a></h3>
<ul class="simple">
<li><strong>Training aware</strong><ul>
<li>Dynamic strategy: During inference, we quantize models with hyperparameters dynamically estimated from small batches of samples.</li>
<li>Static strategy: During inference, we quantize models with the same hyperparameters estimated from training data.</li>
<li>Support layer-wise and channel-wise quantization.</li>
</ul>
</li>
<li><strong>Post training</strong></li>
</ul>
</div>
<div class="section" id="knowledge-distillation">
<h3>Knowledge Distillation<a class="headerlink" href="#knowledge-distillation" title="Permalink to this headline"></a></h3>
<ul class="simple">
<li><strong>Naive knowledge distillation:</strong> transfers dark knowledge by merging the teacher and student model into the same Program</li>
<li><strong>Paddle large-scale scalable knowledge distillation framework Pantheon:</strong> a universal solution for knowledge distillation, more flexible than the naive knowledge distillation, and easier to scale to the large-scale applications.<ul>
<li>Decouple the teacher and student models &#8212; they run in different processes in the same or different nodes, and transfer knowledge via TCP/IP ports or local files;</li>
<li>Friendly to assemble multiple teacher models and each of them can work in either online or offline mode independently;</li>
<li>Merge knowledge from different teachers and make batch data for the student model automatically;</li>
<li>Support the large-scale knowledge prediction of teacher models on multiple devices.</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="neural-architecture-search">
<h3>Neural Architecture Search<a class="headerlink" href="#neural-architecture-search" title="Permalink to this headline"></a></h3>
<ul class="simple">
<li>Neural architecture search based on evolution strategy.</li>
<li>Support distributed search.</li>
<li>One-Shot neural architecture search.</li>
<li>Support FLOPs and latency constrained search.</li>
<li>Support the latency estimation on different hardware and platforms.</li>
</ul>
</div>
</div>
<div class="section" id="performance">
<h2>Performance<a class="headerlink" href="#performance" title="Permalink to this headline"></a></h2>
<div class="section" id="image-classification">
<h3>Image Classification<a class="headerlink" href="#image-classification" title="Permalink to this headline"></a></h3>
<p>Dataset: ImageNet2012; Model: MobileNetV1;</p>
<table border="1" class="docutils">
<colgroup>
<col width="33%" />
<col width="33%" />
<col width="33%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">Method</th>
<th class="head">Accuracy(baseline: 70.91%)</th>
<th class="head">Model Size(baseline: 17.0M)</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>Knowledge Distillation(ResNet50)</td>
<td><strong>+1.06%</strong></td>
<td>&#160;</td>
</tr>
<tr class="row-odd"><td>Knowledge Distillation(ResNet50) + int8 quantization</td>
<td><strong>+1.10%</strong></td>
<td><strong>-71.76%</strong></td>
</tr>
<tr class="row-even"><td>Pruning(FLOPs-50%) + int8 quantization</td>
<td><strong>-1.71%</strong></td>
<td><strong>-86.47%</strong></td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="object-detection">
<h3>Object Detection<a class="headerlink" href="#object-detection" title="Permalink to this headline"></a></h3>
<div class="section" id="dataset-pascal-voc-model-mobilenet-v1-yolov3">
<h4>Dataset: Pascal VOC; Model: MobileNet-V1-YOLOv3<a class="headerlink" href="#dataset-pascal-voc-model-mobilenet-v1-yolov3" title="Permalink to this headline"></a></h4>
<table border="1" class="docutils">
<colgroup>
<col width="33%" />
<col width="33%" />
<col width="33%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">Method</th>
<th class="head">mAP(baseline: 76.2%)</th>
<th class="head">Model Size(baseline: 94MB)</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>Knowledge Distillation(ResNet34-YOLOv3)</td>
<td><strong>+2.8%</strong></td>
<td>&#160;</td>
</tr>
<tr class="row-odd"><td>Pruning(FLOPs -52.88%)</td>
<td><strong>+1.4%</strong></td>
<td><strong>-67.76%</strong></td>
</tr>
<tr class="row-even"><td>Knowledge DistillationResNet34-YOLOv3)+Pruning(FLOPs-69.57%)</td>
<td><strong>+2.6%</strong></td>
<td><strong>-67.00%</strong></td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="dataset-coco-model-mobilenet-v1-yolov3">
<h4>Dataset: COCO; Model: MobileNet-V1-YOLOv3<a class="headerlink" href="#dataset-coco-model-mobilenet-v1-yolov3" title="Permalink to this headline"></a></h4>
<table border="1" class="docutils">
<colgroup>
<col width="33%" />
<col width="33%" />
<col width="33%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">Method</th>
<th class="head">mAP(baseline: 29.3%)</th>
<th class="head">Model Size</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>Knowledge Distillation(ResNet34-YOLOv3)</td>
<td><strong>+2.1%</strong></td>
<td><ul class="first last simple">
<li></li>
</ul>
</td>
</tr>
<tr class="row-odd"><td>Knowledge Distillation(ResNet34-YOLOv3)+Pruning(FLOPs-67.56%)</td>
<td><strong>-0.3%</strong></td>
<td><strong>-66.90%</strong></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="section" id="nas">
<h3>NAS<a class="headerlink" href="#nas" title="Permalink to this headline"></a></h3>
<p>Dataset: ImageNet2012; Model: MobileNetV2</p>
<table border="1" class="docutils">
<colgroup>
<col width="33%" />
<col width="33%" />
<col width="33%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">Device</th>
<th class="head">Infer time cost</th>
<th class="head">Top1 accuracy(baseline:71.90%)</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>RK3288</td>
<td><strong>-23%</strong></td>
<td>+0.07%</td>
</tr>
<tr class="row-odd"><td>Android cellphone</td>
<td><strong>-20%</strong></td>
<td>+0.16%</td>
</tr>
<tr class="row-even"><td>iPhone 6s</td>
<td><strong>-17%</strong></td>
<td>+0.32%</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
......
......@@ -35,7 +35,7 @@
<link rel="search" title="搜索" href="search.html"/>
<link rel="top" title="PaddleSlim 1.0 文档" href="index.html"/>
<link rel="next" title="快速开始" href="quick_start/index.html"/>
<link rel="prev" title="PaddleSlim简介" href="intro.html"/>
<link rel="prev" title="介绍" href="intro.html"/>
<script src="_static/js/modernizr.min.js"></script>
......@@ -82,7 +82,7 @@
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="index_en.html">English Documents</a></li>
<li class="toctree-l1"><a class="reference internal" href="intro.html">PaddleSlim简介</a></li>
<li class="toctree-l1"><a class="reference internal" href="intro.html">介绍</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">安装</a></li>
<li class="toctree-l1"><a class="reference internal" href="quick_start/index.html">快速开始</a></li>
<li class="toctree-l1"><a class="reference internal" href="tutorials/index.html">进阶教程</a></li>
......@@ -166,7 +166,7 @@ python setup.py install
<a href="quick_start/index.html" class="btn btn-neutral float-right" title="快速开始" accesskey="n">Next <span class="fa fa-arrow-circle-right"></span></a>
<a href="intro.html" class="btn btn-neutral" title="PaddleSlim简介" accesskey="p"><span class="fa fa-arrow-circle-left"></span> Previous</a>
<a href="intro.html" class="btn btn-neutral" title="介绍" accesskey="p"><span class="fa fa-arrow-circle-left"></span> Previous</a>
</div>
......
......@@ -134,25 +134,25 @@
<div class="section" id="install">
<h1>Install<a class="headerlink" href="#install" title="Permalink to this headline"></a></h1>
<p>安装PaddleSlim前,请确认已正确安装Paddle1.6版本或更新版本。Paddle安装请参考:<a class="reference external" href="https://www.paddlepaddle.org.cn/install/quick">Paddle安装教程</a></p>
<p>Please ensure you have installed PaddlePaddle1.7+. <a class="reference external" href="https://www.paddlepaddle.org.cn/install/quick">How to install PaddlePaddle</a></p>
<ul class="simple">
<li>安装develop版本</li>
<li>Install by pip</li>
</ul>
<div class="highlight-bash"><div class="highlight"><pre><span></span>git clone https://github.com/PaddlePaddle/PaddleSlim.git
<span class="nb">cd</span> PaddleSlim
python setup.py install
<div class="highlight-bash"><div class="highlight"><pre><span></span>pip install paddleslim -i https://pypi.org/simple
</pre></div>
</div>
<ul class="simple">
<li>安装官方发布的最新版本</li>
<li>Install from source</li>
</ul>
<div class="highlight-bash"><div class="highlight"><pre><span></span>pip install paddleslim -i https://pypi.org/simple
<div class="highlight-bash"><div class="highlight"><pre><span></span>git clone https://github.com/PaddlePaddle/PaddleSlim.git
<span class="nb">cd</span> PaddleSlim
python setup.py install
</pre></div>
</div>
<ul class="simple">
<li>安装历史版本</li>
<li>History packages</li>
</ul>
<p>请点击<a class="reference external" href="https://pypi.org/project/paddleslim/#history">pypi.org</a>查看可安装历史版本。</p>
<p>History packages is available in <a class="reference external" href="https://pypi.org/project/paddleslim/#history">pypi.org</a>.</p>
</div>
......
......@@ -8,7 +8,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PaddleSlim简介 &mdash; PaddleSlim 1.0 文档</title>
<title>介绍 &mdash; PaddleSlim 1.0 文档</title>
......@@ -82,8 +82,18 @@
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="index_en.html">English Documents</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">PaddleSlim简介</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#id1">功能</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">介绍</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#id2">功能</a></li>
<li class="toctree-l2"><a class="reference internal" href="#id3">部分压缩策略效果</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#id4">分类模型</a></li>
<li class="toctree-l3"><a class="reference internal" href="#id5">图像检测模型</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#pascal-voc-mobilenet-v1-yolov3">数据:Pascal VOC;模型:MobileNet-V1-YOLOv3</a></li>
<li class="toctree-l4"><a class="reference internal" href="#coco-mobilenet-v1-yolov3">数据:COCO;模型:MobileNet-V1-YOLOv3</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="#id6">搜索</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="install.html">安装</a></li>
......@@ -122,7 +132,7 @@
<ul class="wy-breadcrumbs">
<li><a href="index.html">Docs</a> &raquo;</li>
<li>PaddleSlim简介</li>
<li>介绍</li>
<li class="wy-breadcrumbs-aside">
......@@ -136,22 +146,26 @@
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<div class="section" id="paddleslim">
<h1>PaddleSlim简介<a class="headerlink" href="#paddleslim" title="永久链接至标题"></a></h1>
<p>PaddleSlim是PaddlePaddle框架的一个子模块,主要用于压缩图像领域模型。在PaddleSlim中,不仅实现了目前主流的网络剪枝、量化、蒸馏三种压缩策略,还实现了超参数搜索和小模型网络结构搜索功能。在后续版本中,会添加更多的压缩策略,以及完善对NLP领域模型的支持。</p>
<div class="section" id="id1">
<h2>功能<a class="headerlink" href="#id1" title="永久链接至标题"></a></h2>
<div class="section" id="id1">
<h1>介绍<a class="headerlink" href="#id1" title="永久链接至标题"></a></h1>
<p>PaddleSlim是一个模型压缩工具库,包含模型剪裁、定点量化、知识蒸馏、超参搜索和模型结构搜索等一系列模型压缩策略。</p>
<p>对于业务用户,PaddleSlim提供完整的模型压缩解决方案,可用于图像分类、检测、分割等各种类型的视觉场景。
同时也在持续探索NLP领域模型的压缩方案。另外,PaddleSlim提供且在不断完善各种压缩策略在经典开源任务的benchmark,
以便业务用户参考。</p>
<p>对于模型压缩算法研究者或开发者,PaddleSlim提供各种压缩策略的底层辅助接口,方便用户复现、调研和使用最新论文方法。
PaddleSlim会从底层能力、技术咨询合作和业务场景等角度支持开发者进行模型压缩策略相关的创新工作。</p>
<div class="section" id="id2">
<h2>功能<a class="headerlink" href="#id2" title="永久链接至标题"></a></h2>
<ul class="simple">
<li>模型剪裁<ul>
<li>支持通道均匀模型剪裁(uniform pruning)</li>
<li>基于敏感度的模型剪裁</li>
<li>基于进化算法的自动模型剪裁三种方式</li>
<li>卷积通道均匀剪裁</li>
<li>基于敏感度的卷积通道剪裁</li>
<li>基于进化算法的自动剪裁</li>
</ul>
</li>
<li>量化训练<ul>
<li>定点量化<ul>
<li>在线量化训练(training aware)</li>
<li>离线量化(post training)</li>
<li>支持对权重全局量化和Channel-Wise量化</li>
</ul>
</li>
<li>知识蒸馏<ul>
......@@ -160,14 +174,130 @@
</ul>
</li>
<li>神经网络结构自动搜索(NAS)<ul>
<li>支持One-Shot网络结构自动搜索(Ont-Shot-NAS)</li>
<li>支持基于进化算法的轻量神经网络结构自动搜索(Light-NAS)</li>
<li>支持基于进化算法的轻量神经网络结构自动搜索</li>
<li>支持One-Shot网络结构自动搜索</li>
<li>支持 FLOPS / 硬件延时约束</li>
<li>支持多平台模型延时评估</li>
<li>支持用户自定义搜索算法和搜索空间</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="id3">
<h2>部分压缩策略效果<a class="headerlink" href="#id3" title="永久链接至标题"></a></h2>
<div class="section" id="id4">
<h3>分类模型<a class="headerlink" href="#id4" title="永久链接至标题"></a></h3>
<p>数据: ImageNet2012; 模型: MobileNetV1;</p>
<table border="1" class="docutils">
<thead>
<tr>
<th align="center">压缩策略</th>
<th align="center">精度收益(baseline: 70.91%)</th>
<th align="center">模型大小(baseline: 17.0M)</th>
</tr>
</thead>
<tbody>
<tr>
<td align="center">知识蒸馏(ResNet50)</td>
<td align="center"><strong>+1.06%</strong></td>
<td align="center"></td>
</tr>
<tr>
<td align="center">知识蒸馏(ResNet50) + int8量化训练</td>
<td align="center"><strong>+1.10%</strong></td>
<td align="center"><strong>-71.76%</strong></td>
</tr>
<tr>
<td align="center">剪裁(FLOPs-50%) + int8量化训练</td>
<td align="center"><strong>-1.71%</strong></td>
<td align="center"><strong>-86.47%</strong></td>
</tr>
</tbody>
</table></div>
<div class="section" id="id5">
<h3>图像检测模型<a class="headerlink" href="#id5" title="永久链接至标题"></a></h3>
<div class="section" id="pascal-voc-mobilenet-v1-yolov3">
<h4>数据:Pascal VOC;模型:MobileNet-V1-YOLOv3<a class="headerlink" href="#pascal-voc-mobilenet-v1-yolov3" title="永久链接至标题"></a></h4>
<table border="1" class="docutils">
<thead>
<tr>
<th align="center">压缩方法</th>
<th align="center">mAP(baseline: 76.2%)</th>
<th align="center">模型大小(baseline: 94MB)</th>
</tr>
</thead>
<tbody>
<tr>
<td align="center">知识蒸馏(ResNet34-YOLOv3)</td>
<td align="center"><strong>+2.8%</strong></td>
<td align="center"></td>
</tr>
<tr>
<td align="center">剪裁 FLOPs -52.88%</td>
<td align="center"><strong>+1.4%</strong></td>
<td align="center"><strong>-67.76%</strong></td>
</tr>
<tr>
<td align="center">知识蒸馏(ResNet34-YOLOv3)+剪裁(FLOPs-69.57%)</td>
<td align="center"><strong>+2.6%</strong></td>
<td align="center"><strong>-67.00%</strong></td>
</tr>
</tbody>
</table></div>
<div class="section" id="coco-mobilenet-v1-yolov3">
<h4>数据:COCO;模型:MobileNet-V1-YOLOv3<a class="headerlink" href="#coco-mobilenet-v1-yolov3" title="永久链接至标题"></a></h4>
<table border="1" class="docutils">
<thead>
<tr>
<th align="center">压缩方法</th>
<th align="center">mAP(baseline: 29.3%)</th>
<th align="center">模型大小</th>
</tr>
</thead>
<tbody>
<tr>
<td align="center">知识蒸馏(ResNet34-YOLOv3)</td>
<td align="center"><strong>+2.1%</strong></td>
<td align="center"></td>
</tr>
<tr>
<td align="center">知识蒸馏(ResNet34-YOLOv3)+剪裁(FLOPs-67.56%)</td>
<td align="center"><strong>-0.3%</strong></td>
<td align="center"><strong>-66.90%</strong></td>
</tr>
</tbody>
</table></div>
</div>
<div class="section" id="id6">
<h3>搜索<a class="headerlink" href="#id6" title="永久链接至标题"></a></h3>
<p>数据:ImageNet2012; 模型:MobileNetV2</p>
<table border="1" class="docutils">
<thead>
<tr>
<th align="center">硬件环境</th>
<th align="center">推理耗时</th>
<th align="center">Top1准确率(baseline:71.90%)</th>
</tr>
</thead>
<tbody>
<tr>
<td align="center">RK3288</td>
<td align="center"><strong>-23%</strong></td>
<td align="center">+0.07%</td>
</tr>
<tr>
<td align="center">Android cellphone</td>
<td align="center"><strong>-20%</strong></td>
<td align="center">+0.16%</td>
</tr>
<tr>
<td align="center">iPhone 6s</td>
<td align="center"><strong>-17%</strong></td>
<td align="center">+0.32%</td>
</tr>
</tbody>
</table></div>
</div>
</div>
......
......@@ -83,7 +83,23 @@
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="index.html">中文文档</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">Introduction</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#methods">Methods</a></li>
<li class="toctree-l2"><a class="reference internal" href="#features">Features</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#pruning">Pruning</a></li>
<li class="toctree-l3"><a class="reference internal" href="#fixed-point-quantization">Fixed Point Quantization</a></li>
<li class="toctree-l3"><a class="reference internal" href="#knowledge-distillation">Knowledge Distillation</a></li>
<li class="toctree-l3"><a class="reference internal" href="#neural-architecture-search">Neural Architecture Search</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="#performance">Performance</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#image-classification">Image Classification</a></li>
<li class="toctree-l3"><a class="reference internal" href="#object-detection">Object Detection</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#dataset-pascal-voc-model-mobilenet-v1-yolov3">Dataset: Pascal VOC; Model: MobileNet-V1-YOLOv3</a></li>
<li class="toctree-l4"><a class="reference internal" href="#dataset-coco-model-mobilenet-v1-yolov3">Dataset: COCO; Model: MobileNet-V1-YOLOv3</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="#nas">NAS</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="install_en.html">Install</a></li>
......@@ -137,36 +153,172 @@
<div class="section" id="introduction">
<h1>Introduction<a class="headerlink" href="#introduction" title="Permalink to this headline"></a></h1>
<p>As a submodule of PaddlePaddle framework, PaddleSlim is an open-source library for deep model compression and architecture search. PaddleSlim supports current popular deep compression techniques such as pruning, quantization, and knowledge distillation. Further, it also automates the search of hyperparameters and the design of lightweight deep architectures. In the future, we will develop more practically useful compression techniques for industrial-level applications and transfer these techniques to models in NLP.</p>
<div class="section" id="methods">
<h2>Methods<a class="headerlink" href="#methods" title="Permalink to this headline"></a></h2>
<p>PaddleSlim is a toolkit for model compression. It contains a collection of compression strategies, such as pruning, fixed point quantization, knowledge distillation, hyperparameter searching and neural architecture search.</p>
<p>PaddleSlim provides solutions of compression on computer vision models, such as image classification, object detection and semantic segmentation. Meanwhile, PaddleSlim Keeps exploring advanced compression strategies for language model. Furthermore, benckmark of compression strategies on some open tasks is available for your reference.</p>
<p>PaddleSlim also provides auxiliary and primitive API for developer and researcher to survey, implement and apply the method in latest papers. PaddleSlim will support developer in ability of framework and technology consulting.</p>
<div class="section" id="features">
<h2>Features<a class="headerlink" href="#features" title="Permalink to this headline"></a></h2>
<div class="section" id="pruning">
<h3>Pruning<a class="headerlink" href="#pruning" title="Permalink to this headline"></a></h3>
<ul class="simple">
<li>Pruning<ul>
<li>Uniform pruning</li>
<li>Sensitivity-based pruning</li>
<li>Automated model pruning</li>
<li>Uniform pruning of convolution</li>
<li>Sensitivity-based prunning</li>
<li>Automated pruning based evolution search strategy</li>
<li>Support pruning of various deep architectures such as VGG, ResNet, and MobileNet.</li>
<li>Support self-defined range of pruning, i.e., layers to be pruned.</li>
</ul>
</li>
<li>Quantization<ul>
<li>Training-aware quantization: Quantize models with hyperparameters dynamically estimated from small batches of samples.</li>
<li>Training-aware quantization: Quantize models with the same hyperparameters estimated from training data.</li>
<li>Support global quantization of weights and Channel-Wise quantization</li>
</div>
<div class="section" id="fixed-point-quantization">
<h3>Fixed Point Quantization<a class="headerlink" href="#fixed-point-quantization" title="Permalink to this headline"></a></h3>
<ul class="simple">
<li><strong>Training aware</strong><ul>
<li>Dynamic strategy: During inference, we quantize models with hyperparameters dynamically estimated from small batches of samples.</li>
<li>Static strategy: During inference, we quantize models with the same hyperparameters estimated from training data.</li>
<li>Support layer-wise and channel-wise quantization.</li>
</ul>
</li>
<li>Knowledge Distillation<ul>
<li>Single-process knowledge distillation</li>
<li>Multi-process distributed knowledge distillation</li>
<li><strong>Post training</strong></li>
</ul>
</li>
<li>Network Architecture Search(NAS)<ul>
<li>Simulated Annealing (SA)-based lightweight network architecture search method.(Light-NAS)</li>
<li>One-Shot network structure automatic search. (One-Shot-NAS)</li>
<li>PaddleSlim supports FLOPs and latency constrained search.</li>
<li>PaddleSlim supports the latency estimation on different hardware and platforms.</li>
</div>
<div class="section" id="knowledge-distillation">
<h3>Knowledge Distillation<a class="headerlink" href="#knowledge-distillation" title="Permalink to this headline"></a></h3>
<ul class="simple">
<li><strong>Naive knowledge distillation:</strong> transfers dark knowledge by merging the teacher and student model into the same Program</li>
<li><strong>Paddle large-scale scalable knowledge distillation framework Pantheon:</strong> a universal solution for knowledge distillation, more flexible than the naive knowledge distillation, and easier to scale to the large-scale applications.<ul>
<li>Decouple the teacher and student models &#8212; they run in different processes in the same or different nodes, and transfer knowledge via TCP/IP ports or local files;</li>
<li>Friendly to assemble multiple teacher models and each of them can work in either online or offline mode independently;</li>
<li>Merge knowledge from different teachers and make batch data for the student model automatically;</li>
<li>Support the large-scale knowledge prediction of teacher models on multiple devices.</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="neural-architecture-search">
<h3>Neural Architecture Search<a class="headerlink" href="#neural-architecture-search" title="Permalink to this headline"></a></h3>
<ul class="simple">
<li>Neural architecture search based on evolution strategy.</li>
<li>Support distributed search.</li>
<li>One-Shot neural architecture search.</li>
<li>Support FLOPs and latency constrained search.</li>
<li>Support the latency estimation on different hardware and platforms.</li>
</ul>
</div>
</div>
<div class="section" id="performance">
<h2>Performance<a class="headerlink" href="#performance" title="Permalink to this headline"></a></h2>
<div class="section" id="image-classification">
<h3>Image Classification<a class="headerlink" href="#image-classification" title="Permalink to this headline"></a></h3>
<p>Dataset: ImageNet2012; Model: MobileNetV1;</p>
<table border="1" class="docutils">
<thead>
<tr>
<th align="center">Method</th>
<th align="center">Accuracy(baseline: 70.91%)</th>
<th align="center">Model Size(baseline: 17.0M)</th>
</tr>
</thead>
<tbody>
<tr>
<td align="center">Knowledge Distillation(ResNet50)</td>
<td align="center"><strong>+1.06%</strong></td>
<td align="center"></td>
</tr>
<tr>
<td align="center">Knowledge Distillation(ResNet50) + int8 quantization</td>
<td align="center"><strong>+1.10%</strong></td>
<td align="center"><strong>-71.76%</strong></td>
</tr>
<tr>
<td align="center">Pruning(FLOPs-50%) + int8 quantization</td>
<td align="center"><strong>-1.71%</strong></td>
<td align="center"><strong>-86.47%</strong></td>
</tr>
</tbody>
</table></div>
<div class="section" id="object-detection">
<h3>Object Detection<a class="headerlink" href="#object-detection" title="Permalink to this headline"></a></h3>
<div class="section" id="dataset-pascal-voc-model-mobilenet-v1-yolov3">
<h4>Dataset: Pascal VOC; Model: MobileNet-V1-YOLOv3<a class="headerlink" href="#dataset-pascal-voc-model-mobilenet-v1-yolov3" title="Permalink to this headline"></a></h4>
<table border="1" class="docutils">
<thead>
<tr>
<th align="center">Method</th>
<th align="center">mAP(baseline: 76.2%)</th>
<th align="center">Model Size(baseline: 94MB)</th>
</tr>
</thead>
<tbody>
<tr>
<td align="center">Knowledge Distillation(ResNet34-YOLOv3)</td>
<td align="center"><strong>+2.8%</strong></td>
<td align="center"></td>
</tr>
<tr>
<td align="center">Pruning(FLOPs -52.88%)</td>
<td align="center"><strong>+1.4%</strong></td>
<td align="center"><strong>-67.76%</strong></td>
</tr>
<tr>
<td align="center">Knowledge DistillationResNet34-YOLOv3)+Pruning(FLOPs-69.57%)</td>
<td align="center"><strong>+2.6%</strong></td>
<td align="center"><strong>-67.00%</strong></td>
</tr>
</tbody>
</table></div>
<div class="section" id="dataset-coco-model-mobilenet-v1-yolov3">
<h4>Dataset: COCO; Model: MobileNet-V1-YOLOv3<a class="headerlink" href="#dataset-coco-model-mobilenet-v1-yolov3" title="Permalink to this headline"></a></h4>
<table border="1" class="docutils">
<thead>
<tr>
<th align="center">Method</th>
<th align="center">mAP(baseline: 29.3%)</th>
<th align="center">Model Size</th>
</tr>
</thead>
<tbody>
<tr>
<td align="center">Knowledge Distillation(ResNet34-YOLOv3)</td>
<td align="center"><strong>+2.1%</strong></td>
<td align="center">-</td>
</tr>
<tr>
<td align="center">Knowledge Distillation(ResNet34-YOLOv3)+Pruning(FLOPs-67.56%)</td>
<td align="center"><strong>-0.3%</strong></td>
<td align="center"><strong>-66.90%</strong></td>
</tr>
</tbody>
</table></div>
</div>
<div class="section" id="nas">
<h3>NAS<a class="headerlink" href="#nas" title="Permalink to this headline"></a></h3>
<p>Dataset: ImageNet2012; Model: MobileNetV2</p>
<table border="1" class="docutils">
<thead>
<tr>
<th align="center">Device</th>
<th align="center">Infer time cost</th>
<th align="center">Top1 accuracy(baseline:71.90%)</th>
</tr>
</thead>
<tbody>
<tr>
<td align="center">RK3288</td>
<td align="center"><strong>-23%</strong></td>
<td align="center">+0.07%</td>
</tr>
<tr>
<td align="center">Android cellphone</td>
<td align="center"><strong>-20%</strong></td>
<td align="center">+0.16%</td>
</tr>
<tr>
<td align="center">iPhone 6s</td>
<td align="center"><strong>-17%</strong></td>
<td align="center">+0.32%</td>
</tr>
</tbody>
</table></div>
</div>
</div>
......
......@@ -82,27 +82,29 @@
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="index_en.html">English Documents</a></li>
<li class="toctree-l1"><a class="reference internal" href="intro.html">PaddleSlim简介</a></li>
<li class="toctree-l1"><a class="reference internal" href="intro.html">介绍</a></li>
<li class="toctree-l1"><a class="reference internal" href="install.html">安装</a></li>
<li class="toctree-l1"><a class="reference internal" href="quick_start/index.html">快速开始</a></li>
<li class="toctree-l1"><a class="reference internal" href="tutorials/index.html">进阶教程</a></li>
<li class="toctree-l1"><a class="reference internal" href="api_cn/index.html">API文档</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">模型库</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#id2">1. 图分类</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#id2">1. 图分类</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#id3">1.1 量化</a></li>
<li class="toctree-l3"><a class="reference internal" href="#id4">1.2 剪裁</a></li>
<li class="toctree-l3"><a class="reference internal" href="#id5">1.3 蒸馏</a></li>
<li class="toctree-l3"><a class="reference internal" href="#id6">1.4 搜索</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="#id6">2. 目标检测</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#id7">2.1 量化</a></li>
<li class="toctree-l3"><a class="reference internal" href="#id8">2.2 剪裁</a></li>
<li class="toctree-l3"><a class="reference internal" href="#id9">2.3 蒸馏</a></li>
<li class="toctree-l2"><a class="reference internal" href="#id7">2. 目标检测</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#id8">2.1 量化</a></li>
<li class="toctree-l3"><a class="reference internal" href="#id9">2.2 剪裁</a></li>
<li class="toctree-l3"><a class="reference internal" href="#id10">2.3 蒸馏</a></li>
<li class="toctree-l3"><a class="reference internal" href="#id11">2.4 搜索</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="#id10">3. 图像分割</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#id11">3.1 量化</a></li>
<li class="toctree-l3"><a class="reference internal" href="#id12">3.2 剪裁</a></li>
<li class="toctree-l2"><a class="reference internal" href="#id13">3. 图像分割</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#id14">3.1 量化</a></li>
<li class="toctree-l3"><a class="reference internal" href="#id15">3.2 剪裁</a></li>
</ul>
</li>
</ul>
......@@ -155,7 +157,7 @@
<div class="section" id="id1">
<h1>模型库<a class="headerlink" href="#id1" title="永久链接至标题"></a></h1>
<div class="section" id="id2">
<h2>1. 图分类<a class="headerlink" href="#id2" title="永久链接至标题"></a></h2>
<h2>1. 图分类<a class="headerlink" href="#id2" title="永久链接至标题"></a></h2>
<p>数据集:ImageNet1000类</p>
<div class="section" id="id3">
<h3>1.1 量化<a class="headerlink" href="#id3" title="永久链接至标题"></a></h3>
......@@ -561,6 +563,10 @@
</table></div>
<div class="section" id="id4">
<h3>1.2 剪裁<a class="headerlink" href="#id4" title="永久链接至标题"></a></h3>
<p>PaddleLite推理耗时说明:</p>
<p>环境:Qualcomm SnapDragon 845 + armv8</p>
<p>速度指标:Thread1/Thread2/Thread4耗时</p>
<p>PaddleLite版本: v2.3</p>
<table border="1" class="docutils">
<thead>
<tr>
......@@ -569,6 +575,8 @@
<th align="center">Top-1/Top-5 Acc</th>
<th align="center">模型体积(MB)</th>
<th align="center">GFLOPs</th>
<th align="center">PaddleLite推理耗时</th>
<th align="center">TensorRT推理速度(FPS)</th>
<th align="center">下载</th>
</tr>
</thead>
......@@ -579,6 +587,8 @@
<td align="center">70.99%/89.68%</td>
<td align="center">17</td>
<td align="center">1.11</td>
<td align="center">66.052\35.8014\19.5762</td>
<td align="center">-</td>
<td align="center"><a href="http://paddle-imagenet-models-name.bj.bcebos.com/MobileNetV1_pretrained.tar">下载链接</a></td>
</tr>
<tr>
......@@ -587,6 +597,8 @@
<td align="center">69.4%/88.66% (-1.59%/-1.02%)</td>
<td align="center">9</td>
<td align="center">0.56</td>
<td align="center">33.5636\18.6834\10.5076</td>
<td align="center">-</td>
<td align="center"><a href="https://paddlemodels.bj.bcebos.com/PaddleSlim/MobileNetV1_uniform-50.tar">下载链接</a></td>
</tr>
<tr>
......@@ -595,6 +607,8 @@
<td align="center">70.4%/89.3% (-0.59%/-0.38%)</td>
<td align="center">12</td>
<td align="center">0.74</td>
<td align="center">46.5958\25.3098\13.6982</td>
<td align="center">-</td>
<td align="center"><a href="https://paddlemodels.bj.bcebos.com/PaddleSlim/MobileNetV1_sensitive-30.tar">下载链接</a></td>
</tr>
<tr>
......@@ -603,6 +617,8 @@
<td align="center">69.8% / 88.9% (-1.19%/-0.78%)</td>
<td align="center">9</td>
<td align="center">0.56</td>
<td align="center">37.9892\20.7882\11.3144</td>
<td align="center">-</td>
<td align="center"><a href="https://paddlemodels.bj.bcebos.com/PaddleSlim/MobileNetV1_sensitive-50.tar">下载链接</a></td>
</tr>
<tr>
......@@ -611,6 +627,8 @@
<td align="center">72.15%/90.65%</td>
<td align="center">15</td>
<td align="center">0.59</td>
<td align="center">41.7874\23.375\13.3998</td>
<td align="center">-</td>
<td align="center"><a href="https://paddle-imagenet-models-name.bj.bcebos.com/MobileNetV2_pretrained.tar">下载链接</a></td>
</tr>
<tr>
......@@ -619,6 +637,8 @@
<td align="center">65.79%/86.11% (-6.35%/-4.47%)</td>
<td align="center">11</td>
<td align="center">0.296</td>
<td align="center">23.8842\13.8698\8.5572</td>
<td align="center">-</td>
<td align="center"><a href="https://paddlemodels.bj.bcebos.com/PaddleSlim/MobileNetV2_uniform-50.tar">下载链接</a></td>
</tr>
<tr>
......@@ -627,6 +647,8 @@
<td align="center">72.15%/90.65%</td>
<td align="center">84</td>
<td align="center">7.36</td>
<td align="center">217.808\139.943\96.7504</td>
<td align="center">342.32</td>
<td align="center"><a href="https://paddle-imagenet-models-name.bj.bcebos.com/ResNet34_pretrained.tar">下载链接</a></td>
</tr>
<tr>
......@@ -635,6 +657,8 @@
<td align="center">70.99%/89.95% (-1.36%/-0.87%)</td>
<td align="center">41</td>
<td align="center">3.67</td>
<td align="center">114.787\75.0332\51.8438</td>
<td align="center">452.41</td>
<td align="center"><a href="https://paddlemodels.bj.bcebos.com/PaddleSlim/ResNet34_uniform-50.tar">下载链接</a></td>
</tr>
<tr>
......@@ -643,6 +667,8 @@
<td align="center">70.24%/89.63% (-2.04%/-1.06%)</td>
<td align="center">33</td>
<td align="center">3.31</td>
<td align="center">105.924\69.3222\48.0246</td>
<td align="center">457.25</td>
<td align="center"><a href="https://paddlemodels.bj.bcebos.com/PaddleSlim/ResNet34_auto-55.tar">下载链接</a></td>
</tr>
</tbody>
......@@ -717,16 +743,74 @@
<td align="center"><a href="https://paddlemodels.bj.bcebos.com/PaddleSlim/ResNet50_distilled.tar">下载链接</a></td>
</tr>
</tbody>
</table><p>!!! note &#8220;Note&#8220;</p>
<div class="highlight-default"><div class="highlight"><pre><span></span>&lt;a name=&quot;trans1&quot;&gt;[1]&lt;/a&gt;:带_vd后缀代表该预训练模型使用了Mixup,Mixup相关介绍参考[mixup: Beyond Empirical Risk Minimization](https://arxiv.org/abs/1710.09412)
</pre></div>
</table><p>注意:带&#8221;_vd&#8221;后缀代表该预训练模型使用了Mixup,Mixup相关介绍参考<a class="reference external" href="https://arxiv.org/abs/1710.09412">mixup: Beyond Empirical Risk Minimization</a></p>
</div>
<div class="section" id="id6">
<h3>1.4 搜索<a class="headerlink" href="#id6" title="永久链接至标题"></a></h3>
<p>数据集: ImageNet1000</p>
<table border="1" class="docutils">
<thead>
<tr>
<th align="center">模型</th>
<th align="center">压缩方法</th>
<th align="center">Top-1/Top-5 Acc</th>
<th align="center">模型体积(MB)</th>
<th align="center">GFLOPs</th>
<th align="center">下载</th>
</tr>
</thead>
<tbody>
<tr>
<td align="center">MobileNetV2</td>
<td align="center">-</td>
<td align="center">72.15%/90.65%</td>
<td align="center">15</td>
<td align="center">0.59</td>
<td align="center"><a href="https://paddle-imagenet-models-name.bj.bcebos.com/MobileNetV2_pretrained.tar">下载链接</a></td>
</tr>
<tr>
<td align="center">MobileNetV2</td>
<td align="center">SANAS</td>
<td align="center">71.518%/90.208% (-0.632%/-0.442%)</td>
<td align="center">14</td>
<td align="center">0.295</td>
<td align="center"><a href="https://paddlemodels.cdn.bcebos.com/PaddleSlim/MobileNetV2_sanas.tar">下载链接</a></td>
</tr>
</tbody>
</table><p>数据集: Cifar10</p>
<table border="1" class="docutils">
<thead>
<tr>
<th align="center">模型</th>
<th align="center">压缩方法</th>
<th align="center">Acc</th>
<th align="center">模型参数(MB)</th>
<th align="center">下载</th>
</tr>
</thead>
<tbody>
<tr>
<td align="center">Darts</td>
<td align="center">-</td>
<td align="center">97.135%</td>
<td align="center">3.767</td>
<td align="center">-</td>
</tr>
<tr>
<td align="center">Darts_SA(基于Darts搜索空间)</td>
<td align="center">SANAS</td>
<td align="center">97.276%(+0.141%)</td>
<td align="center">3.344(-11.2%)</td>
<td align="center">-</td>
</tr>
</tbody>
</table><p>Note: MobileNetV2_NAS 的token是:[4,&nbsp;4,&nbsp;5,&nbsp;1,&nbsp;1,&nbsp;2,&nbsp;1,&nbsp;1,&nbsp;0,&nbsp;2,&nbsp;6,&nbsp;2,&nbsp;0,&nbsp;3,&nbsp;4,&nbsp;5,&nbsp;0,&nbsp;4,&nbsp;5,&nbsp;5,&nbsp;1,&nbsp;4,&nbsp;8,&nbsp;0,&nbsp;0]. Darts_SA的token是:[5, 5, 0, 5, 5, 10, 7, 7, 5, 7, 7, 11, 10, 12, 10, 0, 5, 3, 10, 8].</p>
</div>
</div>
<div class="section" id="id6">
<h2>2. 目标检测<a class="headerlink" href="#id6" title="永久链接至标题"></a></h2>
<div class="section" id="id7">
<h3>2.1 量化<a class="headerlink" href="#id7" title="永久链接至标题"></a></h3>
<h2>2. 目标检测<a class="headerlink" href="#id7" title="永久链接至标题"></a></h2>
<div class="section" id="id8">
<h3>2.1 量化<a class="headerlink" href="#id8" title="永久链接至标题"></a></h3>
<p>数据集: COCO 2017</p>
<table border="1" class="docutils">
<thead>
......@@ -938,9 +1022,13 @@
</tr>
</tbody>
</table></div>
<div class="section" id="id8">
<h3>2.2 剪裁<a class="headerlink" href="#id8" title="永久链接至标题"></a></h3>
<div class="section" id="id9">
<h3>2.2 剪裁<a class="headerlink" href="#id9" title="永久链接至标题"></a></h3>
<p>数据集:Pasacl VOC &amp; COCO 2017</p>
<p>PaddleLite推理耗时说明:</p>
<p>环境:Qualcomm SnapDragon 845 + armv8</p>
<p>速度指标:Thread1/Thread2/Thread4耗时</p>
<p>PaddleLite版本: v2.3</p>
<table border="1" class="docutils">
<thead>
<tr>
......@@ -953,6 +1041,8 @@
<th align="center">输入320 Box AP</th>
<th align="center">模型体积(MB)</th>
<th align="center">GFLOPs (608*608)</th>
<th align="center">PaddleLite推理耗时(ms)(608*608)</th>
<th align="center">TensorRT推理速度(FPS)(608*608)</th>
<th align="center">下载</th>
</tr>
</thead>
......@@ -967,6 +1057,8 @@
<td align="center">75.3</td>
<td align="center">94</td>
<td align="center">40.49</td>
<td align="center">1238\796.943\520.101</td>
<td align="center">60.04</td>
<td align="center"><a href="https://paddlemodels.bj.bcebos.com/object_detection/yolov3_mobilenet_v1_voc.tar">下载链接</a></td>
</tr>
<tr>
......@@ -979,6 +1071,8 @@
<td align="center">75.5 (+0.2)</td>
<td align="center">31</td>
<td align="center">19.08</td>
<td align="center">602.497\353.759\222.427</td>
<td align="center">99.36</td>
<td align="center"><a href="https://paddlemodels.bj.bcebos.com/PaddleSlim/yolov3_mobilenet_v1_voc_prune.tar">下载链接</a></td>
</tr>
<tr>
......@@ -991,6 +1085,8 @@
<td align="center">27.0</td>
<td align="center">95</td>
<td align="center">41.35</td>
<td align="center">-</td>
<td align="center">-</td>
<td align="center"><a href="https://paddlemodels.bj.bcebos.com/object_detection/yolov3_mobilenet_v1.tar">下载链接</a></td>
</tr>
<tr>
......@@ -1003,6 +1099,8 @@
<td align="center">22.6 (-4.4)</td>
<td align="center">32</td>
<td align="center">19.94</td>
<td align="center">-</td>
<td align="center">73.93</td>
<td align="center"><a href="https://paddlemodels.bj.bcebos.com/PaddleSlim/yolov3_mobilenet_v1_prune.tar">下载链接</a></td>
</tr>
<tr>
......@@ -1015,6 +1113,8 @@
<td align="center">-</td>
<td align="center">177</td>
<td align="center">89.60</td>
<td align="center">-</td>
<td align="center">27.68</td>
<td align="center"><a href="https://paddlemodels.bj.bcebos.com/object_detection/yolov3_r50vd_dcn.tar">下载链接</a></td>
</tr>
<tr>
......@@ -1027,6 +1127,8 @@
<td align="center">-</td>
<td align="center">150</td>
<td align="center">81.20</td>
<td align="center">-</td>
<td align="center">30.08</td>
<td align="center"><a href="https://paddlemodels.bj.bcebos.com/PaddleSlim/yolov3_r50vd_dcn_prune.tar">下载链接</a></td>
</tr>
<tr>
......@@ -1039,6 +1141,8 @@
<td align="center">-</td>
<td align="center">113</td>
<td align="center">67.48</td>
<td align="center">-</td>
<td align="center">34.32</td>
<td align="center"><a href="https://paddlemodels.bj.bcebos.com/PaddleSlim/yolov3_r50vd_dcn_prune578.tar">下载链接</a></td>
</tr>
<tr>
......@@ -1051,6 +1155,8 @@
<td align="center">-</td>
<td align="center">177</td>
<td align="center">89.60</td>
<td align="center">-</td>
<td align="center">-</td>
<td align="center"><a href="https://paddlemodels.bj.bcebos.com/object_detection/yolov3_r50vd_dcn_obj365_pretrained_coco.tar">下载链接</a></td>
</tr>
<tr>
......@@ -1063,6 +1169,8 @@
<td align="center">-</td>
<td align="center">150</td>
<td align="center">81.20</td>
<td align="center">-</td>
<td align="center">-</td>
<td align="center"><a href="https://paddlemodels.bj.bcebos.com/PaddleSlim/yolov3_r50vd_dcn_obj365_pretrained_coco_prune.tar">下载链接</a></td>
</tr>
<tr>
......@@ -1075,12 +1183,14 @@
<td align="center">-</td>
<td align="center">113</td>
<td align="center">67.48</td>
<td align="center">-</td>
<td align="center">-</td>
<td align="center"><a href="https://paddlemodels.bj.bcebos.com/PaddleSlim/yolov3_r50vd_dcn_obj365_pretrained_coco_prune578.tar">下载链接</a></td>
</tr>
</tbody>
</table></div>
<div class="section" id="id9">
<h3>2.3 蒸馏<a class="headerlink" href="#id9" title="永久链接至标题"></a></h3>
<div class="section" id="id10">
<h3>2.3 蒸馏<a class="headerlink" href="#id10" title="永久链接至标题"></a></h3>
<p>数据集:Pasacl VOC &amp; COCO 2017</p>
<table border="1" class="docutils">
<thead>
......@@ -1165,12 +1275,62 @@
</tr>
</tbody>
</table></div>
<div class="section" id="id11">
<h3>2.4 搜索<a class="headerlink" href="#id11" title="永久链接至标题"></a></h3>
<p>数据集:WIDER-FACE</p>
<table border="1" class="docutils">
<thead>
<tr>
<th align="center">模型</th>
<th align="center">压缩方法</th>
<th align="center">Image/GPU</th>
<th align="center">输入尺寸</th>
<th align="center">Easy/Medium/Hard</th>
<th align="center">模型体积(KB)</th>
<th align="center">硬件延时(ms)</th>
<th align="center">下载</th>
</tr>
</thead>
<tbody>
<tr>
<td align="center">BlazeFace</td>
<td align="center">-</td>
<td align="center">8</td>
<td align="center">640</td>
<td align="center">91.5/89.2/79.7</td>
<td align="center">815</td>
<td align="center">71.862</td>
<td align="center"><a href="https://paddlemodels.bj.bcebos.com/object_detection/blazeface_original.tar">下载链接</a></td>
</tr>
<tr>
<td align="center">BlazeFace-NAS</td>
<td align="center">-</td>
<td align="center">8</td>
<td align="center">640</td>
<td align="center">83.7/80.7/65.8</td>
<td align="center">244</td>
<td align="center">21.117</td>
<td align="center"><a href="https://paddlemodels.bj.bcebos.com/object_detection/blazeface_nas.tar">下载链接</a></td>
</tr>
<tr>
<td align="center">BlazeFace-NASV2</td>
<td align="center">SANAS</td>
<td align="center">8</td>
<td align="center">640</td>
<td align="center">87.0/83.7/68.5</td>
<td align="center">389</td>
<td align="center">22.558</td>
<td align="center"><a href="https://paddlemodels.bj.bcebos.com/object_detection/blazeface_nas2.tar">下载链接</a></td>
</tr>
</tbody>
</table><p>Note: 硬件延时时间是利用提供的硬件延时表得到的,硬件延时表是在855芯片上基于PaddleLite测试的结果。BlazeFace-NASV2的详细配置在<a class="reference external" href="https://github.com/PaddlePaddle/PaddleDetection/blob/master/configs/face_detection/blazeface_nas_v2.yml">这里</a>.</p>
</div>
<div class="section" id="id10">
<h2>3. 图像分割<a class="headerlink" href="#id10" title="永久链接至标题"></a></h2>
</div>
<div class="section" id="id13">
<h2>3. 图像分割<a class="headerlink" href="#id13" title="永久链接至标题"></a></h2>
<p>数据集:Cityscapes</p>
<div class="section" id="id11">
<h3>3.1 量化<a class="headerlink" href="#id11" title="永久链接至标题"></a></h3>
<div class="section" id="id14">
<h3>3.1 量化<a class="headerlink" href="#id14" title="永久链接至标题"></a></h3>
<table border="1" class="docutils">
<thead>
<tr>
......@@ -1441,8 +1601,12 @@
</tr>
</tbody>
</table></div>
<div class="section" id="id12">
<h3>3.2 剪裁<a class="headerlink" href="#id12" title="永久链接至标题"></a></h3>
<div class="section" id="id15">
<h3>3.2 剪裁<a class="headerlink" href="#id15" title="永久链接至标题"></a></h3>
<p>PaddleLite推理耗时说明:</p>
<p>环境:Qualcomm SnapDragon 845 + armv8</p>
<p>速度指标:Thread1/Thread2/Thread4耗时</p>
<p>PaddleLite版本: v2.3</p>
<table border="1" class="docutils">
<thead>
<tr>
......@@ -1451,6 +1615,8 @@
<th align="center">mIoU</th>
<th align="center">模型体积(MB)</th>
<th align="center">GFLOPs</th>
<th align="center">PaddleLite推理耗时</th>
<th align="center">TensorRT推理速度(FPS)</th>
<th align="center">下载</th>
</tr>
</thead>
......@@ -1461,6 +1627,8 @@
<td align="center">69.64</td>
<td align="center">11</td>
<td align="center">14.41</td>
<td align="center">1226.36\682.96\415.664</td>
<td align="center">39.53</td>
<td align="center"><a href="https://paddlemodels.bj.bcebos.com/PaddleSlim/fast_scnn_cityscape.tar">下载链接</a></td>
</tr>
<tr>
......@@ -1469,6 +1637,8 @@
<td align="center">69.58 (-0.06)</td>
<td align="center">8.5</td>
<td align="center">11.95</td>
<td align="center">1140.37\656.612\415.888</td>
<td align="center">42.01</td>
<td align="center"><a href="https://paddlemodels.bj.bcebos.com/PaddleSlim/fast_scnn_cityscape_uniform-17.tar">下载链接</a></td>
</tr>
<tr>
......@@ -1477,6 +1647,8 @@
<td align="center">66.68 (-2.96)</td>
<td align="center">5.7</td>
<td align="center">7.55</td>
<td align="center">866.693\494.467\291.748</td>
<td align="center">51.48</td>
<td align="center"><a href="https://paddlemodels.bj.bcebos.com/PaddleSlim/fast_scnn_cityscape_sensitive-47.tar">下载链接</a></td>
</tr>
</tbody>
......
此差异已折叠。
无法预览此类型文件
......@@ -83,7 +83,7 @@
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../index_en.html">English Documents</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intro.html">PaddleSlim简介</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intro.html">介绍</a></li>
<li class="toctree-l1"><a class="reference internal" href="../install.html">安装</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="index.html">快速开始</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="pruning_tutorial.html">图像分类模型通道剪裁-快速开始</a></li>
......@@ -154,7 +154,7 @@
<h1>图像分类模型知识蒸馏-快速开始<a class="headerlink" href="#id1" title="永久链接至标题"></a></h1>
<p>该教程以图像分类模型MobileNetV1为例,说明如何快速使用<a class="reference external" href="https://paddlepaddle.github.io/PaddleSlim/api/single_distiller_api/">PaddleSlim的知识蒸馏接口</a>
该示例包含以下步骤:</p>
<ol class="simple">
<ol class="arabic simple">
<li>导入依赖</li>
<li>定义student_program和teacher_program</li>
<li>选择特征图</li>
......@@ -165,9 +165,9 @@
<div class="section" id="id2">
<h2>1. 导入依赖<a class="headerlink" href="#id2" title="永久链接至标题"></a></h2>
<p>PaddleSlim依赖Paddle1.7版本,请确认已正确安装Paddle,然后按以下方式导入Paddle和PaddleSlim:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">paddle</span>
<span class="kn">import</span> <span class="nn">paddle.fluid</span> <span class="k">as</span> <span class="nn">fluid</span>
<span class="kn">import</span> <span class="nn">paddleslim</span> <span class="k">as</span> <span class="nn">slim</span>
<div class="highlight-guess"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">paddle</span>
<span class="kn">import</span> <span class="nn">paddle.fluid</span> <span class="kn">as</span> <span class="nn">fluid</span>
<span class="kn">import</span> <span class="nn">paddleslim</span> <span class="kn">as</span> <span class="nn">slim</span>
</pre></div>
</div>
</div>
......@@ -222,11 +222,11 @@
<span class="c1">#print(teacher_vars)</span>
</pre></div>
</div>
<p>经过筛选我们可以看到,teacher_program中的&#8216;bn5c_branch2b.output.1.tmp_3&#8216;和student_program的&#8216;depthwise_conv2d_11.tmp_0&#8216;尺寸一致,可以组成蒸馏损失函数。</p>
<p>经过筛选我们可以看到,teacher_program中的&#8217;bn5c_branch2b.output.1.tmp_3&#8217;和student_program的&#8217;depthwise_conv2d_11.tmp_0&#8217;尺寸一致,可以组成蒸馏损失函数。</p>
</div>
<div class="section" id="program-merge-loss">
<h2>4. 合并program (merge)并添加蒸馏loss<a class="headerlink" href="#program-merge-loss" title="永久链接至标题"></a></h2>
<p>merge操作将student_program和teacher_program中的所有Variables和Op都将被添加到同一个Program中,同时为了避免两个program中有同名变量会引起命名冲突,merge也会为teacher_program中的Variables添加一个同一的命名前缀name_prefix,其默认值是&#8216;teacher_&#8216;</p>
<p>merge操作将student_program和teacher_program中的所有Variables和Op都将被添加到同一个Program中,同时为了避免两个program中有同名变量会引起命名冲突,merge也会为teacher_program中的Variables添加一个同一的命名前缀name<em>prefix,其默认值是&#8217;teacher</em>&#8216;</p>
<p>为了确保teacher网络和student网络输入的数据是一样的,merge操作也会对两个program的输入数据层进行合并操作,所以需要指定一个数据层名称的映射关系data_name_map,key是teacher的输入数据名称,value是student的</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">data_name_map</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;image&#39;</span><span class="p">:</span> <span class="s1">&#39;image&#39;</span><span class="p">}</span>
<span class="n">main</span> <span class="o">=</span> <span class="n">slim</span><span class="o">.</span><span class="n">dist</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">teacher_program</span><span class="p">,</span> <span class="n">student_program</span><span class="p">,</span> <span class="n">data_name_map</span><span class="p">,</span> <span class="n">fluid</span><span class="o">.</span><span class="n">CPUPlace</span><span class="p">())</span>
......
......@@ -134,7 +134,7 @@
<h1>Knowledge Distillation for Image Classification<a class="headerlink" href="#knowledge-distillation-for-image-classification" title="Permalink to this headline"></a></h1>
<p>In this tutorial, you will learn how to use knowledge distillation API of PaddleSlim
by a demo of MobileNetV1 model on MNIST dataset. This tutorial following workflow:</p>
<ol class="simple">
<ol class="arabic simple">
<li>Import dependency</li>
<li>Define student_program and teacher_program</li>
<li>Select feature maps</li>
......@@ -144,16 +144,16 @@ by a demo of MobileNetV1 model on MNIST dataset. This tutorial following workflo
<div class="section" id="import-dependency">
<h2>1. Import dependency<a class="headerlink" href="#import-dependency" title="Permalink to this headline"></a></h2>
<p>PaddleSlim dependents on Paddle1.7. Please ensure that you have installed paddle correctly. Import Paddle and PaddleSlim as below:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">paddle</span>
<span class="kn">import</span> <span class="nn">paddle.fluid</span> <span class="k">as</span> <span class="nn">fluid</span>
<span class="kn">import</span> <span class="nn">paddleslim</span> <span class="k">as</span> <span class="nn">slim</span>
<div class="highlight-guess"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">paddle</span>
<span class="kn">import</span> <span class="nn">paddle.fluid</span> <span class="kn">as</span> <span class="nn">fluid</span>
<span class="kn">import</span> <span class="nn">paddleslim</span> <span class="kn">as</span> <span class="nn">slim</span>
</pre></div>
</div>
</div>
<div class="section" id="define-student-program-and-teacher-program">
<h2>2. Define student_program and teacher_program<a class="headerlink" href="#define-student-program-and-teacher-program" title="Permalink to this headline"></a></h2>
<p>This tutorial trains and verifies distillation model on the MNIST dataset. The input image shape is <code class="docutils literal"><span class="pre">[1,</span> <span class="pre">28,</span> <span class="pre">28]</span> </code>and the number of output categories is 10.
Select <code class="docutils literal"><span class="pre">ResNet50</span></code> as the teacher to perform distillation training on the students of the<code class="docutils literal"> <span class="pre">MobileNet</span></code> architecture.</p>
<p>This tutorial trains and verifies distillation model on the MNIST dataset. The input image shape is <code class="docutils literal"><span class="pre">[1,</span> <span class="pre">28,</span> <span class="pre">28]</span></code>and the number of output categories is 10.
Select <code class="docutils literal"><span class="pre">ResNet50</span></code> as the teacher to perform distillation training on the students of the<code class="docutils literal"><span class="pre">MobileNet</span></code> architecture.</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">model</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="vm">__dict__</span><span class="p">[</span><span class="s1">&#39;MobileNet&#39;</span><span class="p">]()</span>
<span class="n">student_program</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">Program</span><span class="p">()</span>
<span class="n">student_startup</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">Program</span><span class="p">()</span>
......@@ -183,7 +183,7 @@ Select <code class="docutils literal"><span class="pre">ResNet50</span></code> a
</div>
<div class="section" id="select-feature-maps">
<h2>3. Select feature maps<a class="headerlink" href="#select-feature-maps" title="Permalink to this headline"></a></h2>
<p>We can use the student_program&#8216;s list_vars method to observe all the Variables, and select one or more variables from it to fit the corresponding variables of the teacher.</p>
<p>We can use the student_program&#8217;s list_vars method to observe all the Variables, and select one or more variables from it to fit the corresponding variables of the teacher.</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="c1"># get all student variables</span>
<span class="n">student_vars</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">student_program</span><span class="o">.</span><span class="n">list_vars</span><span class="p">():</span>
......@@ -201,12 +201,12 @@ Select <code class="docutils literal"><span class="pre">ResNet50</span></code> a
<span class="c1">#print(teacher_vars)</span>
</pre></div>
</div>
<p>we can see that the shape of &#8216;bn5c_branch2b.output.1.tmp_3&#8216; in the teacher_program and the &#8216;depthwise_conv2d_11.tmp_0&#8216; of the student are the same and can form the distillation loss function.</p>
<p>we can see that the shape of &#8216;bn5c_branch2b.output.1.tmp_3&#8217; in the teacher_program and the &#8216;depthwise_conv2d_11.tmp_0&#8217; of the student are the same and can form the distillation loss function.</p>
</div>
<div class="section" id="merge-program-and-add-distillation-loss">
<h2>4. Merge program and add distillation loss<a class="headerlink" href="#merge-program-and-add-distillation-loss" title="Permalink to this headline"></a></h2>
<p>The merge operation adds all Variables and Ops in teacher_program to student_Program. At the same time, in order to avoid naming conflicts caused by variables with the same name in two programs, merge will also add a unified naming prefix <strong>name_prefix</strong> for Variables in teacher_program, which The default value is &#8216;teacher_&#8216;_.</p>
<p>In order to ensure that the data of the teacher network and the student network are the same, the merge operation also merges the input data layers of the two programs, so you need to specify a data layer name mapping <em><strong>data_name_map</strong></em>, where key is the input data name of the teacher, and value Is student&#8216;s.</p>
<p>The merge operation adds all Variables and Ops in teacher_program to student_Program. At the same time, in order to avoid naming conflicts caused by variables with the same name in two programs, merge will also add a unified naming prefix <strong>name_prefix</strong> for Variables in teacher<em>program, which The default value is &#8216;teacher</em>&#8216;_.</p>
<p>In order to ensure that the data of the teacher network and the student network are the same, the merge operation also merges the input data layers of the two programs, so you need to specify a data layer name mapping <a href="#id1"><span class="problematic" id="id2">**</span></a><em>data_name_map</em><a href="#id3"><span class="problematic" id="id4">**</span></a>, where key is the input data name of the teacher, and value Is student&#8217;s.</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">data_name_map</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;image&#39;</span><span class="p">:</span> <span class="s1">&#39;image&#39;</span><span class="p">}</span>
<span class="n">main</span> <span class="o">=</span> <span class="n">slim</span><span class="o">.</span><span class="n">dist</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">teacher_program</span><span class="p">,</span> <span class="n">student_program</span><span class="p">,</span> <span class="n">data_name_map</span><span class="p">,</span> <span class="n">fluid</span><span class="o">.</span><span class="n">CPUPlace</span><span class="p">())</span>
<span class="k">with</span> <span class="n">fluid</span><span class="o">.</span><span class="n">program_guard</span><span class="p">(</span><span class="n">student_program</span><span class="p">,</span> <span class="n">student_startup</span><span class="p">):</span>
......
......@@ -82,7 +82,7 @@
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../index_en.html">English Documents</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intro.html">PaddleSlim简介</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intro.html">介绍</a></li>
<li class="toctree-l1"><a class="reference internal" href="../install.html">安装</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">快速开始</a><ul>
<li class="toctree-l2"><a class="reference internal" href="pruning_tutorial.html">图像分类模型通道剪裁-快速开始</a></li>
......
......@@ -83,7 +83,7 @@
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../index_en.html">English Documents</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intro.html">PaddleSlim简介</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intro.html">介绍</a></li>
<li class="toctree-l1"><a class="reference internal" href="../install.html">安装</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="index.html">快速开始</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="pruning_tutorial.html">图像分类模型通道剪裁-快速开始</a></li>
......@@ -91,22 +91,22 @@
<li class="toctree-l2"><a class="reference internal" href="quant_aware_tutorial.html">图像分类模型量化训练-快速开始</a></li>
<li class="toctree-l2"><a class="reference internal" href="quant_post_tutorial.html">图像分类模型离线量化-快速开始</a></li>
<li class="toctree-l2 current"><a class="current reference internal" href="#">图像分类网络结构搜索-快速开始</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#id2">1. 导入依赖</a></li>
<li class="toctree-l3"><a class="reference internal" href="#id3">1. 导入依赖</a></li>
<li class="toctree-l3"><a class="reference internal" href="#sanas">2. 初始化SANAS搜索实例</a></li>
<li class="toctree-l3"><a class="reference internal" href="#id3">3. 构建网络</a></li>
<li class="toctree-l3"><a class="reference internal" href="#id4">4. 定义输入数据函数</a></li>
<li class="toctree-l3"><a class="reference internal" href="#id5">5. 定义训练函数</a></li>
<li class="toctree-l3"><a class="reference internal" href="#id6">6. 定义评估函数</a></li>
<li class="toctree-l3"><a class="reference internal" href="#id7">7. 启动搜索实验</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#id8">7.1 获取模型结构</a></li>
<li class="toctree-l3"><a class="reference internal" href="#id4">3. 构建网络</a></li>
<li class="toctree-l3"><a class="reference internal" href="#id5">4. 定义输入数据函数</a></li>
<li class="toctree-l3"><a class="reference internal" href="#id6">5. 定义训练函数</a></li>
<li class="toctree-l3"><a class="reference internal" href="#id7">6. 定义评估函数</a></li>
<li class="toctree-l3"><a class="reference internal" href="#id8">7. 启动搜索实验</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#id9">7.1 获取模型结构</a></li>
<li class="toctree-l4"><a class="reference internal" href="#program">7.2 构造program</a></li>
<li class="toctree-l4"><a class="reference internal" href="#id9">7.3 定义输入数据</a></li>
<li class="toctree-l4"><a class="reference internal" href="#id10">7.4 训练模型</a></li>
<li class="toctree-l4"><a class="reference internal" href="#id11">7.5 评估模型</a></li>
<li class="toctree-l4"><a class="reference internal" href="#id12">7.6 回传当前模型的得分</a></li>
<li class="toctree-l4"><a class="reference internal" href="#id10">7.3 定义输入数据</a></li>
<li class="toctree-l4"><a class="reference internal" href="#id11">7.4 训练模型</a></li>
<li class="toctree-l4"><a class="reference internal" href="#id12">7.5 评估模型</a></li>
<li class="toctree-l4"><a class="reference internal" href="#id13">7.6 回传当前模型的得分</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="#id13">8. 完整示例</a></li>
<li class="toctree-l3"><a class="reference internal" href="#id14">8. 完整示例</a></li>
</ul>
</li>
</ul>
......@@ -163,9 +163,9 @@
<div class="section" id="id1">
<h1>图像分类网络结构搜索-快速开始<a class="headerlink" href="#id1" title="永久链接至标题"></a></h1>
<p>该教程以图像分类模型MobileNetV2为例,说明如何在cifar10数据集上快速使用<a class="reference external" href="../api/nas_api">网络结构搜索接口</a>
<p>该教程以图像分类模型MobileNetV2为例,说明如何在cifar10数据集上快速使用<a class="reference external" href="../api/nas_api.md">网络结构搜索接口</a>
该示例包含以下步骤:</p>
<ol class="simple">
<ol class="arabic simple">
<li>导入依赖</li>
<li>初始化SANAS搜索实例</li>
<li>构建网络</li>
......@@ -182,8 +182,8 @@
<li>完整示例</li>
</ol>
<p>以下章节依次介绍每个步骤的内容。</p>
<div class="section" id="id2">
<h2>1. 导入依赖<a class="headerlink" href="#id2" title="永久链接至标题"></a></h2>
<div class="section" id="id3">
<h2>1. 导入依赖<a class="headerlink" href="#id3" title="永久链接至标题"></a></h2>
<p>请确认已正确安装Paddle,导入需要的依赖包。</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">paddle</span>
<span class="kn">import</span> <span class="nn">paddle.fluid</span> <span class="k">as</span> <span class="nn">fluid</span>
......@@ -198,8 +198,8 @@
</pre></div>
</div>
</div>
<div class="section" id="id3">
<h2>3. 构建网络<a class="headerlink" href="#id3" title="永久链接至标题"></a></h2>
<div class="section" id="id4">
<h2>3. 构建网络<a class="headerlink" href="#id4" title="永久链接至标题"></a></h2>
<p>根据传入的网络结构构造训练program和测试program。</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">build_program</span><span class="p">(</span><span class="n">archs</span><span class="p">):</span>
<span class="n">train_program</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">Program</span><span class="p">()</span>
......@@ -216,7 +216,7 @@
<span class="n">acc_top1</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">accuracy</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">softmax_out</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="n">label</span><span class="p">,</span> <span class="n">k</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
<span class="n">acc_top5</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">accuracy</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">softmax_out</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="n">label</span><span class="p">,</span> <span class="n">k</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span>
<span class="n">test_program</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">default_main_program</span><span class="p">()</span><span class="o">.</span><span class="n">clone</span><span class="p">(</span><span class="n">for_test</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="n">optimizer</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">optimizer</span><span class="o">.</span><span class="n">Adam</span><span class="p">(</span><span class="n">learning_rate</span><span class="o">=</span><span class="mf">0.1</span><span class="p">)</span>
<span class="n">optimizer</span><span class="o">.</span><span class="n">minimize</span><span class="p">(</span><span class="n">avg_cost</span><span class="p">)</span>
......@@ -227,8 +227,8 @@
</pre></div>
</div>
</div>
<div class="section" id="id4">
<h2>4. 定义输入数据函数<a class="headerlink" href="#id4" title="永久链接至标题"></a></h2>
<div class="section" id="id5">
<h2>4. 定义输入数据函数<a class="headerlink" href="#id5" title="永久链接至标题"></a></h2>
<p>使用的数据集为cifar10,paddle框架中<code class="docutils literal"><span class="pre">paddle.dataset.cifar</span></code>包括了cifar数据集的下载和读取,代码如下:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">input_data</span><span class="p">(</span><span class="n">inputs</span><span class="p">):</span>
<span class="n">train_reader</span> <span class="o">=</span> <span class="n">paddle</span><span class="o">.</span><span class="n">batch</span><span class="p">(</span><span class="n">paddle</span><span class="o">.</span><span class="n">reader</span><span class="o">.</span><span class="n">shuffle</span><span class="p">(</span><span class="n">paddle</span><span class="o">.</span><span class="n">dataset</span><span class="o">.</span><span class="n">cifar</span><span class="o">.</span><span class="n">train10</span><span class="p">(</span><span class="n">cycle</span><span class="o">=</span><span class="kc">False</span><span class="p">),</span> <span class="n">buf_size</span><span class="o">=</span><span class="mi">1024</span><span class="p">),</span><span class="n">batch_size</span><span class="o">=</span><span class="mi">256</span><span class="p">)</span>
......@@ -239,10 +239,10 @@
</pre></div>
</div>
</div>
<div class="section" id="id5">
<h2>5. 定义训练函数<a class="headerlink" href="#id5" title="永久链接至标题"></a></h2>
<div class="section" id="id6">
<h2>5. 定义训练函数<a class="headerlink" href="#id6" title="永久链接至标题"></a></h2>
<p>根据训练program和训练数据进行训练。</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">start_train</span><span class="p">(</span><span class="n">program</span><span class="p">,</span> <span class="n">data_reader</span><span class="p">,</span> <span class="n">data_feeder</span><span class="p">):</span>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">start_train</span><span class="p">(</span><span class="n">program</span><span class="p">,</span> <span class="n">data_reader</span><span class="p">,</span> <span class="n">data_feeder</span><span class="p">):</span>
<span class="n">outputs</span> <span class="o">=</span> <span class="p">[</span><span class="n">avg_cost</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">acc_top1</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">acc_top5</span><span class="o">.</span><span class="n">name</span><span class="p">]</span>
<span class="k">for</span> <span class="n">data</span> <span class="ow">in</span> <span class="n">data_reader</span><span class="p">():</span>
<span class="n">batch_reward</span> <span class="o">=</span> <span class="n">exe</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="n">program</span><span class="p">,</span> <span class="n">feed</span><span class="o">=</span><span class="n">data_feeder</span><span class="o">.</span><span class="n">feed</span><span class="p">(</span><span class="n">data</span><span class="p">),</span> <span class="n">fetch_list</span> <span class="o">=</span> <span class="n">outputs</span><span class="p">)</span>
......@@ -250,8 +250,8 @@
</pre></div>
</div>
</div>
<div class="section" id="id6">
<h2>6. 定义评估函数<a class="headerlink" href="#id6" title="永久链接至标题"></a></h2>
<div class="section" id="id7">
<h2>6. 定义评估函数<a class="headerlink" href="#id7" title="永久链接至标题"></a></h2>
<p>根据评估program和评估数据进行评估。</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">start_eval</span><span class="p">(</span><span class="n">program</span><span class="p">,</span> <span class="n">data_reader</span><span class="p">,</span> <span class="n">data_feeder</span><span class="p">):</span>
<span class="n">reward</span> <span class="o">=</span> <span class="p">[]</span>
......@@ -267,11 +267,11 @@
</pre></div>
</div>
</div>
<div class="section" id="id7">
<h2>7. 启动搜索实验<a class="headerlink" href="#id7" title="永久链接至标题"></a></h2>
<p>以下步骤拆解说明了如何获得当前模型结构以及获得当前模型结构之后应该有的步骤,如果想要看如何启动搜索实验的完整示例可以看步骤9。</p>
<div class="section" id="id8">
<h3>7.1 获取模型结构<a class="headerlink" href="#id8" title="永久链接至标题"></a></h3>
<h2>7. 启动搜索实验<a class="headerlink" href="#id8" title="永久链接至标题"></a></h2>
<p>以下步骤拆解说明了如何获得当前模型结构以及获得当前模型结构之后应该有的步骤,如果想要看如何启动搜索实验的完整示例可以看步骤9。</p>
<div class="section" id="id9">
<h3>7.1 获取模型结构<a class="headerlink" href="#id9" title="永久链接至标题"></a></h3>
<p>调用<code class="docutils literal"><span class="pre">next_archs()</span></code>函数获取到下一个模型结构。</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">archs</span> <span class="o">=</span> <span class="n">sanas</span><span class="o">.</span><span class="n">next_archs</span><span class="p">()[</span><span class="mi">0</span><span class="p">]</span>
</pre></div>
......@@ -284,35 +284,35 @@
</pre></div>
</div>
</div>
<div class="section" id="id9">
<h3>7.3 定义输入数据<a class="headerlink" href="#id9" title="永久链接至标题"></a></h3>
<div class="section" id="id10">
<h3>7.3 定义输入数据<a class="headerlink" href="#id10" title="永久链接至标题"></a></h3>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">train_reader</span><span class="p">,</span> <span class="n">train_feeder</span><span class="p">,</span> <span class="n">eval_reader</span><span class="p">,</span> <span class="n">eval_feeder</span> <span class="o">=</span> <span class="n">input_data</span><span class="p">(</span><span class="n">inputs</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="id10">
<h3>7.4 训练模型<a class="headerlink" href="#id10" title="永久链接至标题"></a></h3>
<div class="section" id="id11">
<h3>7.4 训练模型<a class="headerlink" href="#id11" title="永久链接至标题"></a></h3>
<p>根据上面得到的训练program和评估数据启动训练。</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">start_train</span><span class="p">(</span><span class="n">train_program</span><span class="p">,</span> <span class="n">train_reader</span><span class="p">,</span> <span class="n">train_feeder</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="id11">
<h3>7.5 评估模型<a class="headerlink" href="#id11" title="永久链接至标题"></a></h3>
<div class="section" id="id12">
<h3>7.5 评估模型<a class="headerlink" href="#id12" title="永久链接至标题"></a></h3>
<p>根据上面得到的评估program和评估数据启动评估。</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">finally_reward</span> <span class="o">=</span> <span class="n">start_eval</span><span class="p">(</span><span class="n">eval_program</span><span class="p">,</span> <span class="n">eval_reader</span><span class="p">,</span> <span class="n">eval_feeder</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="id12">
<h3>7.6 回传当前模型的得分<a class="headerlink" href="#id12" title="永久链接至标题"></a></h3>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">sanas</span><span class="o">.</span><span class="n">reward</span><span class="p">(</span><span class="nb">float</span><span class="p">(</span><span class="n">finally_reward</span><span class="p">[</span><span class="mi">1</span><span class="p">]))</span>
<div class="section" id="id13">
<h3>7.6 回传当前模型的得分<a class="headerlink" href="#id13" title="永久链接至标题"></a></h3>
<div class="highlight-guess"><div class="highlight"><pre><span></span><span class="err">sanas.reward(float(finally_reward[1]))</span>
</pre></div>
</div>
</div>
</div>
<div class="section" id="id13">
<h2>8. 完整示例<a class="headerlink" href="#id13" title="永久链接至标题"></a></h2>
<div class="section" id="id14">
<h2>8. 完整示例<a class="headerlink" href="#id14" title="永久链接至标题"></a></h2>
<p>以下是一个完整的搜索实验示例,示例中使用FLOPs作为约束条件,搜索实验一共搜索3个step,表示搜索到3个满足条件的模型结构进行训练,每搜索到一个网络结构训练7个epoch。</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="k">for</span> <span class="n">step</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">3</span><span class="p">):</span>
<span class="n">archs</span> <span class="o">=</span> <span class="n">sanas</span><span class="o">.</span><span class="n">next_archs</span><span class="p">()[</span><span class="mi">0</span><span class="p">]</span>
......@@ -322,7 +322,7 @@
<span class="n">current_flops</span> <span class="o">=</span> <span class="n">slim</span><span class="o">.</span><span class="n">analysis</span><span class="o">.</span><span class="n">flops</span><span class="p">(</span><span class="n">train_program</span><span class="p">)</span>
<span class="k">if</span> <span class="n">current_flops</span> <span class="o">&gt;</span> <span class="mi">321208544</span><span class="p">:</span>
<span class="k">continue</span>
<span class="k">for</span> <span class="n">epoch</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">7</span><span class="p">):</span>
<span class="n">start_train</span><span class="p">(</span><span class="n">train_program</span><span class="p">,</span> <span class="n">train_reader</span><span class="p">,</span> <span class="n">train_feeder</span><span class="p">)</span>
......
......@@ -161,8 +161,8 @@
<div class="section" id="nerual-architecture-search-for-image-classification">
<h1>Nerual Architecture Search for Image Classification<a class="headerlink" href="#nerual-architecture-search-for-image-classification" title="Permalink to this headline"></a></h1>
<p>This tutorial shows how to use <a class="reference external" href="../api/nas_api">API</a> about SANAS in PaddleSlim. We start experiment based on MobileNetV2 as example. The tutorial contains follow section.</p>
<ol class="simple">
<p>This tutorial shows how to use <a class="reference external" href="../api/nas_api.md">API</a> about SANAS in PaddleSlim. We start experiment based on MobileNetV2 as example. The tutorial contains follow section.</p>
<ol class="arabic simple">
<li>necessary imports</li>
<li>initial SANAS instance</li>
<li>define function about building program</li>
......@@ -213,7 +213,7 @@
<span class="n">acc_top1</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">accuracy</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">softmax_out</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="n">label</span><span class="p">,</span> <span class="n">k</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
<span class="n">acc_top5</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">accuracy</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">softmax_out</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="n">label</span><span class="p">,</span> <span class="n">k</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span>
<span class="n">test_program</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">default_main_program</span><span class="p">()</span><span class="o">.</span><span class="n">clone</span><span class="p">(</span><span class="n">for_test</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="n">optimizer</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">optimizer</span><span class="o">.</span><span class="n">Adam</span><span class="p">(</span><span class="n">learning_rate</span><span class="o">=</span><span class="mf">0.1</span><span class="p">)</span>
<span class="n">optimizer</span><span class="o">.</span><span class="n">minimize</span><span class="p">(</span><span class="n">avg_cost</span><span class="p">)</span>
......@@ -239,7 +239,7 @@
<div class="section" id="define-function-about-training">
<h2>5. define function about training<a class="headerlink" href="#define-function-about-training" title="Permalink to this headline"></a></h2>
<p>Start training.</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">start_train</span><span class="p">(</span><span class="n">program</span><span class="p">,</span> <span class="n">data_reader</span><span class="p">,</span> <span class="n">data_feeder</span><span class="p">):</span>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">start_train</span><span class="p">(</span><span class="n">program</span><span class="p">,</span> <span class="n">data_reader</span><span class="p">,</span> <span class="n">data_feeder</span><span class="p">):</span>
<span class="n">outputs</span> <span class="o">=</span> <span class="p">[</span><span class="n">avg_cost</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">acc_top1</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">acc_top5</span><span class="o">.</span><span class="n">name</span><span class="p">]</span>
<span class="k">for</span> <span class="n">data</span> <span class="ow">in</span> <span class="n">data_reader</span><span class="p">():</span>
<span class="n">batch_reward</span> <span class="o">=</span> <span class="n">exe</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="n">program</span><span class="p">,</span> <span class="n">feed</span><span class="o">=</span><span class="n">data_feeder</span><span class="o">.</span><span class="n">feed</span><span class="p">(</span><span class="n">data</span><span class="p">),</span> <span class="n">fetch_list</span> <span class="o">=</span> <span class="n">outputs</span><span class="p">)</span>
......@@ -303,7 +303,7 @@
</div>
<div class="section" id="reture-score">
<h3>7.6 reture score<a class="headerlink" href="#reture-score" title="Permalink to this headline"></a></h3>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">sanas</span><span class="o">.</span><span class="n">reward</span><span class="p">(</span><span class="nb">float</span><span class="p">(</span><span class="n">finally_reward</span><span class="p">[</span><span class="mi">1</span><span class="p">]))</span>
<div class="highlight-guess"><div class="highlight"><pre><span></span><span class="err">sanas.reward(float(finally_reward[1]))</span>
</pre></div>
</div>
</div>
......@@ -319,7 +319,7 @@
<span class="n">current_flops</span> <span class="o">=</span> <span class="n">slim</span><span class="o">.</span><span class="n">analysis</span><span class="o">.</span><span class="n">flops</span><span class="p">(</span><span class="n">train_program</span><span class="p">)</span>
<span class="k">if</span> <span class="n">current_flops</span> <span class="o">&gt;</span> <span class="mi">321208544</span><span class="p">:</span>
<span class="k">continue</span>
<span class="k">for</span> <span class="n">epoch</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">7</span><span class="p">):</span>
<span class="n">start_train</span><span class="p">(</span><span class="n">train_program</span><span class="p">,</span> <span class="n">train_reader</span><span class="p">,</span> <span class="n">train_feeder</span><span class="p">)</span>
......
......@@ -83,7 +83,7 @@
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../index_en.html">English Documents</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intro.html">PaddleSlim简介</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intro.html">介绍</a></li>
<li class="toctree-l1"><a class="reference internal" href="../install.html">安装</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="index.html">快速开始</a><ul class="current">
<li class="toctree-l2 current"><a class="current reference internal" href="#">图像分类模型通道剪裁-快速开始</a><ul>
......@@ -160,9 +160,9 @@
<div class="section" id="id1">
<h1>图像分类模型通道剪裁-快速开始<a class="headerlink" href="#id1" title="永久链接至标题"></a></h1>
<p>该教程以图像分类模型MobileNetV1为例,说明如何快速使用<a class="reference external" href="#">PaddleSlim的卷积通道剪裁接口</a>
<p>该教程以图像分类模型MobileNetV1为例,说明如何快速使用<a href="#id10"><span class="problematic" id="id11">`PaddleSlim的卷积通道剪裁接口 &lt;&gt;`_</span></a>
该示例包含以下步骤:</p>
<ol class="simple">
<ol class="arabic simple">
<li>导入依赖</li>
<li>构建模型</li>
<li>剪裁</li>
......@@ -172,9 +172,9 @@
<div class="section" id="id2">
<h2>1. 导入依赖<a class="headerlink" href="#id2" title="永久链接至标题"></a></h2>
<p>PaddleSlim依赖Paddle1.7版本,请确认已正确安装Paddle,然后按以下方式导入Paddle和PaddleSlim:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">paddle</span>
<span class="kn">import</span> <span class="nn">paddle.fluid</span> <span class="k">as</span> <span class="nn">fluid</span>
<span class="kn">import</span> <span class="nn">paddleslim</span> <span class="k">as</span> <span class="nn">slim</span>
<div class="highlight-guess"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">paddle</span>
<span class="kn">import</span> <span class="nn">paddle.fluid</span> <span class="kn">as</span> <span class="nn">fluid</span>
<span class="kn">import</span> <span class="nn">paddleslim</span> <span class="kn">as</span> <span class="nn">slim</span>
</pre></div>
</div>
</div>
......@@ -182,8 +182,8 @@
<h2>2. 构建网络<a class="headerlink" href="#id3" title="永久链接至标题"></a></h2>
<p>该章节构造一个用于对MNIST数据进行分类的分类模型,选用<code class="docutils literal"><span class="pre">MobileNetV1</span></code>,并将输入大小设置为<code class="docutils literal"><span class="pre">[1,</span> <span class="pre">28,</span> <span class="pre">28]</span></code>,输出类别数为10。
为了方便展示示例,我们在<code class="docutils literal"><span class="pre">paddleslim.models</span></code>下预定义了用于构建分类模型的方法,执行以下代码构建分类模型:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">exe</span><span class="p">,</span> <span class="n">train_program</span><span class="p">,</span> <span class="n">val_program</span><span class="p">,</span> <span class="n">inputs</span><span class="p">,</span> <span class="n">outputs</span> <span class="o">=</span>
<span class="n">slim</span><span class="o">.</span><span class="n">models</span><span class="o">.</span><span class="n">image_classification</span><span class="p">(</span><span class="s2">&quot;MobileNet&quot;</span><span class="p">,</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">28</span><span class="p">,</span> <span class="mi">28</span><span class="p">],</span> <span class="mi">10</span><span class="p">,</span> <span class="n">use_gpu</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<div class="highlight-guess"><div class="highlight"><pre><span></span><span class="err">exe, train_program, val_program, inputs, outputs =</span>
<span class="err"> slim.models.image_classification(&quot;MobileNet&quot;, [1, 28, 28], 10, use_gpu=False)</span>
</pre></div>
</div>
<blockquote>
......@@ -193,8 +193,8 @@
<h2>3. 剪裁卷积层通道<a class="headerlink" href="#id4" title="永久链接至标题"></a></h2>
<div class="section" id="flops">
<h3>3.1 计算剪裁之前的FLOPs<a class="headerlink" href="#flops" title="永久链接至标题"></a></h3>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">FLOPs</span> <span class="o">=</span> <span class="n">slim</span><span class="o">.</span><span class="n">analysis</span><span class="o">.</span><span class="n">flops</span><span class="p">(</span><span class="n">train_program</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;FLOPs: </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">FLOPs</span><span class="p">))</span>
<div class="highlight-guess"><div class="highlight"><pre><span></span><span class="err">FLOPs = slim.analysis.flops(train_program)</span>
<span class="err">print(&quot;FLOPs: {}&quot;.format(FLOPs))</span>
</pre></div>
</div>
</div>
......@@ -202,21 +202,21 @@
<h3>3.2 剪裁<a class="headerlink" href="#id5" title="永久链接至标题"></a></h3>
<p>我们这里对参数名为<code class="docutils literal"><span class="pre">conv2_1_sep_weights</span></code><code class="docutils literal"><span class="pre">conv2_2_sep_weights</span></code>的卷积层进行剪裁,分别剪掉20%和30%的通道数。
代码如下所示:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">pruner</span> <span class="o">=</span> <span class="n">slim</span><span class="o">.</span><span class="n">prune</span><span class="o">.</span><span class="n">Pruner</span><span class="p">()</span>
<span class="n">pruned_program</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="n">_</span> <span class="o">=</span> <span class="n">pruner</span><span class="o">.</span><span class="n">prune</span><span class="p">(</span>
<span class="n">train_program</span><span class="p">,</span>
<span class="n">fluid</span><span class="o">.</span><span class="n">global_scope</span><span class="p">(),</span>
<span class="n">params</span><span class="o">=</span><span class="p">[</span><span class="s2">&quot;conv2_1_sep_weights&quot;</span><span class="p">,</span> <span class="s2">&quot;conv2_2_sep_weights&quot;</span><span class="p">],</span>
<span class="n">ratios</span><span class="o">=</span><span class="p">[</span><span class="mf">0.33</span><span class="p">]</span> <span class="o">*</span> <span class="mi">2</span><span class="p">,</span>
<span class="n">place</span><span class="o">=</span><span class="n">fluid</span><span class="o">.</span><span class="n">CPUPlace</span><span class="p">())</span>
<div class="highlight-guess"><div class="highlight"><pre><span></span><span class="err">pruner = slim.prune.Pruner()</span>
<span class="err">pruned_program, _, _ = pruner.prune(</span>
<span class="err"> train_program,</span>
<span class="err"> fluid.global_scope(),</span>
<span class="err"> params=[&quot;conv2_1_sep_weights&quot;, &quot;conv2_2_sep_weights&quot;],</span>
<span class="err"> ratios=[0.33] * 2,</span>
<span class="err"> place=fluid.CPUPlace())</span>
</pre></div>
</div>
<p>以上操作会修改<code class="docutils literal"><span class="pre">train_program</span></code>中对应卷积层参数的定义,同时对<code class="docutils literal"><span class="pre">fluid.global_scope()</span></code>中存储的参数数组进行裁剪。</p>
</div>
<div class="section" id="id6">
<h3>3.3 计算剪裁之后的FLOPs<a class="headerlink" href="#id6" title="永久链接至标题"></a></h3>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">FLOPs</span> <span class="o">=</span> <span class="n">paddleslim</span><span class="o">.</span><span class="n">analysis</span><span class="o">.</span><span class="n">flops</span><span class="p">(</span><span class="n">train_program</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;FLOPs: </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">FLOPs</span><span class="p">))</span>
<div class="highlight-guess"><div class="highlight"><pre><span></span><span class="err">FLOPs = paddleslim.analysis.flops(train_program)</span>
<span class="err">print(&quot;FLOPs: {}&quot;.format(FLOPs))</span>
</pre></div>
</div>
</div>
......@@ -227,9 +227,9 @@
<h3>4.1 定义输入数据<a class="headerlink" href="#id8" title="永久链接至标题"></a></h3>
<p>为了快速执行该示例,我们选取简单的MNIST数据,Paddle框架的<code class="docutils literal"><span class="pre">paddle.dataset.mnist</span></code>包定义了MNIST数据的下载和读取。
代码如下:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">paddle.dataset.mnist</span> <span class="k">as</span> <span class="nn">reader</span>
<div class="highlight-guess"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">paddle.dataset.mnist</span> <span class="kn">as</span> <span class="nn">reader</span>
<span class="n">train_reader</span> <span class="o">=</span> <span class="n">paddle</span><span class="o">.</span><span class="n">batch</span><span class="p">(</span>
<span class="n">reader</span><span class="o">.</span><span class="n">train</span><span class="p">(),</span> <span class="n">batch_size</span><span class="o">=</span><span class="mi">128</span><span class="p">,</span> <span class="n">drop_last</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="n">reader</span><span class="o">.</span><span class="n">train</span><span class="p">(),</span> <span class="n">batch_size</span><span class="o">=</span><span class="mi">128</span><span class="p">,</span> <span class="n">drop_last</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
<span class="n">train_feeder</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">DataFeeder</span><span class="p">(</span><span class="n">inputs</span><span class="p">,</span> <span class="n">fluid</span><span class="o">.</span><span class="n">CPUPlace</span><span class="p">())</span>
</pre></div>
</div>
......@@ -237,9 +237,9 @@
<div class="section" id="id9">
<h3>4.2 执行训练<a class="headerlink" href="#id9" title="永久链接至标题"></a></h3>
<p>以下代码执行了一个<code class="docutils literal"><span class="pre">epoch</span></code>的训练:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">for</span> <span class="n">data</span> <span class="ow">in</span> <span class="n">train_reader</span><span class="p">():</span>
<span class="n">acc1</span><span class="p">,</span> <span class="n">acc5</span><span class="p">,</span> <span class="n">loss</span> <span class="o">=</span> <span class="n">exe</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="n">pruned_program</span><span class="p">,</span> <span class="n">feed</span><span class="o">=</span><span class="n">train_feeder</span><span class="o">.</span><span class="n">feed</span><span class="p">(</span><span class="n">data</span><span class="p">),</span> <span class="n">fetch_list</span><span class="o">=</span><span class="n">outputs</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="n">acc1</span><span class="p">,</span> <span class="n">acc5</span><span class="p">,</span> <span class="n">loss</span><span class="p">)</span>
<div class="highlight-guess"><div class="highlight"><pre><span></span><span class="err">for data in train_reader():</span>
<span class="err"> acc1, acc5, loss = exe.run(pruned_program, feed=train_feeder.feed(data), fetch_list=outputs)</span>
<span class="err"> print(acc1, acc5, loss)</span>
</pre></div>
</div>
</div>
......
......@@ -160,7 +160,7 @@
<h1>Channel Pruning for Image Classification<a class="headerlink" href="#channel-pruning-for-image-classification" title="Permalink to this headline"></a></h1>
<p>In this tutorial, you will learn how to use channel pruning API of PaddleSlim
by a demo of MobileNetV1 model on MNIST dataset. This tutorial following workflow:</p>
<ol class="simple">
<ol class="arabic simple">
<li>Import dependency</li>
<li>Build model</li>
<li>Prune model</li>
......@@ -169,9 +169,9 @@ by a demo of MobileNetV1 model on MNIST dataset. This tutorial following workflo
<div class="section" id="import-dependency">
<h2>1. Import dependency<a class="headerlink" href="#import-dependency" title="Permalink to this headline"></a></h2>
<p>PaddleSlim dependents on Paddle1.7. Please ensure that you have installed paddle correctly. Import Paddle and PaddleSlim as below:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">paddle</span>
<span class="kn">import</span> <span class="nn">paddle.fluid</span> <span class="k">as</span> <span class="nn">fluid</span>
<span class="kn">import</span> <span class="nn">paddleslim</span> <span class="k">as</span> <span class="nn">slim</span>
<div class="highlight-guess"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">paddle</span>
<span class="kn">import</span> <span class="nn">paddle.fluid</span> <span class="kn">as</span> <span class="nn">fluid</span>
<span class="kn">import</span> <span class="nn">paddleslim</span> <span class="kn">as</span> <span class="nn">slim</span>
</pre></div>
</div>
</div>
......@@ -180,8 +180,8 @@ by a demo of MobileNetV1 model on MNIST dataset. This tutorial following workflo
<p>This section will build a classsification model based <code class="docutils literal"><span class="pre">MobileNetV1</span></code> for MNIST task. The shape of the input is <code class="docutils literal"><span class="pre">[1,</span> <span class="pre">28,</span> <span class="pre">28]</span></code> and the output number is 10.</p>
<p>To make the code simple, we define a function in package <code class="docutils literal"><span class="pre">paddleslim.models</span></code> to build classification model.
Excute following code to build a model,</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">exe</span><span class="p">,</span> <span class="n">train_program</span><span class="p">,</span> <span class="n">val_program</span><span class="p">,</span> <span class="n">inputs</span><span class="p">,</span> <span class="n">outputs</span> <span class="o">=</span>
<span class="n">slim</span><span class="o">.</span><span class="n">models</span><span class="o">.</span><span class="n">image_classification</span><span class="p">(</span><span class="s2">&quot;MobileNet&quot;</span><span class="p">,</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">28</span><span class="p">,</span> <span class="mi">28</span><span class="p">],</span> <span class="mi">10</span><span class="p">,</span> <span class="n">use_gpu</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<div class="highlight-guess"><div class="highlight"><pre><span></span><span class="err">exe, train_program, val_program, inputs, outputs =</span>
<span class="err"> slim.models.image_classification(&quot;MobileNet&quot;, [1, 28, 28], 10, use_gpu=False)</span>
</pre></div>
</div>
<blockquote>
......@@ -191,29 +191,29 @@ Excute following code to build a model,</p>
<h2>3. Prune model<a class="headerlink" href="#prune-model" title="Permalink to this headline"></a></h2>
<div class="section" id="compute-flops-bofore-pruning">
<h3>3.1 Compute FLOPs bofore pruning<a class="headerlink" href="#compute-flops-bofore-pruning" title="Permalink to this headline"></a></h3>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">FLOPs</span> <span class="o">=</span> <span class="n">slim</span><span class="o">.</span><span class="n">analysis</span><span class="o">.</span><span class="n">flops</span><span class="p">(</span><span class="n">train_program</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;FLOPs: </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">FLOPs</span><span class="p">))</span>
<div class="highlight-guess"><div class="highlight"><pre><span></span><span class="err">FLOPs = slim.analysis.flops(train_program)</span>
<span class="err">print(&quot;FLOPs: {}&quot;.format(FLOPs))</span>
</pre></div>
</div>
</div>
<div class="section" id="pruning">
<h3>3.2 Pruning<a class="headerlink" href="#pruning" title="Permalink to this headline"></a></h3>
<p>The section will prune the parameters named <code class="docutils literal"><span class="pre">conv2_1_sep_weights</span></code> and <code class="docutils literal"><span class="pre">conv2_2_sep_weights</span></code> by 20% and 30%.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">pruner</span> <span class="o">=</span> <span class="n">slim</span><span class="o">.</span><span class="n">prune</span><span class="o">.</span><span class="n">Pruner</span><span class="p">()</span>
<span class="n">pruned_program</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="n">_</span> <span class="o">=</span> <span class="n">pruner</span><span class="o">.</span><span class="n">prune</span><span class="p">(</span>
<span class="n">train_program</span><span class="p">,</span>
<span class="n">fluid</span><span class="o">.</span><span class="n">global_scope</span><span class="p">(),</span>
<span class="n">params</span><span class="o">=</span><span class="p">[</span><span class="s2">&quot;conv2_1_sep_weights&quot;</span><span class="p">,</span> <span class="s2">&quot;conv2_2_sep_weights&quot;</span><span class="p">],</span>
<span class="n">ratios</span><span class="o">=</span><span class="p">[</span><span class="mf">0.33</span><span class="p">]</span> <span class="o">*</span> <span class="mi">2</span><span class="p">,</span>
<span class="n">place</span><span class="o">=</span><span class="n">fluid</span><span class="o">.</span><span class="n">CPUPlace</span><span class="p">())</span>
<div class="highlight-guess"><div class="highlight"><pre><span></span><span class="err">pruner = slim.prune.Pruner()</span>
<span class="err">pruned_program, _, _ = pruner.prune(</span>
<span class="err"> train_program,</span>
<span class="err"> fluid.global_scope(),</span>
<span class="err"> params=[&quot;conv2_1_sep_weights&quot;, &quot;conv2_2_sep_weights&quot;],</span>
<span class="err"> ratios=[0.33] * 2,</span>
<span class="err"> place=fluid.CPUPlace())</span>
</pre></div>
</div>
<p>It will change the shapes of parameters defined in <code class="docutils literal"><span class="pre">train_program</span></code>. And the parameters<code class="docutils literal"><span class="pre">values</span> <span class="pre">stored</span> <span class="pre">in</span></code>fluid.global_scope()` will be pruned.</p>
</div>
<div class="section" id="compute-flops-after-pruning">
<h3>3.3 Compute FLOPs after pruning<a class="headerlink" href="#compute-flops-after-pruning" title="Permalink to this headline"></a></h3>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">FLOPs</span> <span class="o">=</span> <span class="n">paddleslim</span><span class="o">.</span><span class="n">analysis</span><span class="o">.</span><span class="n">flops</span><span class="p">(</span><span class="n">train_program</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;FLOPs: </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">FLOPs</span><span class="p">))</span>
<div class="highlight-guess"><div class="highlight"><pre><span></span><span class="err">FLOPs = paddleslim.analysis.flops(train_program)</span>
<span class="err">print(&quot;FLOPs: {}&quot;.format(FLOPs))</span>
</pre></div>
</div>
</div>
......@@ -224,9 +224,9 @@ Excute following code to build a model,</p>
<h3>4.1 Define dataset<a class="headerlink" href="#define-dataset" title="Permalink to this headline"></a></h3>
<p>To make you easily run this demo, it will training on MNIST dataset. The package <code class="docutils literal"><span class="pre">paddle.dataset.mnist</span></code> of Paddle defines the downloading and reading of MNIST dataset.
Define training data reader and test data reader as below:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">paddle.dataset.mnist</span> <span class="k">as</span> <span class="nn">reader</span>
<div class="highlight-guess"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">paddle.dataset.mnist</span> <span class="kn">as</span> <span class="nn">reader</span>
<span class="n">train_reader</span> <span class="o">=</span> <span class="n">paddle</span><span class="o">.</span><span class="n">batch</span><span class="p">(</span>
<span class="n">reader</span><span class="o">.</span><span class="n">train</span><span class="p">(),</span> <span class="n">batch_size</span><span class="o">=</span><span class="mi">128</span><span class="p">,</span> <span class="n">drop_last</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="n">reader</span><span class="o">.</span><span class="n">train</span><span class="p">(),</span> <span class="n">batch_size</span><span class="o">=</span><span class="mi">128</span><span class="p">,</span> <span class="n">drop_last</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
<span class="n">train_feeder</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">DataFeeder</span><span class="p">(</span><span class="n">inputs</span><span class="p">,</span> <span class="n">fluid</span><span class="o">.</span><span class="n">CPUPlace</span><span class="p">())</span>
</pre></div>
</div>
......@@ -234,9 +234,9 @@ Define training data reader and test data reader as below:</p>
<div class="section" id="training">
<h3>4.2 Training<a class="headerlink" href="#training" title="Permalink to this headline"></a></h3>
<p>Excute following code to run an <code class="docutils literal"><span class="pre">epoch</span></code> training:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">for</span> <span class="n">data</span> <span class="ow">in</span> <span class="n">train_reader</span><span class="p">():</span>
<span class="n">acc1</span><span class="p">,</span> <span class="n">acc5</span><span class="p">,</span> <span class="n">loss</span> <span class="o">=</span> <span class="n">exe</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="n">pruned_program</span><span class="p">,</span> <span class="n">feed</span><span class="o">=</span><span class="n">train_feeder</span><span class="o">.</span><span class="n">feed</span><span class="p">(</span><span class="n">data</span><span class="p">),</span> <span class="n">fetch_list</span><span class="o">=</span><span class="n">outputs</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="n">acc1</span><span class="p">,</span> <span class="n">acc5</span><span class="p">,</span> <span class="n">loss</span><span class="p">)</span>
<div class="highlight-guess"><div class="highlight"><pre><span></span><span class="err">for data in train_reader():</span>
<span class="err"> acc1, acc5, loss = exe.run(pruned_program, feed=train_feeder.feed(data), fetch_list=outputs)</span>
<span class="err"> print(acc1, acc5, loss)</span>
</pre></div>
</div>
</div>
......
......@@ -83,22 +83,22 @@
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../index_en.html">English Documents</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intro.html">PaddleSlim简介</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intro.html">介绍</a></li>
<li class="toctree-l1"><a class="reference internal" href="../install.html">安装</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="index.html">快速开始</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="pruning_tutorial.html">图像分类模型通道剪裁-快速开始</a></li>
<li class="toctree-l2"><a class="reference internal" href="distillation_tutorial.html">图像分类模型知识蒸馏-快速开始</a></li>
<li class="toctree-l2 current"><a class="current reference internal" href="#">图像分类模型量化训练-快速开始</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#id2">1. 导入依赖</a></li>
<li class="toctree-l3"><a class="reference internal" href="#id3">2. 构建网络</a></li>
<li class="toctree-l3"><a class="reference internal" href="#id4">3. 训练模型</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#id5">3.1 定义输入数据</a></li>
<li class="toctree-l4"><a class="reference internal" href="#id6">3.2 训练和测试</a></li>
<li class="toctree-l3"><a class="reference internal" href="#id3">1. 导入依赖</a></li>
<li class="toctree-l3"><a class="reference internal" href="#id4">2. 构建网络</a></li>
<li class="toctree-l3"><a class="reference internal" href="#id5">3. 训练模型</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#id6">3.1 定义输入数据</a></li>
<li class="toctree-l4"><a class="reference internal" href="#id7">3.2 训练和测试</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="#id7">4. 量化</a></li>
<li class="toctree-l3"><a class="reference internal" href="#id8">5. 训练和测试量化后的模型</a></li>
<li class="toctree-l3"><a class="reference internal" href="#id9">6. 保存量化后的模型</a></li>
<li class="toctree-l3"><a class="reference internal" href="#id8">4. 量化</a></li>
<li class="toctree-l3"><a class="reference internal" href="#id10">5. 训练和测试量化后的模型</a></li>
<li class="toctree-l3"><a class="reference internal" href="#id11">6. 保存量化后的模型</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="quant_post_tutorial.html">图像分类模型离线量化-快速开始</a></li>
......@@ -157,8 +157,8 @@
<div class="section" id="id1">
<h1>图像分类模型量化训练-快速开始<a class="headerlink" href="#id1" title="永久链接至标题"></a></h1>
<p>该教程以图像分类模型MobileNetV1为例,说明如何快速使用PaddleSlim的<a class="reference external" href="https://github.com/PaddlePaddle/PaddleSlim/blob/develop/docs/docs/api/quantization_api">量化训练接口</a>。 该示例包含以下步骤:</p>
<ol class="simple">
<p>该教程以图像分类模型MobileNetV1为例,说明如何快速使用PaddleSlim的<a class="reference external" href="https://github.com/PaddlePaddle/PaddleSlim/blob/develop/docs/docs/api/quantization_api.md">量化训练接口</a>。 该示例包含以下步骤:</p>
<ol class="arabic simple">
<li>导入依赖</li>
<li>构建模型</li>
<li>训练模型</li>
......@@ -166,8 +166,8 @@
<li>训练和测试量化后的模型</li>
<li>保存量化后的模型</li>
</ol>
<div class="section" id="id2">
<h2>1. 导入依赖<a class="headerlink" href="#id2" title="永久链接至标题"></a></h2>
<div class="section" id="id3">
<h2>1. 导入依赖<a class="headerlink" href="#id3" title="永久链接至标题"></a></h2>
<p>PaddleSlim依赖Paddle1.7版本,请确认已正确安装Paddle,然后按以下方式导入Paddle和PaddleSlim:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">paddle</span>
<span class="kn">import</span> <span class="nn">paddle.fluid</span> <span class="k">as</span> <span class="nn">fluid</span>
......@@ -176,8 +176,8 @@
</pre></div>
</div>
</div>
<div class="section" id="id3">
<h2>2. 构建网络<a class="headerlink" href="#id3" title="永久链接至标题"></a></h2>
<div class="section" id="id4">
<h2>2. 构建网络<a class="headerlink" href="#id4" title="永久链接至标题"></a></h2>
<p>该章节构造一个用于对MNIST数据进行分类的分类模型,选用<code class="docutils literal"><span class="pre">MobileNetV1</span></code>,并将输入大小设置为<code class="docutils literal"><span class="pre">[1,</span> <span class="pre">28,</span> <span class="pre">28]</span></code>,输出类别数为10。 为了方便展示示例,我们在<code class="docutils literal"><span class="pre">paddleslim.models</span></code>下预定义了用于构建分类模型的方法,执行以下代码构建分类模型:</p>
<blockquote>
<div>注意:paddleslim.models下的API并非PaddleSlim常规API,是为了简化示例而封装预定义的一系列方法,比如:模型结构的定义、Program的构建等。</div></blockquote>
......@@ -186,11 +186,11 @@
</pre></div>
</div>
</div>
<div class="section" id="id4">
<h2>3. 训练模型<a class="headerlink" href="#id4" title="永久链接至标题"></a></h2>
<p>该章节介绍了如何定义输入数据和如何训练和测试分类模型。先训练分类模型的原因是量化训练过程是在训练好的模型上进行的,也就是说是在训练好的模型的基础上加入量化反量化op之后,用小学习率进行参数微调。</p>
<div class="section" id="id5">
<h3>3.1 定义输入数据<a class="headerlink" href="#id5" title="永久链接至标题"></a></h3>
<h2>3. 训练模型<a class="headerlink" href="#id5" title="永久链接至标题"></a></h2>
<p>该章节介绍了如何定义输入数据和如何训练和测试分类模型。先训练分类模型的原因是量化训练过程是在训练好的模型上进行的,也就是说是在训练好的模型的基础上加入量化反量化op之后,用小学习率进行参数微调。</p>
<div class="section" id="id6">
<h3>3.1 定义输入数据<a class="headerlink" href="#id6" title="永久链接至标题"></a></h3>
<p>为了快速执行该示例,我们选取简单的MNIST数据,Paddle框架的<code class="docutils literal"><span class="pre">paddle.dataset.mnist</span></code>包定义了MNIST数据的下载和读取。
代码如下:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">paddle.dataset.mnist</span> <span class="k">as</span> <span class="nn">reader</span>
......@@ -202,8 +202,8 @@
</pre></div>
</div>
</div>
<div class="section" id="id6">
<h3>3.2 训练和测试<a class="headerlink" href="#id6" title="永久链接至标题"></a></h3>
<div class="section" id="id7">
<h3>3.2 训练和测试<a class="headerlink" href="#id7" title="永久链接至标题"></a></h3>
<p>先定义训练和测试函数,正常训练和量化训练时只需要调用函数即可。在训练函数中执行了一个epoch的训练,因为MNIST数据集数据较少,一个epoch就可将top1精度训练到95%以上。</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">train</span><span class="p">(</span><span class="n">prog</span><span class="p">):</span>
<span class="nb">iter</span> <span class="o">=</span> <span class="mi">0</span>
......@@ -212,7 +212,7 @@
<span class="k">if</span> <span class="nb">iter</span> <span class="o">%</span> <span class="mi">100</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;train iter=</span><span class="si">{}</span><span class="s1">, top1=</span><span class="si">{}</span><span class="s1">, top5=</span><span class="si">{}</span><span class="s1">, loss=</span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">iter</span><span class="p">,</span> <span class="n">acc1</span><span class="o">.</span><span class="n">mean</span><span class="p">(),</span> <span class="n">acc5</span><span class="o">.</span><span class="n">mean</span><span class="p">(),</span> <span class="n">loss</span><span class="o">.</span><span class="n">mean</span><span class="p">()))</span>
<span class="nb">iter</span> <span class="o">+=</span> <span class="mi">1</span>
<span class="k">def</span> <span class="nf">test</span><span class="p">(</span><span class="n">prog</span><span class="p">):</span>
<span class="nb">iter</span> <span class="o">=</span> <span class="mi">0</span>
<span class="n">res</span> <span class="o">=</span> <span class="p">[[],</span> <span class="p">[]]</span>
......@@ -236,16 +236,16 @@
</div>
</div>
</div>
<div class="section" id="id7">
<h2>4. 量化<a class="headerlink" href="#id7" title="永久链接至标题"></a></h2>
<div class="section" id="id8">
<h2>4. 量化<a class="headerlink" href="#id8" title="永久链接至标题"></a></h2>
<p>按照<a class="reference external" href="https://paddlepaddle.github.io/PaddleSlim/api/quantization_api/#_1">默认配置</a><code class="docutils literal"><span class="pre">train_program</span></code><code class="docutils literal"><span class="pre">val_program</span></code>中加入量化和反量化op.</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">quant_program</span> <span class="o">=</span> <span class="n">slim</span><span class="o">.</span><span class="n">quant</span><span class="o">.</span><span class="n">quant_aware</span><span class="p">(</span><span class="n">train_program</span><span class="p">,</span> <span class="n">exe</span><span class="o">.</span><span class="n">place</span><span class="p">,</span> <span class="n">for_test</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="n">val_quant_program</span> <span class="o">=</span> <span class="n">slim</span><span class="o">.</span><span class="n">quant</span><span class="o">.</span><span class="n">quant_aware</span><span class="p">(</span><span class="n">val_program</span><span class="p">,</span> <span class="n">exe</span><span class="o">.</span><span class="n">place</span><span class="p">,</span> <span class="n">for_test</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="id8">
<h2>5. 训练和测试量化后的模型<a class="headerlink" href="#id8" title="永久链接至标题"></a></h2>
<div class="section" id="id10">
<h2>5. 训练和测试量化后的模型<a class="headerlink" href="#id10" title="永久链接至标题"></a></h2>
<p>微调量化后的模型,训练一个epoch后测试。</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">train</span><span class="p">(</span><span class="n">quant_program</span><span class="p">)</span>
</pre></div>
......@@ -255,8 +255,8 @@
</pre></div>
</div>
</div>
<div class="section" id="id9">
<h2>6. 保存量化后的模型<a class="headerlink" href="#id9" title="永久链接至标题"></a></h2>
<div class="section" id="id11">
<h2>6. 保存量化后的模型<a class="headerlink" href="#id11" title="永久链接至标题"></a></h2>
<p><code class="docutils literal"><span class="pre">4.</span> <span class="pre">量化</span></code>中使用接口<code class="docutils literal"><span class="pre">slim.quant.quant_aware</span></code>接口得到的模型只适合训练时使用,为了得到最终使用时的模型,需要使用<a class="reference external" href="https://paddlepaddle.github.io/PaddleSlim/api/quantization_api/#convert">slim.quant.convert</a>接口,然后使用<a class="reference external" href="https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api_cn/io_cn/save_inference_model_cn.html#save-inference-model">fluid.io.save_inference_model</a>保存模型。<code class="docutils literal"><span class="pre">float_prog</span></code>的参数数据类型是float32,但是数据范围是int8, 保存之后可使用fluid或者paddle-lite加载使用,paddle-lite在使用时,会先将类型转换为int8。<code class="docutils literal"><span class="pre">int8_prog</span></code>的参数数据类型是int8, 保存后可看到量化后模型大小,不可加载使用。</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">float_prog</span><span class="p">,</span> <span class="n">int8_prog</span> <span class="o">=</span> <span class="n">slim</span><span class="o">.</span><span class="n">quant</span><span class="o">.</span><span class="n">convert</span><span class="p">(</span><span class="n">val_quant_program</span><span class="p">,</span> <span class="n">exe</span><span class="o">.</span><span class="n">place</span><span class="p">,</span> <span class="n">save_int8</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="n">target_vars</span> <span class="o">=</span> <span class="p">[</span><span class="n">float_prog</span><span class="o">.</span><span class="n">global_block</span><span class="p">()</span><span class="o">.</span><span class="n">var</span><span class="p">(</span><span class="n">name</span><span class="p">)</span> <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">outputs</span><span class="p">]</span>
......
......@@ -155,8 +155,8 @@
<div class="section" id="training-aware-quantization-of-image-classification-model-quick-start">
<h1>Training-aware Quantization of image classification model - quick start<a class="headerlink" href="#training-aware-quantization-of-image-classification-model-quick-start" title="Permalink to this headline"></a></h1>
<p>This tutorial shows how to do training-aware quantization using <a class="reference external" href="https://github.com/PaddlePaddle/PaddleSlim/blob/develop/docs/docs/api/quantization_api">API</a> in PaddleSlim. We use MobileNetV1 to train image classification model as example. The tutorial contains follow sections:</p>
<ol class="simple">
<p>This tutorial shows how to do training-aware quantization using <a class="reference external" href="https://github.com/PaddlePaddle/PaddleSlim/blob/develop/docs/docs/api/quantization_api.md">API</a> in PaddleSlim. We use MobileNetV1 to train image classification model as example. The tutorial contains follow sections:</p>
<ol class="arabic simple">
<li>Necessary imports</li>
<li>Model architecture</li>
<li>Train normal model</li>
......@@ -176,7 +176,7 @@
</div>
<div class="section" id="model-architecture">
<h2>2. Model architecture<a class="headerlink" href="#model-architecture" title="Permalink to this headline"></a></h2>
<p>The section constructs a classification model, which use <code class="docutils literal"><span class="pre">MobileNetV1</span></code> and MNIST dataset. The model&#8216;s input size is <code class="docutils literal"><span class="pre">[1,</span> <span class="pre">28,</span> <span class="pre">28]</span></code> and output size is 10. In order to show tutorial conveniently, we pre-defined a method to get image classification model in <code class="docutils literal"><span class="pre">paddleslim.models</span></code>.</p>
<p>The section constructs a classification model, which use <code class="docutils literal"><span class="pre">MobileNetV1</span></code> and MNIST dataset. The model&#8217;s input size is <code class="docutils literal"><span class="pre">[1,</span> <span class="pre">28,</span> <span class="pre">28]</span></code> and output size is 10. In order to show tutorial conveniently, we pre-defined a method to get image classification model in <code class="docutils literal"><span class="pre">paddleslim.models</span></code>.</p>
<blockquote>
<div>note: The APIs in <code class="docutils literal"><span class="pre">paddleslim.models</span></code> are not formal inferface in PaddleSlim. They are defined to simplify the tutorial such as the definition of model structure and the construction of Program.</div></blockquote>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">exe</span><span class="p">,</span> <span class="n">train_program</span><span class="p">,</span> <span class="n">val_program</span><span class="p">,</span> <span class="n">inputs</span><span class="p">,</span> <span class="n">outputs</span> <span class="o">=</span> \
......@@ -186,7 +186,7 @@
</div>
<div class="section" id="train-normal-model">
<h2>3. Train normal model<a class="headerlink" href="#train-normal-model" title="Permalink to this headline"></a></h2>
<p>The section shows how to define model inputs, train and test model. The reason for training the normal image classification model first is that the quantization model&#8216;s training process is performed on the well-trained model. We add quantization and dequantization operators in well-trained model and finetune using smaller learning rate.</p>
<p>The section shows how to define model inputs, train and test model. The reason for training the normal image classification model first is that the quantization model&#8217;s training process is performed on the well-trained model. We add quantization and dequantization operators in well-trained model and finetune using smaller learning rate.</p>
<div class="section" id="input-data-definition">
<h3>3.1 input data definition<a class="headerlink" href="#input-data-definition" title="Permalink to this headline"></a></h3>
<p>To speed up training process, we select MNIST dataset to train image classification model. The API <code class="docutils literal"><span class="pre">paddle.dataset.mnist</span></code> in Paddle framework contains downloading and reading the images in dataset.</p>
......@@ -254,7 +254,7 @@
</div>
<div class="section" id="save-model-after-quantization">
<h2>6. Save model after quantization<a class="headerlink" href="#save-model-after-quantization" title="Permalink to this headline"></a></h2>
<p>The model in <code class="docutils literal"><span class="pre">4.</span> <span class="pre">Quantization</span></code> after calling <code class="docutils literal"><span class="pre">slim.quant.quant_aware</span></code> API is only suitable to train. To get the inference model, we should use <a class="reference external" href="https://paddlepaddle.github.io/PaddleSlim/api/quantization_api/#convert">slim.quant.convert</a> API to change model architecture and use <a class="reference external" href="https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api_cn/io_cn/save_inference_model_cn.html#save-inference-model">fluid.io.save_inference_model</a> to save model. <code class="docutils literal"><span class="pre">float_prog</span></code>&#8216;s parameters are float32 dtype but in int8&#8216;s range which can be used in <code class="docutils literal"><span class="pre">fluid</span></code> or <code class="docutils literal"><span class="pre">paddle-lite</span></code>. <code class="docutils literal"><span class="pre">paddle-lite</span></code> will change the parameters&#8216; dtype from float32 to int8 first when loading the inference model. <code class="docutils literal"><span class="pre">int8_prog</span></code>&#8216;s parameters are int8 dtype and we can get model size after quantization by saving it. <code class="docutils literal"><span class="pre">int8_prog</span></code> cannot be used in <code class="docutils literal"><span class="pre">fluid</span></code> or <code class="docutils literal"><span class="pre">paddle-lite</span></code>.</p>
<p>The model in <code class="docutils literal"><span class="pre">4.</span> <span class="pre">Quantization</span></code> after calling <code class="docutils literal"><span class="pre">slim.quant.quant_aware</span></code> API is only suitable to train. To get the inference model, we should use <a class="reference external" href="https://paddlepaddle.github.io/PaddleSlim/api/quantization_api/#convert">slim.quant.convert</a> API to change model architecture and use <a class="reference external" href="https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api_cn/io_cn/save_inference_model_cn.html#save-inference-model">fluid.io.save_inference_model</a> to save model. <code class="docutils literal"><span class="pre">float_prog</span></code>&#8216;s parameters are float32 dtype but in int8&#8217;s range which can be used in <code class="docutils literal"><span class="pre">fluid</span></code> or <code class="docutils literal"><span class="pre">paddle-lite</span></code>. <code class="docutils literal"><span class="pre">paddle-lite</span></code> will change the parameters&#8217; dtype from float32 to int8 first when loading the inference model. <code class="docutils literal"><span class="pre">int8_prog</span></code>&#8216;s parameters are int8 dtype and we can get model size after quantization by saving it. <code class="docutils literal"><span class="pre">int8_prog</span></code> cannot be used in <code class="docutils literal"><span class="pre">fluid</span></code> or <code class="docutils literal"><span class="pre">paddle-lite</span></code>.</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">float_prog</span><span class="p">,</span> <span class="n">int8_prog</span> <span class="o">=</span> <span class="n">slim</span><span class="o">.</span><span class="n">quant</span><span class="o">.</span><span class="n">convert</span><span class="p">(</span><span class="n">val_quant_program</span><span class="p">,</span> <span class="n">exe</span><span class="o">.</span><span class="n">place</span><span class="p">,</span> <span class="n">save_int8</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="n">target_vars</span> <span class="o">=</span> <span class="p">[</span><span class="n">float_prog</span><span class="o">.</span><span class="n">global_block</span><span class="p">()</span><span class="o">.</span><span class="n">var</span><span class="p">(</span><span class="n">name</span><span class="p">)</span> <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">outputs</span><span class="p">]</span>
<span class="n">fluid</span><span class="o">.</span><span class="n">io</span><span class="o">.</span><span class="n">save_inference_model</span><span class="p">(</span><span class="n">dirname</span><span class="o">=</span><span class="s1">&#39;./inference_model/float&#39;</span><span class="p">,</span>
......
......@@ -153,8 +153,8 @@
<div class="section" id="post-training-quantization-of-image-classification-model-quick-start">
<h1>Post-training Quantization of image classification model - quick start<a class="headerlink" href="#post-training-quantization-of-image-classification-model-quick-start" title="Permalink to this headline"></a></h1>
<p>This tutorial shows how to do post training quantization using <a class="reference external" href="https://github.com/PaddlePaddle/PaddleSlim/blob/develop/docs/docs/api/quantization_api">API</a> in PaddleSlim. We use MobileNetV1 to train image classification model as example. The tutorial contains follow sections:</p>
<ol class="simple">
<p>This tutorial shows how to do post training quantization using <a class="reference external" href="https://github.com/PaddlePaddle/PaddleSlim/blob/develop/docs/docs/api/quantization_api.md">API</a> in PaddleSlim. We use MobileNetV1 to train image classification model as example. The tutorial contains follow sections:</p>
<ol class="arabic simple">
<li>Necessary imports</li>
<li>Model architecture</li>
<li>Train normal model</li>
......@@ -172,7 +172,7 @@
</div>
<div class="section" id="model-architecture">
<h2>2. Model architecture<a class="headerlink" href="#model-architecture" title="Permalink to this headline"></a></h2>
<p>The section constructs a classification model, which use <code class="docutils literal"><span class="pre">MobileNetV1</span></code> and MNIST dataset. The model&#8216;s input size is <code class="docutils literal"><span class="pre">[1,</span> <span class="pre">28,</span> <span class="pre">28]</span></code> and output size is 10. In order to show tutorial conveniently, we pre-defined a method to get image classification model in <code class="docutils literal"><span class="pre">paddleslim.models</span></code>.</p>
<p>The section constructs a classification model, which use <code class="docutils literal"><span class="pre">MobileNetV1</span></code> and MNIST dataset. The model&#8217;s input size is <code class="docutils literal"><span class="pre">[1,</span> <span class="pre">28,</span> <span class="pre">28]</span></code> and output size is 10. In order to show tutorial conveniently, we pre-defined a method to get image classification model in <code class="docutils literal"><span class="pre">paddleslim.models</span></code>.</p>
<blockquote>
<div>note: The APIs in <code class="docutils literal"><span class="pre">paddleslim.models</span></code> are not formal inferface in PaddleSlim. They are defined to simplify the tutorial such as the definition of model structure and the construction of Program.</div></blockquote>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">exe</span><span class="p">,</span> <span class="n">train_program</span><span class="p">,</span> <span class="n">val_program</span><span class="p">,</span> <span class="n">inputs</span><span class="p">,</span> <span class="n">outputs</span> <span class="o">=</span> \
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
......@@ -80,7 +80,7 @@
<ul>
<li class="toctree-l1"><a class="reference internal" href="../index_en.html">English Documents</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intro.html">PaddleSlim简介</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intro.html">介绍</a></li>
<li class="toctree-l1"><a class="reference internal" href="../install.html">安装</a></li>
<li class="toctree-l1"><a class="reference internal" href="../quick_start/index.html">快速开始</a></li>
<li class="toctree-l1"><a class="reference internal" href="index.html">进阶教程</a></li>
......@@ -135,7 +135,7 @@
<h1>图像分类模型通道剪裁-敏感度分析<a class="headerlink" href="#id1" title="永久链接至标题"></a></h1>
<p>该教程以图像分类模型MobileNetV1为例,说明如何快速使用<a class="reference external" href="https://paddlepaddle.github.io/PaddleSlim/api/prune_api/#sensitivity">PaddleSlim的敏感度分析接口</a>
该示例包含以下步骤:</p>
<ol class="simple">
<ol class="arabic simple">
<li>导入依赖</li>
<li>构建模型</li>
<li>定义输入数据</li>
......@@ -149,9 +149,9 @@
<div class="section" id="id2">
<h2>1. 导入依赖<a class="headerlink" href="#id2" title="永久链接至标题"></a></h2>
<p>PaddleSlim依赖Paddle1.7版本,请确认已正确安装Paddle,然后按以下方式导入Paddle和PaddleSlim:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">paddle</span>
<span class="kn">import</span> <span class="nn">paddle.fluid</span> <span class="k">as</span> <span class="nn">fluid</span>
<span class="kn">import</span> <span class="nn">paddleslim</span> <span class="k">as</span> <span class="nn">slim</span>
<div class="highlight-guess"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">paddle</span>
<span class="kn">import</span> <span class="nn">paddle.fluid</span> <span class="kn">as</span> <span class="nn">fluid</span>
<span class="kn">import</span> <span class="nn">paddleslim</span> <span class="kn">as</span> <span class="nn">slim</span>
</pre></div>
</div>
</div>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册