未验证 提交 11c8a8b8 编写于 作者: T Tingquan Gao 提交者: GitHub

add pplcnet pplcnetv2 pphgnet (#5560)

* add pplcnet

* add pplcnetv2

* add pphgnet

* fix

* update

* support gradio for PPLCNet PPLCNetV2 PPHGNet

* fix

* enrich contents

* Update benchmark_cn.md

* Update download_cn.md

* Update info.yaml

* Update info.yaml

* add example

* Add modelcenter en

* Add PP-HGNet en

* Add PP-LCNet and PP-LCNetV2 en

* Add modelcenter English

* rename v2 to V2

* fix

* Update info.yaml
Co-authored-by: NliuTINA0907 <65896652+liuTINA0907@users.noreply.github.com>
Co-authored-by: weixin_46524038's avatarzhangyubo0722 <zhangyubo0722@163.com>
上级 24e1be42
import gradio as gr
import numpy as np
from paddleclas import PaddleClas
import cv2 as cv
clas = PaddleClas(model_name='PPHGNet_tiny')
# UGC: Define the inference fn() for your models
def model_inference(image):
result = clas.predict(image)
return next(result)
def clear_all():
return None, None
with gr.Blocks() as demo:
gr.Markdown("Image Classification")
with gr.Column(scale=1, min_width=100):
img_in = gr.Image(
value="https://gitee.com/paddlepaddle/PaddleClas/raw/release/2.5/docs/images/inference_deployment/whl_demo.jpg",
shape=(200, 200),
label="Input").style(height=200)
with gr.Row():
btn1 = gr.Button("Clear")
btn2 = gr.Button("Submit")
prediction_out = gr.Textbox(label="Prediction")
btn1.click(fn=clear_all, inputs=None, outputs=[img_in, prediction_out])
btn2.click(fn=model_inference, inputs=img_in, outputs=[prediction_out])
gr.Button.style(1)
demo.launch()
【PP-HGNet-App-YAML】
APP_Info:
title: PP-HGNet-App
colorFrom: blue
colorTo: yellow
sdk: gradio
sdk_version: 3.4.1
app_file: app.py
license: apache-2.0
device: cpu
gradio
paddlepaddle
paddleclas
\ No newline at end of file
## 1. 训练 Benchmark
PP-HGNet 系列模型的训练 Benchmark 评测流程可以参考 [PaddleClas-TIPC](https://github.com/paddlepaddle/paddleclas/blob/release%2F2.5/test_tipc/docs/benchmark_train.md)
## 2. 推理 Benchmark
### 2.1 软硬件环境
* 下列测试基于 NVIDIA® Tesla® V100 硬件平台,开启 TensorRT 加速;
* 下列测试均基于 FP32 精度完成;
### 2.2 数据集
PP-HGNet 系列模型使用 ImageNet1k validation 数据集进行评测。
### 2.3 指标
| Model | Latency(ms) |
|:--: |:--: |
| PPHGNet_tiny | 1.77 |
| PPHGNet_tiny_ssld | 1.77 |
| PPHGNet_small | 2.52 |
| PPHGNet_small_ssld | 2.52 |
| PPHGNet_base_ssld | 5.97 |
## 3. 相关使用说明
更多信息请参考[PaddleClas-PPHGNet](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.5/docs/zh_CN/models/ImageNet1k/PP-HGNet.md)
## 1. Train Benchmark
PP-HGNet series model training Benchmark evaluation process can be referred to [PaddleClas-TIPC](https://github.com/paddlepaddle/paddleclas/blob/release%2F2.5/test_tipc/docs/benchmark_train.md).
## 2. Inference Benchmark
### 2.1 Environment
* The following tests are based on the NVIDIA® Tesla® V100,and the TensorRT engine is turned on;
* The precision type is FP32;
### 2.2 Dataset
The PP-HGNet series models were evaluated using the ImageNet1k validation dataset.
### 2.3 Metrics
| Model | Latency(ms) |
|:--: |:--: |
| PPHGNet_tiny | 1.77 |
| PPHGNet_tiny_ssld | 1.77 |
| PPHGNet_small | 2.52 |
| PPHGNet_small_ssld | 2.52 |
| PPHGNet_base_ssld | 5.97 |
## 3. Instructions
For more information please refer to[PaddleClas-PPHGNet](https://github.com/PaddlePaddle/PaddleClas/blob/release%2F2.5/docs/en/models/PP-HGNet_en.md).
# 模型列表
|模型名称 | 模型简介 | 输入尺寸 | 下载地址 |
|---|---|---|---|
| PPHGNet_tiny | 图像分类 | 224 | [推理模型](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPHGNet_tiny_infer.tar)/[预训练模型](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/legendary_models/PPHGNet_tiny_pretrained.pdparams) |
| PPHGNet_tiny_ssld | 图像分类 | 224 | [推理模型](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPHGNet_tiny_ssld_infer.tar)/[预训练模型](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/legendary_models/PPHGNet_tiny_ssld_pretrained.pdparams) |
| PPHGNet_small | 图像分类 | 224 | [推理模型](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPHGNet_small_infer.tar)/[预训练模型](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/legendary_models/PPHGNet_small_pretrained.pdparams) |
| PPHGNet_small_ssld | 图像分类 | 224 | [推理模型](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPHGNet_small_ssld_infer.tar)/[预训练模型](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/legendary_models/PPHGNet_small_ssld_pretrained.pdparams) |
| PPHGNet_base_ssld | 图像分类| 224 | [推理模型](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPHGNet_base_ssld_infer.tar)/[预训练模型](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/legendary_models/PPHGNet_base_ssld_pretrained.pdparams) |
# List of Models
|Model | Introduction | Model Size | Input size | Download link |
|---|---|---|---|---|
| PPHGNet_tiny | Image classification | | 224 | [Inference](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPHGNet_tiny_infer.tar)/[Pretrained](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/legendary_models/PPHGNet_tiny_pretrained.pdparams) |
| PPHGNet_tiny_ssld | Image classification | | 224 | [Inference](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPHGNet_tiny_ssld_infer.tar)/[Pretrained](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/legendary_models/PPHGNet_tiny_ssld_pretrained.pdparams) |
| PPHGNet_small | Image classification | | 224 | [Inference](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPHGNet_small_infer.tar)/[Pretrained](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/legendary_models/PPHGNet_small_pretrained.pdparams) |
| PPHGNet_small_ssld | Image classification | | 224 | [Inference](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPHGNet_small_ssld_infer.tar)/[Pretrained](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/legendary_models/PPHGNet_small_ssld_pretrained.pdparams) |
| PPHGNet_base_ssld | Image classification | | 224 | [Inference](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPHGNet_base_ssld_infer.tar)/[Pretrained](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/legendary_models/PPHGNet_base_ssld_pretrained.pdparams) |
---
Model_Info:
name: "PP-HGNet"
description: "面向Nvidia GPU端的高性能卷积神经网络"
description_en: "A High-performance Convolutional Neural Network for Nvidia GPU"
icon: ""
from_repo: "PaddleClas"
Task:
- tag_en: "Computer Vision"
tag: "计算机视觉"
sub_tag_en: "Image Classification"
sub_tag: "图像分类"
Example: ""
Datasets: "ImageNet1k"
Pulisher: "Baidu"
License: "apache.2.0"
Paper: ""
IfTraining: 1
IfOnlineDemo: 1
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 1. PP-HGNet 模型简介\n",
"PP-HGNet(High Performance GPU Net) 是百度飞桨视觉团队自研的更适用于 GPU 平台的高性能骨干网络,该网络在 VOVNet 的基础上使用了可学习的下采样层(LDS Layer),融合了 ResNet_vd、PPHGNet 等模型的优点,该模型在 GPU 平台上与其他 SOTA 模型在相同的速度下有着更高的精度。在同等速度下,该模型高于 ResNet34-D 模型 3.8 个百分点,高于 ResNet50-D 模型 2.4 个百分点,在使用百度自研 SSLD 蒸馏策略后,超越 ResNet50-D 模型 4.7 个百分点。与此同时,在相同精度下,其推理速度也远超主流 VisionTransformer 的推理速度。\n",
"\n",
"PP-HGNet 系列模型基于 PaddleClas 开发、训练,更多关于 PP-HGNet 系列模型的更多信息,可以从 [PaddleClas-PPHGNet](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.5/docs/zh_CN/models/ImageNet1k/PP-HGNet.md) 获取。"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 2. 模型效果\n",
"\n",
"PP-HGNet 系列模型在 ImageNet1k 数据集上的评测指标如下所示:\n",
"\n",
"| Model | Top-1 Acc(\\%) | Top-5 Acc(\\%) | Latency(ms) |\n",
"|:--: |:--: |:--: |:--: | :--: |:--: |\n",
"| PPHGNet_tiny | 79.83 | 95.04 | 1.77 |\n",
"| PPHGNet_tiny_ssld | 81.95 | 96.12 | 1.77 |\n",
"| PPHGNet_small | 81.51| 95.82 | 2.52 |\n",
"| PPHGNet_small_ssld | 83.82| 96.81 | 2.52 |\n",
"| PPHGNet_base_ssld | 85.00| 97.35 | 5.97 |\n",
"\n",
"其中 `_ssld` 表示使用 `SSLD 蒸馏`后的模型。关于 `SSLD蒸馏` 的内容,详情 [SSLD 蒸馏](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.5/docs/zh_CN/training/advanced/knowledge_distillation.md)。\n",
"\n",
"PP-HGNet 与其他模型的比较如下,其中测试机器为 NVIDIA® Tesla® V100,开启 TensorRT 引擎,精度类型为 FP32。在相同速度下,PP-HGNet 精度均超越了其他 SOTA CNN 模型,在与 SwinTransformer 模型的比较中,在更高精度的同时,速度快 2 倍以上。\n",
"\n",
"| Model | Top-1 Acc(\\%) | Top-5 Acc(\\%) | Latency(ms) |\n",
"|:--: |:--: |:--: |:--: |\n",
"| ResNet34 | 74.57 | 92.14 | 1.97 |\n",
"| ResNet34_vd | 75.98 | 92.98 | 2.00 |\n",
"| EfficientNetB0 | 77.38 | 93.31 | 1.96 |\n",
"| <b>PPHGNet_tiny<b> | <b>79.83<b> | <b>95.04<b> | <b>1.77<b> |\n",
"| <b>PPHGNet_tiny_ssld<b> | <b>81.95<b> | <b>96.12<b> | <b>1.77<b> |\n",
"| ResNet50 | 76.50 | 93.00 | 2.54 |\n",
"| ResNet50_vd | 79.12 | 94.44 | 2.60 |\n",
"| ResNet50_rsb | 80.40 | | 2.54 |\n",
"| EfficientNetB1 | 79.15 | 94.41 | 2.88 |\n",
"| SwinTransformer_tiny | 81.2 | 95.5 | 6.59 |\n",
"| <b>PPHGNet_small<b> | <b>81.51<b>| <b>95.82<b> | <b>2.52<b> |\n",
"| <b>PPHGNet_small_ssld<b> | <b>83.82<b>| <b>96.81<b> | <b>2.52<b> |\n",
"| Res2Net200_vd_26w_4s_ssld| 85.13 | 97.42 | 11.45 |\n",
"| ResNeXt101_32x48d_wsl | 85.37 | 97.69 | 55.07 |\n",
"| SwinTransformer_base | 85.2 | 97.5 | 13.53 | \n",
"| <b>PPHGNet_base_ssld<b> | <b>85.00<b>| <b>97.35<b> | <b>5.97<b> |"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 3. 模型快速使用\n",
"\n",
"### 3.1 模型推理:\n",
"* 安装相关 Python 包\n",
"\n",
"(不在Jupyter Notebook上运行时需要将\"!\"去掉。)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"如果您的机器安装了 CUDA9、CUDA10 或 CUDA11,请运行以下命令安装 paddle"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!pip install paddlepaddle-gpu"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"您的机器是CPU,请运行以下命令安装 paddle"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!pip install paddlepaddle"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"安装 paddleclas"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
},
"scrolled": true,
"tags": []
},
"outputs": [],
"source": [
"!pip install paddleclas"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* 快速体验\n",
"\n",
"恭喜! 您已经成功安装了 PaddleClas,接下来快速体验图像分类效果。"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true,
"tags": []
},
"outputs": [],
"source": [
"!wget https://gitee.com/paddlepaddle/PaddleClas/raw/release/2.5/docs/images/inference_deployment/whl_demo.jpg\n",
"!paddleclas --model_name=PPHGNet_small --infer_imgs=\"./whl_demo.jpg\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"上述命令的运行结果如下所示:\n",
"\n",
"class_ids: [8, 7, 86, 82, 81], scores: [0.71479, 0.08682, 0.00806, 0.0023, 0.00121], label_names: ['hen', 'cock', 'partridge', 'ruffed grouse, partridge, Bonasa umbellus', 'ptarmigan'], filename: docs/images/inference_deployment/whl_demo.jpg\n",
"Predict complete!"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 3.2 模型训练\n",
"* PP-HGNet 系列模型基于 PaddleClas 实现,模型训练的具体信息请参考[模型训练、评估和预测](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.5/docs/zh_CN/models/ImageNet1k/PP-HGNet.md#3-%E6%A8%A1%E5%9E%8B%E8%AE%AD%E7%BB%83%E8%AF%84%E4%BC%B0%E5%92%8C%E9%A2%84%E6%B5%8B)。"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 4. 模型原理"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"PP-HGNet 作者针对 GPU 设备,对目前 GPU 友好的网络做了分析和归纳,尽可能多的使用 3x3 标准卷积(计算密度最高)。在此将 VOVNet 作为基准模型,将主要的有利于 GPU 推理的改进点进行融合。从而得到一个有利于 GPU 推理的骨干网络,同样速度下,精度大幅超越其他 CNN 或者 VisionTransformer 模型。\n",
"\n",
"PP-HGNet 骨干网络的整体结构如下:\n",
"\n",
"<div align=\"center\">\n",
"<img src=\"https://user-images.githubusercontent.com/12560511/200782647-93cec23d-67fe-4585-bfcf-899dc65c7845.png\" width = \"80%\" />\n",
"</div>\n",
"\n",
"其中,PP-HGNet是由多个HG-Block组成,HG-Block的细节如下:\n",
"\n",
"<div align=\"center\">\n",
"<img src=\"https://user-images.githubusercontent.com/12560511/201665345-1182b902-29f2-43a4-bc9b-c3473769b025.png\" width = \"80%\" />\n",
"</div>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 5. 注意事项\n",
"PP-HGNet 系列模型的推理延时评测基于 NVIDIA® Tesla® V100 硬件平台进行,并且开启 TensorRT 引擎,精度类型为 FP32。"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 6. 相关论文以及引用信息"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.8"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 1. PP-HGNet Introduction\n",
"PP-HGNet(High Performance GPU Net) is a high-performance backbone network developed by the PaddleCV team that is more suitable for GPU devices.Based on VOVNet, the model uses a learnable downsampling layer(LDS Layer),which integrates the advantages and characteristics of ResNet_vd, PPHGNet and other models,Compared with other SOTA models on GPU devices, this model has higher accuracy under the same latency.At the same latency, the model is 3.8 percentage points higher than the ResNet34-D model, 2.4 percentage points higher than the ResNet50-D model, and 4.7 percentage points higher than the ResNet50-D model after using the SSLD distillation strategy. At the same time, under the same accuracy, its latency is much smaller than the mainstream VisionTransformer model.\n",
"\n",
"The PP-HGNet series model was developed and trained based on PaddleClas. For more information on PP-HGNet series models, see [PaddleClas-PPHGNet](https://github.com/PaddlePaddle/PaddleClas/blob/release%2F2.5/docs/en/models/PP-HGNet_en.md)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 2. Performance\n",
"\n",
"The evaluation indexes of PP-HGNet series models in ImageNet1k data set are shown as follows:\n",
"\n",
"| Model | Top-1 Acc(\\%) | Top-5 Acc(\\%) | Latency(ms) |\n",
"|:--: |:--: |:--: |:--: | :--: |:--: |\n",
"| PPHGNet_tiny | 79.83 | 95.04 | 1.77 |\n",
"| PPHGNet_tiny_ssld | 81.95 | 96.12 | 1.77 |\n",
"| PPHGNet_small | 81.51| 95.82 | 2.52 |\n",
"| PPHGNet_small_ssld | 83.82| 96.81 | 2.52 |\n",
"| PPHGNet_base_ssld | 85.00| 97.35 | 5.97 |\n",
"\n",
"`_ssld` represents the model after using `SSLD distillation`. For details about `SSLD distillation`, see [SSLD distillation](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.5/docs/en/advanced_tutorials/knowledge_distillation_en.md).\n",
"\n",
"The comparison between PP-HGNet and other models is as follows. The test machine is NVIDIA® Tesla® V100, the TensorRT engine is turned on, and the precision type is FP32. Under the same latency, the accuracy of PP-HGNet surpasses other SOTA CNN models, and in comparison with the SwinTransformer model, it is more than 2 times faster with higher accuracy.\n",
"\n",
"| Model | Top-1 Acc(\\%) | Top-5 Acc(\\%) | Latency(ms) |\n",
"|:--: |:--: |:--: |:--: |\n",
"| ResNet34 | 74.57 | 92.14 | 1.97 |\n",
"| ResNet34_vd | 75.98 | 92.98 | 2.00 |\n",
"| EfficientNetB0 | 77.38 | 93.31 | 1.96 |\n",
"| <b>PPHGNet_tiny<b> | <b>79.83<b> | <b>95.04<b> | <b>1.77<b> |\n",
"| <b>PPHGNet_tiny_ssld<b> | <b>81.95<b> | <b>96.12<b> | <b>1.77<b> |\n",
"| ResNet50 | 76.50 | 93.00 | 2.54 |\n",
"| ResNet50_vd | 79.12 | 94.44 | 2.60 |\n",
"| ResNet50_rsb | 80.40 | | 2.54 |\n",
"| EfficientNetB1 | 79.15 | 94.41 | 2.88 |\n",
"| SwinTransformer_tiny | 81.2 | 95.5 | 6.59 |\n",
"| <b>PPHGNet_small<b> | <b>81.51<b>| <b>95.82<b> | <b>2.52<b> |\n",
"| <b>PPHGNet_small_ssld<b> | <b>83.82<b>| <b>96.81<b> | <b>2.52<b> |\n",
"| Res2Net200_vd_26w_4s_ssld| 85.13 | 97.42 | 11.45 |\n",
"| ResNeXt101_32x48d_wsl | 85.37 | 97.69 | 55.07 |\n",
"| SwinTransformer_base | 85.2 | 97.5 | 13.53 | \n",
"| <b>PPHGNet_base_ssld<b> | <b>85.00<b>| <b>97.35<b> | <b>5.97<b> |"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 3. Quick Start\n",
"\n",
"### 3.1 Inference:\n",
"* Install the relevant Python packages\n",
"\n",
"(Remove the\"!\" when not running on the Jupyter Notebook)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Run the following command to install if CUDA9、CUDA10 or CUDA11 is available."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!pip install paddlepaddle-gpu"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Run the following command to install if GPU device is unavailable."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!pip install paddlepaddle"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Install paddleclas"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
},
"scrolled": true,
"tags": []
},
"outputs": [],
"source": [
"!pip install paddleclas"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* Quick Start\n",
"\n",
"Congratulations! Now that you've successfully installed PaddleClas, you can experience the image classification effects."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true,
"tags": []
},
"outputs": [],
"source": [
"!wget https://gitee.com/paddlepaddle/PaddleClas/raw/release/2.5/docs/images/inference_deployment/whl_demo.jpg\n",
"!paddleclas --model_name=PPHGNet_small --infer_imgs=\"./whl_demo.jpg\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The above command results are as follows:\n",
"\n",
"class_ids: [8, 7, 86, 82, 81], scores: [0.71479, 0.08682, 0.00806, 0.0023, 0.00121], label_names: ['hen', 'cock', 'partridge', 'ruffed grouse, partridge, Bonasa umbellus', 'ptarmigan'], filename: docs/images/inference_deployment/whl_demo.jpg\n",
"Predict complete!"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 3.2 Training\n",
"* PP-HGNet series models are implemented based on PaddleClas. For details of model training, please refer to[Training, Evaluation and Inference](https://github.com/paddlepaddle/paddleclas/blob/release%2F2.5/docs/en/models/PP-HGNet_en.md)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 4. Theory"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The author of PP-HGNet analyzes and summarizes the current GPU-friendly networks for GPU devices, and uses 3x3 standard convolutions as much as possible (the highest computational density). Here, VOVNet is used as the base model, and the improvement points that are mainly beneficial to GPU acceleration will be integrated. In the end, under the same latency of PP-HGNet, the accuracy greatly surpasses other backbones.\n",
"\n",
"The overall structure of the PP-HGNet backbone network is as follows:\n",
"\n",
"<div align=\"center\">\n",
"<img src=\"https://user-images.githubusercontent.com/12560511/200782647-93cec23d-67fe-4585-bfcf-899dc65c7845.png\" width = \"80%\" />\n",
"</div>\n",
"\n",
"Among them, PP-HGNet is composed of multiple HG-Blocks. The details of HG-Blocks are as follows:\n",
"\n",
"<div align=\"center\">\n",
"<img src=\"https://user-images.githubusercontent.com/12560511/201665345-1182b902-29f2-43a4-bc9b-c3473769b025.png\" width = \"80%\" />\n",
"</div>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 5. Notes\n",
"The test machine is NVIDIA® Tesla® V100, the TensorRT engine is turned on, and the precision type is FP32. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 6. Relevant Papers and Citations"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.8"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
import gradio as gr
import numpy as np
from paddleclas import PaddleClas
import cv2 as cv
clas = PaddleClas(model_name='PPLCNet_x0_25')
# UGC: Define the inference fn() for your models
def model_inference(image):
result = clas.predict(image)
return next(result)
def clear_all():
return None, None
with gr.Blocks() as demo:
gr.Markdown("Image Classification")
with gr.Column(scale=1, min_width=100):
img_in = gr.Image(
value="https://gitee.com/paddlepaddle/PaddleClas/raw/release/2.5/docs/images/inference_deployment/whl_demo.jpg",
shape=(200, 200),
label="Input").style(height=200)
with gr.Row():
btn1 = gr.Button("Clear")
btn2 = gr.Button("Submit")
prediction_out = gr.Textbox(label="Prediction")
btn1.click(fn=clear_all, inputs=None, outputs=[img_in, prediction_out])
btn2.click(fn=model_inference, inputs=img_in, outputs=[prediction_out])
gr.Button.style(1)
demo.launch()
【PP-LCNet-App-YAML】
APP_Info:
title: PP-LCNet-App
colorFrom: blue
colorTo: yellow
sdk: gradio
sdk_version: 3.4.1
app_file: app.py
license: apache-2.0
device: cpu
\ No newline at end of file
gradio
paddlepaddle
paddleclas
\ No newline at end of file
## 1. 训练 Benchmark
PP-LCNet 系列模型的训练 Benchmark 评测流程可以参考 [PaddleClas-TIPC](https://github.com/paddlepaddle/paddleclas/blob/release%2F2.5/test_tipc/docs/benchmark_train.md)
## 2. 推理 Benchmark
### 2.1 软硬件环境
* PP-LCNet 系列模型基于 Intel CPU、V100 GPU、SD855 在内的多种硬件平台对推理速度进行了评测;
* 下列测试均基于 FP32 精度完成;
* 对于 Intel CPU 硬件平台测试,开启 MKLDNN 加速;
* 对于 V100 GPU 硬件平台测试,开启 TensorRT 加速;
### 2.2 数据集
PP-LCNet 系列模型使用 ImageNet1k validation 数据集进行评测。
### 2.3 指标
#### 2.3.1 基于 Intel Xeon Gold 6148 的预测速度
| Model | Latency(ms)<br/>bs=1, thread=10 |
|:--:|:--:|
| PPLCNet_x0_25 | 1.74 |
| PPLCNet_x0_35 | 1.92 |
| PPLCNet_x0_5 | 2.05 |
| PPLCNet_x0_75 | 2.29 |
| PPLCNet_x1_0 | 2.46 |
| PPLCNet_x1_5 | 3.19 |
| PPLCNet_x2_0 | 4.27 |
| PPLCNet_x2_5 | 5.39 |
#### 2.3.2 基于 V100 GPU 的预测速度
| Models | Latency(ms)<br>bs=1 | Latency(ms)<br/>bs=4 | Latency(ms)<br/>bs=8 |
| :--: | :--:| :--: | :--: |
| PPLCNet_x0_25 | 0.72 | 1.17 | 1.71 |
| PPLCNet_x0_35 | 0.69 | 1.21 | 1.82 |
| PPLCNet_x0_5 | 0.70 | 1.32 | 1.94 |
| PPLCNet_x0_75 | 0.71 | 1.49 | 2.19 |
| PPLCNet_x1_0 | 0.73 | 1.64 | 2.53 |
| PPLCNet_x1_5 | 0.82 | 2.06 | 3.12 |
| PPLCNet_x2_0 | 0.94 | 2.58 | 4.08 |
#### 2.3.3 基于 SD855 的预测速度
| Models | Latency(ms)<br>bs=1, thread=1 | Latency(ms)<br/>bs=1, thread=2 | Latency(ms)<br/>bs=1, thread=4 |
| :--: | :--: | :--: | :--: |
| PPLCNet_x0_25 | 2.30 | 1.62 | 1.32 |
| PPLCNet_x0_35 | 3.15 | 2.11 | 1.64 |
| PPLCNet_x0_5 | 4.27 | 2.73 | 1.92 |
| PPLCNet_x0_75 | 7.38 | 4.51 | 2.91 |
| PPLCNet_x1_0 | 10.78 | 6.49 | 3.98 |
| PPLCNet_x1_5 | 20.55 | 12.26 | 7.54 |
| PPLCNet_x2_0 | 33.79 | 20.17 | 12.10 |
| PPLCNet_x2_5 | 49.89 | 29.60 | 17.82 |
## 3. 相关使用说明
更多信息请参考[PaddleClas-PPLCNet](https://github.com/paddlepaddle/paddleclas/blob/release%2F2.5/docs/zh_CN/models/ImageNet1k/PP-LCNet.md)
\ No newline at end of file
## 1. Train Benchmark
PP-LCNet series model training Benchmark evaluation process can be referred to [PaddleClas-TIPC](https://github.com/paddlepaddle/paddleclas/blob/release%2F2.5/test_tipc/docs/benchmark_train.md).
## 2. Inference Benchmark
### 2.1 Environment
* The inference speed of PP-LCNet series model is evaluated based on various hardware platforms including Intel CPU, V100 GPU and SD855.
* The precision type is FP32;
* For Intel CPU,the MKLDNN is turned on;
* For V100 GPU,the TensorRT is turned on;
### 2.2 Dataset
The PP-LCNet series models were evaluated using the ImageNet1k validation dataset.
### 2.3 Metrics
#### 2.3.1 Inference speed based on Intel Xeon Gold 6148
| Model | Latency(ms)<br/>bs=1, thread=10 |
|:--:|:--:|
| PPLCNet_x0_25 | 1.74 |
| PPLCNet_x0_35 | 1.92 |
| PPLCNet_x0_5 | 2.05 |
| PPLCNet_x0_75 | 2.29 |
| PPLCNet_x1_0 | 2.46 |
| PPLCNet_x1_5 | 3.19 |
| PPLCNet_x2_0 | 4.27 |
| PPLCNet_x2_5 | 5.39 |
#### 2.3.2 Inference speed based on V100 GPU
| Models | Latency(ms)<br>bs=1 | Latency(ms)<br/>bs=4 | Latency(ms)<br/>bs=8 |
| :--: | :--:| :--: | :--: |
| PPLCNet_x0_25 | 0.72 | 1.17 | 1.71 |
| PPLCNet_x0_35 | 0.69 | 1.21 | 1.82 |
| PPLCNet_x0_5 | 0.70 | 1.32 | 1.94 |
| PPLCNet_x0_75 | 0.71 | 1.49 | 2.19 |
| PPLCNet_x1_0 | 0.73 | 1.64 | 2.53 |
| PPLCNet_x1_5 | 0.82 | 2.06 | 3.12 |
| PPLCNet_x2_0 | 0.94 | 2.58 | 4.08 |
#### 2.3.3 Inference speed based on SD855
| Models | Latency(ms)<br>bs=1, thread=1 | Latency(ms)<br/>bs=1, thread=2 | Latency(ms)<br/>bs=1, thread=4 |
| :--: | :--: | :--: | :--: |
| PPLCNet_x0_25 | 2.30 | 1.62 | 1.32 |
| PPLCNet_x0_35 | 3.15 | 2.11 | 1.64 |
| PPLCNet_x0_5 | 4.27 | 2.73 | 1.92 |
| PPLCNet_x0_75 | 7.38 | 4.51 | 2.91 |
| PPLCNet_x1_0 | 10.78 | 6.49 | 3.98 |
| PPLCNet_x1_5 | 20.55 | 12.26 | 7.54 |
| PPLCNet_x2_0 | 33.79 | 20.17 | 12.10 |
| PPLCNet_x2_5 | 49.89 | 29.60 | 17.82 |
## 3. Instructions
For more information please refer to [PaddleClas-PPLCNet](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.5/docs/en/models/PP-LCNet_en.md).
# 模型列表
|模型名称 | 模型简介 | 模型体积 | 输入尺寸 | 下载地址 |
|---|---|---|---|---|
| PPLCNet_x0_25 | 图像分类 | | 224 | [推理模型](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPLCNet_x0_25_infer.tar)/[预训练模型](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/legendary_models/PPLCNet_x0_25_pretrained.pdparams) |
| PPLCNet_x0_35 | 图像分类 | | 224 | [推理模型](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPLCNet_x0_35_infer.tar)/[预训练模型](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/legendary_models/PPLCNet_x0_35_pretrained.pdparams) |
| PPLCNet_x0_5 | 图像分类 | | 224 | [推理模型](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPLCNet_x0_5_infer.tar)/[预训练模型](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/legendary_models/PPLCNet_x0_5_pretrained.pdparams) |
| PPLCNet_x0_75 | 图像分类 | | 224 | [推理模型](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPLCNet_x0_75_infer.tar)/[预训练模型](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/legendary_models/PPLCNet_x0_75_pretrained.pdparams) |
| PPLCNet_x1_0 | 图像分类 | | 224 | [推理模型](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPLCNet_x1_0_infer.tar)/[预训练模型](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/legendary_models/PPLCNet_x1_0_pretrained.pdparams) |
| PPLCNet_x1_5 | 图像分类 | | 224 | [推理模型](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPLCNet_x1_5_infer.tar)/[预训练模型](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/legendary_models/PPLCNet_x1_5_pretrained.pdparams) |
| PPLCNet_x2_0 | 图像分类 | | 224 | [推理模型](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPLCNet_x2_0_infer.tar)/[预训练模型](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/legendary_models/PPLCNet_x2_0_pretrained.pdparams) |
| PPLCNet_x2_5 | 图像分类 | | 224 | [推理模型](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPLCNet_x2_5_infer.tar)/[预训练模型](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/legendary_models/PPLCNet_x2_5_pretrained.pdparams) |
| PPLCNet_x0_5_ssld | 图像分类 | | 224 | [推理模型](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPLCNet_x0_5_ssld_infer.tar)/[预训练模型](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/legendary_models/PPLCNet_x0_5_ssld_pretrained.pdparams) |
| PPLCNet_x1_0_ssld | 图像分类 | | 224 | [推理模型](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPLCNet_x1_0_ssld_infer.tar)/[预训练模型](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/legendary_models/PPLCNet_x1_0_ssld_pretrained.pdparams) |
| PPLCNet_x2_5_ssld | 图像分类 | | 224 | [推理模型](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPLCNet_x2_5_ssld_infer.tar)/[预训练模型](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/legendary_models/PPLCNet_x2_5_ssld_pretrained.pdparams) |
# List of Models
| Model | Introduction | Model Size | Input Size | Download link |
|---|---|---|---|---|
| PPLCNet_x0_25 | Image classification | | 224 | [Inference](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPLCNet_x0_25_infer.tar)/[Pretrained](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/legendary_models/PPLCNet_x0_25_pretrained.pdparams) |
| PPLCNet_x0_35 | Image classification | | 224 | [Inference](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPLCNet_x0_35_infer.tar)/[Pretrained](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/legendary_models/PPLCNet_x0_35_pretrained.pdparams) |
| PPLCNet_x0_5 | Image classification | | 224 | [Inference](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPLCNet_x0_5_infer.tar)/[Pretrained](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/legendary_models/PPLCNet_x0_5_pretrained.pdparams) |
| PPLCNet_x0_75 | Image classification | | 224 | [Inference](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPLCNet_x0_75_infer.tar)/[Pretrained](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/legendary_models/PPLCNet_x0_75_pretrained.pdparams) |
| PPLCNet_x1_0 | Image classification | | 224 | [Inference](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPLCNet_x1_0_infer.tar)/[Pretrained](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/legendary_models/PPLCNet_x1_0_pretrained.pdparams) |
| PPLCNet_x1_5 | Image classification | | 224 | [Inference](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPLCNet_x1_5_infer.tar)/[Pretrained](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/legendary_models/PPLCNet_x1_5_pretrained.pdparams) |
| PPLCNet_x2_0 | Image classification | | 224 | [Inference](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPLCNet_x2_0_infer.tar)/[Pretrained](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/legendary_models/PPLCNet_x2_0_pretrained.pdparams) |
| PPLCNet_x2_5 | Image classification | | 224 | [Inference](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPLCNet_x2_5_infer.tar)/[Pretrained](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/legendary_models/PPLCNet_x2_5_pretrained.pdparams) |
| PPLCNet_x0_5_ssld | Image classification | | 224 | [Inference](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPLCNet_x0_5_ssld_infer.tar)/[Pretrained](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/legendary_models/PPLCNet_x0_5_ssld_pretrained.pdparams) |
| PPLCNet_x1_0_ssld | Image classification | | 224 | [Inference](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPLCNet_x1_0_ssld_infer.tar)/[Pretrained](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/legendary_models/PPLCNet_x1_0_ssld_pretrained.pdparams) |
| PPLCNet_x2_5_ssld | Image classification | | 224 | [Inference](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPLCNet_x2_5_ssld_infer.tar)/[Pretrained](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/legendary_models/PPLCNet_x2_5_ssld_pretrained.pdparams) |
---
Model_Info:
name: "PP-LCNet"
description: "面向Intel CPU端的轻量级卷积神经网络"
description_en: "A Lightweight Convolutional Neural Network for Intel CPU"
icon: ""
from_repo: "PaddleClas"
Task:
- tag_en: "Computer Vision"
tag: "计算机视觉"
sub_tag_en: "Image Classification"
sub_tag: "图像分类"
Example:
- tag_en: "Intelligent Security"
tag: "智慧安防"
sub_tag_en: "Personnel access management"
title: "人员进出视频管理方案详解"
sub_tag: "人员进出管理"
url: "https://aistudio.baidu.com/aistudio/projectdetail/4094475"
Datasets: "ImageNet1k"
Pulisher: "Baidu"
License: "apache.2.0"
Paper:
- title: "PP-LCNet: A Lightweight CPU Convolutional Neural Network"
url: "https://arxiv.org/pdf/2109.15099.pdf"
IfTraining: 1
IfOnlineDemo: 1
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 1. PP-LCNet 模型简介\n",
"PP-LCNet 系列模型是 PaddleCV 团队提出的轻量级卷积神经网络模型,该系列模型针对 Intel CPU 硬件平台特别优化,同时兼顾多种平台,在模型推理速度和精度之间取得了很好的平衡,实现了速度更快、准确率更高的轻量级骨干网络,同时也能提高目标检测、语义分割等下游视觉任务的效果。在 ImageNet1k 数据集上,PPLCNet 系列模型与其他轻量级网络的对比效果如下图所示。\n",
"\n",
"<div align=\"center\">\n",
"<img src=\"https://user-images.githubusercontent.com/12560511/200731336-917cfa94-8470-4ac5-97a3-1f0d686a8f44.png\" width = \"80%\" />\n",
"</div>\n",
"\n",
"\n",
"PP-LCNet 系列模型基于 PaddleClas 开发、训练,更多关于 PP-LCNet 系列模型的更多信息,可以从 [PaddleClas-PPLCNet](https://github.com/paddlepaddle/paddleclas/blob/release%2F2.5/docs/zh_CN/models/ImageNet1k/PP-LCNet.md) 获取。"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 2. 模型效果\n",
"\n",
"我们在图像分类、目标检测、语义分割任务上评测了 PP-LCNet 系列模型的效果。\n",
"\n",
"### 2.1 图像分类\n",
"\n",
"PP-LCNet 系列模型在 ImageNet1k 数据集上的评测指标如下所示:\n",
"\n",
"| Model | Params(M) | FLOPs(M) | Top-1 Acc(\\%) | Top-5 Acc(\\%) | Latency(ms) |\n",
"|:--:|:--:|:--:|:--:|:--:|:--:|:--:|:--:|\n",
"| PPLCNet_x0_25 | 1.5 | 18 | 51.86 | 75.65 | 1.74 |\n",
"| PPLCNet_x0_35 | 1.6 | 29 | 58.09 | 80.83 | 1.92 |\n",
"| PPLCNet_x0_5 | 1.9 | 47 | 63.14 | 84.66 | 2.05 |\n",
"| PPLCNet_x0_75 | 2.4 | 99 | 68.18 | 88.30 | 2.29 |\n",
"| PPLCNet_x1_0 | 3.0 | 161 | 71.32 | 90.03 | 2.46 |\n",
"| PPLCNet_x1_5 | 4.5 | 342 | 73.71 | 91.53 | 3.19 |\n",
"| PPLCNet_x2_0 | 6.5 | 590 | 75.18 | 92.27 | 4.27 |\n",
"| PPLCNet_x2_5 | 9.0 | 906 | 76.60 | 93.00 | 5.39 |\n",
"| PPLCNet_x0_5_ssld | 1.9 | 47 | 66.10 | 86.46 | 2.05 |\n",
"| PPLCNet_x1_0_ssld | 3.0 | 161 | 74.39 | 92.09 | 2.46 |\n",
"| PPLCNet_x2_5_ssld | 9.0 | 906 | 80.82 | 95.33 | 5.39 |\n",
"\n",
"其中 `_ssld` 表示使用 `SSLD 蒸馏`后的模型。关于 `SSLD蒸馏` 的内容,详情 [SSLD 蒸馏](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.5/docs/zh_CN/training/advanced/knowledge_distillation.md)。\n",
"\n",
"与其他轻量级网络的性能对比:\n",
"\n",
"| Model | Params(M) | FLOPs(M) | Top-1 Acc(\\%) | Top-5 Acc(\\%) | Latency(ms) |\n",
"|:--:|:--:|:--:|:--:|:--:|:--:|\n",
"| MobileNetV2_x0_25 | 1.5 | 34 | 53.21 | 76.52 | 2.47 |\n",
"| MobileNetV3_small_x0_35 | 1.7 | 15 | 53.03 | 76.37 | 3.02 |\n",
"| ShuffleNetV2_x0_33 | 0.6 | 24 | 53.73 | 77.05 | 4.30 |\n",
"| <b>PPLCNet_x0_25<b> | <b>1.5<b> | <b>18<b> | <b>51.86<b> | <b>75.65<b> | <b>1.74<b> |\n",
"| MobileNetV2_x0_5 | 2.0 | 99 | 65.03 | 85.72 | 2.85 |\n",
"| MobileNetV3_large_x0_35 | 2.1 | 41 | 64.32 | 85.46 | 3.68 |\n",
"| ShuffleNetV2_x0_5 | 1.4 | 43 | 60.32 | 82.26 | 4.65 |\n",
"| <b>PPLCNet_x0_5<b> | <b>1.9<b> | <b>47<b> | <b>63.14<b> | <b>84.66<b> | <b>2.05<b> |\n",
"| MobileNetV1_x1_0 | 4.3 | 578 | 70.99 | 89.68 | 3.38 |\n",
"| MobileNetV2_x1_0 | 3.5 | 327 | 72.15 | 90.65 | 4.26 |\n",
"| MobileNetV3_small_x1_25 | 3.6 | 100 | 70.67 | 89.51 | 3.95 |\n",
"| <b>PPLCNet_x1_0<b> |<b> 3.0<b> | <b>161<b> | <b>71.32<b> | <b>90.03<b> | <b>2.46<b> |\n",
"\n",
"### 2.2 目标检测\n",
"\n",
"目标检测的方法选用了百度自研的 PicoDet,该方法主打轻量级目标检测场景,下表展示了在 COCO 数据集上、backbone 选用 PP-LCNet 与 MobileNetV3 的结果的比较,无论在精度还是速度上,PP-LCNet 的优势都非常明显。\n",
"\n",
"| Backbone | mAP(%) | Latency(ms) |\n",
"|:--:|:--:|:--:|\n",
"| MobileNetV3_large_x0_35 | 19.2 | 8.1 |\n",
"| <b>PPLCNet_x0_5<b> | <b>20.3<b> | <b>6.0<b> |\n",
"| MobileNetV3_large_x0_75 | 25.8 | 11.1 |\n",
"| <b>PPLCNet_x1_0<b> | <b>26.9<b> | <b>7.9<b> |\n",
"\n",
"### 2.3 语义分割\n",
"\n",
"语义分割的方法我们选用了 DeeplabV3+,下表展示了在 Cityscapes 数据集上、backbone 选用 PP-LCNet 与 MobileNetV3 的比较,在精度和速度方面,PP-LCNet 的优势同样明显。\n",
"\n",
"| Backbone | mIoU(%) | Latency(ms) |\n",
"|:--:|:--:|:--:|\n",
"| MobileNetV3_large_x0_5 | 55.42 | 135 |\n",
"| <b>PPLCNet_x0_5<b> | <b>58.36<b> | <b>82<b> |\n",
"| MobileNetV3_large_x0_75 | 64.53 | 151 |\n",
"| <b>PPLCNet_x1_0<b> | <b>66.03<b> | <b>96<b> |"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 3. 模型快速使用\n",
"\n",
"### 3.1 模型推理:\n",
"* 安装相关 Python 包\n",
"\n",
"(不在Jupyter Notebook上运行时需要将\"!\"去掉。)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"如果您的机器安装了 CUDA9、CUDA10 或 CUDA11,请运行以下命令安装 paddle"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!pip install paddlepaddle-gpu"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"您的机器是CPU,请运行以下命令安装 paddle"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!pip install paddlepaddle"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"安装 paddleclas"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
},
"scrolled": true,
"tags": []
},
"outputs": [],
"source": [
"!pip install paddleclas"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* 快速体验\n",
"\n",
"恭喜! 您已经成功安装了 PaddleClas,接下来快速体验图像分类效果。"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true,
"tags": []
},
"outputs": [],
"source": [
"!wget https://gitee.com/paddlepaddle/PaddleClas/raw/release/2.5/docs/images/inference_deployment/whl_demo.jpg\n",
"!paddleclas --model_name=PPLCNet_x1_0 --infer_imgs=\"./whl_demo.jpg\"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"上述命令的运行结果如下所示:\n",
"\n",
"class_ids: [8, 7, 86, 81, 85], scores: [0.91347, 0.03779, 0.0036, 0.00117, 0.00112], label_names: ['hen', 'cock', 'partridge', 'ptarmigan', 'quail'], filename: docs/images/inference_deployment/whl_demo.jpg\n",
"Predict complete!"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 3.2 模型训练\n",
"* PP-LCNet 系列模型基于 PaddleClas 实现,模型训练的具体信息请参考[模型训练、评估和预测](https://github.com/paddlepaddle/paddleclas/blob/release%2F2.5/docs/zh_CN/models/ImageNet1k/PP-LCNet.md#3-%E6%A8%A1%E5%9E%8B%E8%AE%AD%E7%BB%83%E8%AF%84%E4%BC%B0%E5%92%8C%E9%A2%84%E6%B5%8B)。"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 4. 模型原理"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 4.1 总体结构\n",
"\n",
"PP-LCNet 网络的整体结构如下图所示:\n",
"\n",
"<div align=\"center\">\n",
"<img src=\"https://user-images.githubusercontent.com/12560511/200734729-62f11a96-6c93-4061-8fc7-ca5d2c41d92b.png\" width = \"80%\" />\n",
"</div>\n",
"\n",
"### 4.2 模型细节\n",
"\n",
"PP-LCNet 网络的结果设计基于大量实验结果,通过对网络不同结构进行实验,总结出了 4 个几乎不增加模型延迟但可以提高模型性能的策略,通过融合这 4 个策略得到了 PP-LCNet 模型。下面对这四条策略一一介绍:\n",
"\n",
"#### 4.2.1 更好的激活函数\n",
"\n",
"自从卷积神经网络使用了 ReLU 激活函数后,网络性能得到了大幅度提升,近些年 ReLU 激活函数的变体也相继出现,如 Leaky-ReLU、P-ReLU、ELU 等,2017 年,谷歌大脑团队通过搜索的方式得到了 swish 激活函数,该激活函数在轻量级网络上表现优异,在 2019 年,MobileNetV3 的作者将该激活函数进一步优化为 H-Swish,该激活函数去除了指数运算,速度更快,网络精度几乎不受影响。我们也经过很多实验发现该激活函数在轻量级网络上有优异的表现。所以在 PP-LCNet 中,我们选用了该激活函数。\n",
"\n",
"#### 4.2.2 合适的位置添加 SE 模块\n",
"SE 模块是 SENet 提出的一种通道注意力机制,可以有效提升模型的精度。但是在 Intel CPU 端,该模块同样会带来较大的延时,如何平衡精度和速度是我们要解决的一个问题。虽然在 MobileNetV3 等基于 NAS 搜索的网络中对 SE 模块的位置进行了搜索,但是并没有得出一般的结论,我们通过实验发现,SE 模块越靠近网络的尾部对模型精度的提升越大。下表也展示了我们的一些实验结果:\n",
"\n",
"| SE Location | Top-1 Acc(\\%) | Latency(ms) |\n",
"|:--:|:--:|:--:|\n",
"| 1100000000000 | 61.73 | 2.06 |\n",
"| 0000001100000 | 62.17 | 2.03 |\n",
"| <b>0000000000011<b> | <b>63.14<b> | <b>2.05<b> |\n",
"| 1111111111111 | 64.27 | 3.80 |\n",
"\n",
"最终,PP-LCNet 中的 SE 模块的位置选用了表格中第三行的方案。\n",
"\n",
"#### 4.2.3 合适的位置添加更大的卷积核\n",
"\n",
"在 MixNet 的论文中,作者分析了卷积核大小对模型性能的影响,结论是在一定范围内大的卷积核可以提升模型的性能,但是超过这个范围会有损模型的性能,所以作者组合了一种 split-concat 范式的 MixConv,这种组合虽然可以提升模型的性能,但是不利于推理。我们通过实验总结了一些更大的卷积核在不同位置的作用,类似 SE 模块的位置,更大的卷积核在网络的中后部作用更明显,下表展示了 5x5 卷积核的位置对精度的影响:\n",
"\n",
"| large-kernel Location | Top-1 Acc(\\%) | Latency(ms) |\n",
"|:--:|:--:|:--:|\n",
"| 1111111111111 | 63.22 | 2.08 |\n",
"| 1111111000000 | 62.70 | 2.07 |\n",
"| <b>0000001111111<b> | <b>63.14<b> | <b>2.05<b> |\n",
"\n",
"实验表明,更大的卷积核放在网络的中后部即可达到放在所有位置的精度,与此同时,获得更快的推理速度。PP-LCNet 最终选用了表格中第三行的方案。\n",
"\n",
"\n",
"#### 4.2.4 GAP 后使用更大的 1x1 卷积层\n",
"在 GoogLeNet 之后,GAP(Global-Average-Pooling)后往往直接接分类层,但是在轻量级网络中,这样会导致 GAP 后提取的特征没有得到进一步的融合和加工。如果在此后使用一个更大的 1x1 卷积层(等同于 FC 层),GAP 后的特征便不会直接经过分类层,而是先进行了融合,并将融合的特征进行分类。这样可以在不影响模型推理速度的同时大大提升准确率。 \n",
"\n",
"\n",
"经过以上四个方面的改进,得到了 PP-LCNet。下表进一步说明了每个方案对结果的影响:\n",
"\n",
"| Activation | SE-block | Large-kernel | last-1x1-conv | Top-1 Acc(\\%) | Latency(ms) |\n",
"|:--:|:--:|:--:|:--:|:--:|:--:|\n",
"| 0 | 1 | 1 | 1 | 61.93 | 1.94 |\n",
"| 1 | 0 | 1 | 1 | 62.51 | 1.87 |\n",
"| 1 | 1 | 0 | 1 | 62.44 | 2.01 |\n",
"| 1 | 1 | 1 | 0 | 59.91 | 1.85 |\n",
"| <b>1<b> | <b>1<b> | <b>1<b> | <b>1<b> | <b>63.14<b> | <b>2.05<b> |\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 5. 注意事项\n",
"PP-LCNet 系列模型在 Intel CPU 端延时测试基于 Intel Xeon Gold 6148 硬件平台完成,推理框架使用 PaddlePaddle,开启 MKLDNN 加速,推理 batch size 为 1,线程数为 10。"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 6. 相关论文以及引用信息\n",
"\n",
"@misc{cui2021pplcnet,\n",
" title={PP-LCNet: A Lightweight CPU Convolutional Neural Network},\n",
" author={Cheng Cui and Tingquan Gao and Shengyu Wei and Yuning Du and Ruoyu Guo and Shuilong Dong and Bin Lu and Ying Zhou and Xueying Lv and Qiwen Liu and Xiaoguang Hu and Dianhai Yu and Yanjun Ma},\n",
" year={2021},\n",
" eprint={2109.15099},\n",
" archivePrefix={arXiv},\n",
" primaryClass={cs.CV}\n",
"}"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.8"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 1. PP-LCNet Introduction\n",
"PP-LCNet series model is a lightweight convolutional neural network model proposed by PaddleCV team. This series model is specially optimized for Intel CPU hardware platform and takes into account various platforms at the same time. It achieves a good balance between model inference speed and precision and achieves a lightweight backbone network with faster speed and higher accuracy. It can also improve the effect of object detection, semantic segmentation and other downstream visual tasks. On the ImageNet1k dataset, the PP-LCNet series model is compared to other lightweight networks as shown in the figure below.\n",
"\n",
"<div align=\"center\">\n",
"<img src=\"https://user-images.githubusercontent.com/12560511/200731336-917cfa94-8470-4ac5-97a3-1f0d686a8f44.png\" width = \"80%\" />\n",
"</div>\n",
"\n",
"\n",
"The PP-LCNet series model was developed and trained based on PaddleClas. For more information on PP-LCNet series models, see [PaddleClas-PPLCNet](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.5/docs/en/models/PP-LCNet_en.md)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 2. Performance\n",
"\n",
"We evaluated the performance of PP-LCNet series models on the tasks of image classification, object detection and semantic segmentation.\n",
"\n",
"### 2.1 Image Classification\n",
"\n",
"The evaluation results of PP-LCNet series models in ImageNet1k dataset are shown as follows:\n",
"\n",
"| Model | Params(M) | FLOPs(M) | Top-1 Acc(\\%) | Top-5 Acc(\\%) | Latency(ms) |\n",
"|:--:|:--:|:--:|:--:|:--:|:--:|:--:|:--:|\n",
"| PPLCNet_x0_25 | 1.5 | 18 | 51.86 | 75.65 | 1.74 |\n",
"| PPLCNet_x0_35 | 1.6 | 29 | 58.09 | 80.83 | 1.92 |\n",
"| PPLCNet_x0_5 | 1.9 | 47 | 63.14 | 84.66 | 2.05 |\n",
"| PPLCNet_x0_75 | 2.4 | 99 | 68.18 | 88.30 | 2.29 |\n",
"| PPLCNet_x1_0 | 3.0 | 161 | 71.32 | 90.03 | 2.46 |\n",
"| PPLCNet_x1_5 | 4.5 | 342 | 73.71 | 91.53 | 3.19 |\n",
"| PPLCNet_x2_0 | 6.5 | 590 | 75.18 | 92.27 | 4.27 |\n",
"| PPLCNet_x2_5 | 9.0 | 906 | 76.60 | 93.00 | 5.39 |\n",
"| PPLCNet_x0_5_ssld | 1.9 | 47 | 66.10 | 86.46 | 2.05 |\n",
"| PPLCNet_x1_0_ssld | 3.0 | 161 | 74.39 | 92.09 | 2.46 |\n",
"| PPLCNet_x2_5_ssld | 9.0 | 906 | 80.82 | 95.33 | 5.39 |\n",
"\n",
"`_ssld` represents the model after using `SSLD distillation`. For details about `SSLD distillation`, see [SSLD distillation](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.5/docs/en/advanced_tutorials/knowledge_distillation_en.md).\n",
"\n",
"Performance comparison with other lightweight networks:\n",
"\n",
"| Model | Params(M) | FLOPs(M) | Top-1 Acc(\\%) | Top-5 Acc(\\%) | Latency(ms) |\n",
"|:--:|:--:|:--:|:--:|:--:|:--:|\n",
"| MobileNetV2_x0_25 | 1.5 | 34 | 53.21 | 76.52 | 2.47 |\n",
"| MobileNetV3_small_x0_35 | 1.7 | 15 | 53.03 | 76.37 | 3.02 |\n",
"| ShuffleNetV2_x0_33 | 0.6 | 24 | 53.73 | 77.05 | 4.30 |\n",
"| <b>PPLCNet_x0_25<b> | <b>1.5<b> | <b>18<b> | <b>51.86<b> | <b>75.65<b> | <b>1.74<b> |\n",
"| MobileNetV2_x0_5 | 2.0 | 99 | 65.03 | 85.72 | 2.85 |\n",
"| MobileNetV3_large_x0_35 | 2.1 | 41 | 64.32 | 85.46 | 3.68 |\n",
"| ShuffleNetV2_x0_5 | 1.4 | 43 | 60.32 | 82.26 | 4.65 |\n",
"| <b>PPLCNet_x0_5<b> | <b>1.9<b> | <b>47<b> | <b>63.14<b> | <b>84.66<b> | <b>2.05<b> |\n",
"| MobileNetV1_x1_0 | 4.3 | 578 | 70.99 | 89.68 | 3.38 |\n",
"| MobileNetV2_x1_0 | 3.5 | 327 | 72.15 | 90.65 | 4.26 |\n",
"| MobileNetV3_small_x1_25 | 3.6 | 100 | 70.67 | 89.51 | 3.95 |\n",
"| <b>PPLCNet_x1_0<b> |<b> 3.0<b> | <b>161<b> | <b>71.32<b> | <b>90.03<b> | <b>2.46<b> |\n",
"\n",
"### 2.2 Object Detection\n",
"\n",
"The object detection method uses PicoDet developed by Baidu, which focuses on lightweight object detection scenarios. The following table shows the comparison between PP-LCNet and MobileNetV3 on COCO datasets. In terms of accuracy and speed, The advantages of PP-LCNet are obvious.\n",
"\n",
"| Backbone | mAP(%) | Latency(ms) |\n",
"|:--:|:--:|:--:|\n",
"| MobileNetV3_large_x0_35 | 19.2 | 8.1 |\n",
"| <b>PPLCNet_x0_5<b> | <b>20.3<b> | <b>6.0<b> |\n",
"| MobileNetV3_large_x0_75 | 25.8 | 11.1 |\n",
"| <b>PPLCNet_x1_0<b> | <b>26.9<b> | <b>7.9<b> |\n",
"\n",
"### 2.3 Semantic Segmentation\n",
"\n",
"The semantic segmentation method uses DeeplabV3+,The following table shows the comparison between PP-LCNet and MobileNetV3 on Cityscapes datasets. PP-LCNet has obvious advantages in terms of accuracy and speed.\n",
"\n",
"| Backbone | mIoU(%) | Latency(ms) |\n",
"|:--:|:--:|:--:|\n",
"| MobileNetV3_large_x0_5 | 55.42 | 135 |\n",
"| <b>PPLCNet_x0_5<b> | <b>58.36<b> | <b>82<b> |\n",
"| MobileNetV3_large_x0_75 | 64.53 | 151 |\n",
"| <b>PPLCNet_x1_0<b> | <b>66.03<b> | <b>96<b> |"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 3. Quick Start\n",
"\n",
"### 3.1 Inference:\n",
"* Install the relevant Python packages\n",
"\n",
" (Remove the\"!\" when not running on the Jupyter Notebook) \n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Run the following command to install if CUDA9、CUDA10 or CUDA11 is available."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!pip install paddlepaddle-gpu"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Run the following command to install if GPU device is unavailable."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!pip install paddlepaddle"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Install paddleclas"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
},
"scrolled": true,
"tags": []
},
"outputs": [],
"source": [
"!pip install paddleclas"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* Quick Start\n",
"\n",
"Congratulations! Now that you've successfully installed PaddleClas, you can experience the image classification effects."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true,
"tags": []
},
"outputs": [],
"source": [
"!wget https://gitee.com/paddlepaddle/PaddleClas/raw/release/2.5/docs/images/inference_deployment/whl_demo.jpg\n",
"!paddleclas --model_name=PPLCNet_x1_0 --infer_imgs=\"./whl_demo.jpg\"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The above command results are as follows:\n",
"\n",
"class_ids: [8, 7, 86, 81, 85], scores: [0.91347, 0.03779, 0.0036, 0.00117, 0.00112], label_names: ['hen', 'cock', 'partridge', 'ptarmigan', 'quail'], filename: docs/images/inference_deployment/whl_demo.jpg\n",
"Predict complete!"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 3.2 Training\n",
"* PP-LCNet series models are implemented based on PaddleClas. For details of model training, please refer to[Training, Evaluation and Inference](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.5/docs/en/models/PP-LCNet_en.md)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 4. Theory"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 4.1 Overall Structure\n",
"\n",
"The overall structure of the network is shown in the figure below. \n",
"\n",
"<div align=\"center\">\n",
"<img src=\"https://user-images.githubusercontent.com/12560511/200734729-62f11a96-6c93-4061-8fc7-ca5d2c41d92b.png\" width = \"80%\" />\n",
"</div>\n",
"\n",
"### 4.2 Model Details\n",
"\n",
"Build on extensive experiments, through the experiment of different network structure,we summarized some strategies that can improve the accuracy of the model without increasing the latency and combined these four strategies to form PP-LCNet.Each of these strategies is described below:\n",
"\n",
"#### 4.2.1 Better Activation Function\n",
"\n",
"Since the convolutional neural network uses ReLU activation function, the network performance has been greatly improved. In recent years, variants of ReLU activation function have also appeared successively, such as Leaky-ReLU, P-ReLU, ELU, etc. In 2017, Google Brain team obtained the swish activation function by searching. The activation function performs well on lightweight networks, and in 2019, the authors of MobileNetV3 further optimized the activation function to H-Swish, which eliminates exponential operations and is faster with little impact on network accuracy. After many experiments, we find that this activation function has excellent performance on lightweight networks. Therefore, at PP-LCNet, we chose this activation function.\n",
"\n",
"#### 4.2.2 Add the SE Module at an Appropriate Position\n",
"SE module is a channel attention mechanism proposed by SENet, which can effectively improve the accuracy of the model. However, in the Intel CPU side, this module will also bring a large delay, how to balance the accuracy and speed is a problem we need to solve. Although the position of SE module was searched in the network based on NAS search such as MobileNetV3, no general conclusion was drawn. We found through the experiment that the closer the SE module is to the tail of the network, the greater the improvement of model accuracy. The following table also shows some of our experimental results:\n",
"\n",
"| SE Location | Top-1 Acc(\\%) | Latency(ms) |\n",
"|:--:|:--:|:--:|\n",
"| 1100000000000 | 61.73 | 2.06 |\n",
"| 0000001100000 | 62.17 | 2.03 |\n",
"| <b>0000000000011<b> | <b>63.14<b> | <b>2.05<b> |\n",
"| 1111111111111 | 64.27 | 3.80 |\n",
"\n",
"Finally, the position of SE module in PP-LCNet selected the scheme in the third row of the table.\n",
"\n",
"#### 4.2.3 Add a Larger Convolution Kernel at Appropriate Position \n",
"\n",
"In the paper on MixNet, the author analyzed the influence of convolution kernel size on model performance and concluded that large convolution kernel could improve model performance within a certain range, but beyond this range would damage model performance. Therefore, the author combined a split-concat paradigm MixConv. Although this combination can improve the performance of the model, it is not conducive to reasoning. Through experiments, we have summarized the functions of some larger convolution kernel in different positions. Similar to the position of SE module, larger convolution nuclei play a more obvious role in the middle and back of the network. The following table shows the influence of the position of 5x5 convolution kernel on the accuracy:\n",
"\n",
"| large-kernel Location | Top-1 Acc(\\%) | Latency(ms) |\n",
"|:--:|:--:|:--:|\n",
"| 1111111111111 | 63.22 | 2.08 |\n",
"| 1111111000000 | 62.70 | 2.07 |\n",
"| <b>0000001111111<b> | <b>63.14<b> | <b>2.05<b> |\n",
"\n",
"Experiments show that a larger convolution kernel placed in the middle and back of the network can achieve the accuracy of placing in all positions, and at the same time, faster inference speed can be obtained. PP-LCNet finally chose the third row of the table.\n",
"\n",
"\n",
"#### 4.2.4 Use a Larger 1x1 Convolution Layer After the GAP\n",
"After GoogLeNet, the classification layer is often directly adopted after the GAP(Global-Average-Pooling). However, in lightweight networks, this will lead to no further integration and processing of features extracted after the GAP. If a larger 1x1 convolution layer (equivalent to FC layer) is used thereafter, the features after GAP will not be directly through the classification layer, but the fusion is first carried out, and the fusion features are classified. This can greatly improve the accuracy without affecting the model inference speed. BaseNet obtained PP-LCNet by improving the above four aspects. \n",
"\n",
"\n",
"The following table further illustrates the impact of each strategy on the results:\n",
"\n",
"| Activation | SE-block | Large-kernel | last-1x1-conv | Top-1 Acc(\\%) | Latency(ms) |\n",
"|:--:|:--:|:--:|:--:|:--:|:--:|\n",
"| 0 | 1 | 1 | 1 | 61.93 | 1.94 |\n",
"| 1 | 0 | 1 | 1 | 62.51 | 1.87 |\n",
"| 1 | 1 | 0 | 1 | 62.44 | 2.01 |\n",
"| 1 | 1 | 1 | 0 | 59.91 | 1.85 |\n",
"| <b>1<b> | <b>1<b> | <b>1<b> | <b>1<b> | <b>63.14<b> | <b>2.05<b> |\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 5. Notes\n",
"The inference speed of PP-LCNet series model were tested at Intel Xeon Gold 6148 CPU with PaddlePaddle inference framework, and MKLDNN was turned on, the batch size was 1 and the number of threads was 10."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 6. Relevant Papers and Citations\n",
"\n",
"@misc{cui2021pplcnet,\n",
" title={PP-LCNet: A Lightweight CPU Convolutional Neural Network},\n",
" author={Cheng Cui and Tingquan Gao and Shengyu Wei and Yuning Du and Ruoyu Guo and Shuilong Dong and Bin Lu and Ying Zhou and Xueying Lv and Qiwen Liu and Xiaoguang Hu and Dianhai Yu and Yanjun Ma},\n",
" year={2021},\n",
" eprint={2109.15099},\n",
" archivePrefix={arXiv},\n",
" primaryClass={cs.CV}\n",
"}"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.8"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
import gradio as gr
import numpy as np
from paddleclas import PaddleClas
import cv2 as cv
clas = PaddleClas(model_name='PPLCNetV2_base')
# UGC: Define the inference fn() for your models
def model_inference(image):
result = clas.predict(image)
return next(result)
def clear_all():
return None, None
with gr.Blocks() as demo:
gr.Markdown("Image Classification")
with gr.Column(scale=1, min_width=100):
img_in = gr.Image(
value="https://gitee.com/paddlepaddle/PaddleClas/raw/release/2.5/docs/images/inference_deployment/whl_demo.jpg",
shape=(200, 200),
label="Input").style(height=200)
with gr.Row():
btn1 = gr.Button("Clear")
btn2 = gr.Button("Submit")
prediction_out = gr.Textbox(label="Prediction")
btn1.click(fn=clear_all, inputs=None, outputs=[img_in, prediction_out])
btn2.click(fn=model_inference, inputs=img_in, outputs=[prediction_out])
gr.Button.style(1)
demo.launch()
【PP-LCNetV2-App-YAML】
APP_Info:
title: PP-LCNetV2-App
colorFrom: blue
colorTo: yellow
sdk: gradio
sdk_version: 3.4.1
app_file: app.py
license: apache-2.0
device: cpu
gradio
paddlepaddle
paddleclas
\ No newline at end of file
## 1. 训练 Benchmark
PP-LCNetV2 系列模型的训练 Benchmark 评测流程可以参考 [PaddleClas-TIPC](https://github.com/paddlepaddle/paddleclas/blob/release%2F2.5/test_tipc/docs/benchmark_train.md)
## 2. 推理 Benchmark
### 2.1 软硬件环境
* 下列测试基于 Intel Xeon Gold 6271C 硬件平台与 OpenVINO 2021.4.2 推理平台完成;
* 下列测试均基于 FP32 精度完成;
### 2.2 数据集
PP-LCNetV2 系列模型使用 ImageNet1k validation 数据集进行评测。
### 2.3 指标
| Model | Latency(ms) |
|:--:|:--:|
| <b>PPLCNetV2_base<b> | <b>4.32<b> |
| <b>PPLCNetV2_base_ssld<b> | <b>4.32<b> |
## 3. 相关使用说明
更多信息请参考[PaddleClas-PPLCNetV2](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.5/docs/zh_CN/models/ImageNet1k/PP-LCNetV2.md)
## 1. Train Benchmark
PP-LCNetV2 series model training Benchmark evaluation process can be referred to [PaddleClas-TIPC](https://github.com/paddlepaddle/paddleclas/blob/release%2F2.5/test_tipc/docs/benchmark_train.md).
## 2. Inference Benchmark
### 2.1 Environment
* The following tests are based on the Intel Xeon Gold 6271C and the OpenVINO 2021.4.2;
* The precision type is FP32;
### 2.2 Dataset
The PP-LCNetV2 series models were evaluated using the ImageNet1k validation dataset.
### 2.3 Metrics
| Model | Latency(ms) |
|:--:|:--:|
| <b>PPLCNetV2_base<b> | <b>4.32<b> |
| <b>PPLCNetV2_base_ssld<b> | <b>4.32<b> |
## 3. Instructions
For more information please refer to [PaddleClas-PPLCNetV2](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.5/docs/en/models/PP-LCNetV2_en.md).
# 模型列表
|模型名称 | 模型简介 | 模型体积 | 输入尺寸 | 下载地址 |
|---|---|---|---|---|
| PPLCNetV2_base | 图像分类 | | 224 | [推理模型](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPLCNetV2_base_infer.tar)/[预训练模型](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/legendary_models/PPLCNetV2_base_pretrained.pdparams) |
| PPLCNetV2_base_ssld | 图像分类 | | 224 | [推理模型](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPLCNetV2_base_ssld_infer.tar)/[预训练模型](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/legendary_models/PPLCNetV2_base_ssld_pretrained.pdparams) |
\ No newline at end of file
# List of Models
| Model | Introduction | Model Size | Input size | Download link |
|---|---|---|---|---|
| PPLCNetV2_base | Image classification | | 224 | [Inference](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPLCNetV2_base_infer.tar)/[Pretrained](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/legendary_models/PPLCNetV2_base_pretrained.pdparams) |
| PPLCNetV2_base_ssld | Image classification | | 224 | [Inference](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPLCNetV2_base_ssld_infer.tar)/[Pretrained](https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/legendary_models/PPLCNetV2_base_ssld_pretrained.pdparams) |
---
Model_Info:
name: "PP-LCNetv2"
description: "面向Intel CPU端的轻量级卷积神经网络"
description_en: "A Lightweight Convolutional Neural Network for Intel CPU"
icon: ""
from_repo: "https://github.com/paddlepaddle/paddleclas"
Task:
- tag_en: "Computer Vision"
tag: "计算机视觉"
sub_tag_en: "Image Classification"
sub_tag: "图像分类"
Example: ""
Datasets: "ImageNet1k"
Pulisher: "Baidu"
License: "apache.2.0"
Paper: ""
IfTraining: 1
IfOnlineDemo: 1
\ No newline at end of file
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 1. PP-LCNetV2 模型简介\n",
"PP-LCNetV2 系列模型是 PaddleCV 团队提出的轻量级卷积神经网络模型,该系列模型基于 PP-LCNetv1 改进而来,更为侧重较高的模型性能,在 ImageNet1k 数据集上可以达到 77.04% 的精度,同时推理延时在 4.32ms 左右。另外,考虑到产业界大量使用 OpenVINO 推理框架的情况,PP-LCNetV2 系列模型针对 Intel CPU 硬件平台结合 OpenVINO 推理框架特别优化。\n",
"\n",
"PP-LCNetV2 系列模型基于 PaddleClas 开发、训练,更多关于 PP-LCNetV2 系列模型的更多信息,可以从 [PaddleClas-PPLCNetV2](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.5/docs/zh_CN/models/ImageNet1k/PP-LCNetV2.md) 获取。"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 2. 模型效果\n",
"\n",
"PP-LCNetV2 系列模型在 ImageNet1k 数据集上的评测指标如下所示:\n",
"\n",
"| Model | Params(M) | FLOPs(M) | Top-1 Acc(\\%) | Top-5 Acc(\\%) | Latency(ms) |\n",
"|:--:|:--:|:--:|:--:|:--:|:--:|:--:|:--:|\n",
"| <b>PPLCNetV2_base<b> | <b>6.6<b> | <b>604<b> | <b>77.04<b> | <b>93.27<b> | <b>4.32<b> |\n",
"| <b>PPLCNetV2_base_ssld<b> | <b>6.6<b> | <b>604<b> | <b>80.07<b> | <b>94.87<b> | <b>4.32<b> |\n",
"\n",
"其中 `_ssld` 表示使用 `SSLD 蒸馏`后的模型。关于 `SSLD蒸馏` 的内容,详情 [SSLD 蒸馏](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.5/docs/zh_CN/training/advanced/knowledge_distillation.md)。\n",
"\n",
"与同量级其他轻量级网络的性能对比:\n",
"\n",
"| Model | Params(M) | FLOPs(M) | Top-1 Acc(\\%) | Top-5 Acc(\\%) | Latency(ms) |\n",
"|:--:|:--:|:--:|:--:|:--:|:--:|\n",
"| MobileNetV3_Large_x1_25 | 7.4 | 714 | 76.4 | 93.00 | 5.19 |\n",
"| PPLCNetv1_x2_5 | 9 | 906 | 76.60 | 93.00 | 7.25 |\n",
"| <b>PPLCNetV2_base<b> | <b>6.6<b> | <b>604<b> | <b>77.04<b> | <b>93.27<b> | <b>4.32<b> |\n",
"| <b>PPLCNetV2_base_ssld<b> | <b>6.6<b> | <b>604<b> | <b>80.07<b> | <b>94.87<b> | <b>4.32<b> |"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 3. 模型快速使用\n",
"\n",
"### 3.1 模型推理:\n",
"* 安装相关 Python 包\n",
"\n",
"(不在Jupyter Notebook上运行时需要将\"!\"去掉。)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"如果您的机器安装了 CUDA9、CUDA10 或 CUDA11,请运行以下命令安装 paddle"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!pip install paddlepaddle-gpu"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"您的机器是CPU,请运行以下命令安装 paddle"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!pip install paddlepaddle"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"安装 paddleclas"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
},
"scrolled": true,
"tags": []
},
"outputs": [],
"source": [
"!pip install paddleclas"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* 快速体验\n",
"\n",
"恭喜! 您已经成功安装了 PaddleClas,接下来快速体验图像分类效果。"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true,
"tags": []
},
"outputs": [],
"source": [
"!wget https://gitee.com/paddlepaddle/PaddleClas/raw/release/2.5/docs/images/inference_deployment/whl_demo.jpg\n",
"!paddleclas --model_name=PPLCNetV2_base --infer_imgs=\"./whl_demo.jpg\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"上述命令的运行结果如下所示:\n",
"\n",
"class_ids: [8, 7, 86, 82, 83], scores: [0.8859, 0.07156, 0.00588, 0.00047, 0.00034], label_names: ['hen', 'cock', 'partridge', 'ruffed grouse, partridge, Bonasa umbellus', 'prairie chicken, prairie grouse, prairie fowl'], filename: docs/images/inference_deployment/whl_demo.jpg\n",
"Predict complete"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 3.2 模型训练\n",
"* PP-LCNetV2 系列模型基于 PaddleClas 实现,模型训练的具体信息请参考[模型训练、评估和预测](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.5/docs/zh_CN/models/ImageNet1k/PP-LCNetV2.md#3-%E6%A8%A1%E5%9E%8B%E8%AE%AD%E7%BB%83%E8%AF%84%E4%BC%B0%E5%92%8C%E9%A2%84%E6%B5%8B)。"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 4. 模型原理"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 4.1 总体结构\n",
"\n",
"PP-LCNetV2 网络的整体结构如下图所示:\n",
"\n",
"<div align=\"center\">\n",
"<img src=\"https://user-images.githubusercontent.com/12560511/200776415-19f7f09d-f8e9-4b64-bbcd-72ac418c23cf.png\" width = \"80%\" />\n",
"</div>\n",
"\n",
"### 4.2 模型细节\n",
"\n",
"PP-LCNetV2 模型是在 PP-LCNetV1 的基础上优化而来,主要使用重参数化策略组合了不同大小卷积核的深度卷积,并优化了点卷积、Shortcut等。\n",
"\n",
"#### 4.2.1 Rep 策略\n",
"\n",
"卷积核的大小决定了卷积层感受野的大小,通过组合使用不同大小的卷积核,能够获取不同尺度的特征,因此 PPLCNetV2 在 Stage4、Stage5 中,在同一层组合使用 kernel size 分别为 5、3、1 的 DW 卷积,同时为了避免对模型效率的影响,使用重参数化(Re parameterization,Rep)策略对同层的 DW 卷积进行融合,如下图所示。\n",
"\n",
"<div align=\"center\">\n",
"<img src=\"https://user-images.githubusercontent.com/12560511/201664156-be8f5dc6-5345-436a-962e-079139f378d5.png\" width = \"80%\" />\n",
"</div>\n",
"\n",
"#### 4.2.2 PW 卷积\n",
"\n",
"深度可分离卷积通常由一层 DW 卷积和一层 PW 卷积组成,用以替换标准卷积,为了使深度可分离卷积具有更强的拟合能力,我们尝试使用两层 PW 卷积,同时为了控制模型效率不受影响,两层 PW 卷积设置为:第一个在通道维度对特征图压缩,第二个再通过放大还原特征图通道,如下图所示。通过实验发现,该策略能够显著提高模型性能,同时为了平衡对模型效率带来的影响,PPLCNetV2 仅在 Stage4 中使用了该策略。\n",
"\n",
"<div align=\"center\">\n",
"<img src=\"https://user-images.githubusercontent.com/12560511/201664376-e3cdd4ac-0767-4773-a6cc-b6885796bc1e.png\" width = \"80%\" />\n",
"</div>\n",
"\n",
"#### 4.2.3 Shortcut\n",
"\n",
"残差结构(residual)自提出以来,被诸多模型广泛使用,但在轻量级卷积神经网络中,由于残差结构所带来的元素级(element-wise)加法操作,会对模型的速度造成影响,我们在 PP-LCNetV2 中,以 Stage 为单位实验了残差结构对模型的影响,发现残差结构的使用并非一定会带来性能的提高,因此 PPLCNetV2 仅在最后一个 Stage 中的使用了残差结构:在 Block 中增加 Shortcut,如下图所示。\n",
"\n",
"<div align=\"center\">\n",
"<img src=\"https://user-images.githubusercontent.com/12560511/201664472-42139a13-28a1-43b9-92d7-d355f10ed56d.png\" width = \"80%\" />\n",
"</div>\n",
"\n",
"#### 4.2.4 激活函数\n",
"\n",
"在目前的轻量级卷积神经网络中,ReLU、Hard-Swish 激活函数最为常用,虽然在模型性能方面,Hard-Swish 通常更为优秀,然而我们发现部分推理平台对于 Hard-Swish 激活函数的效率优化并不理想,因此为了兼顾通用性,PP-LCNetV2 默认使用了 ReLU 激活函数,并且我们测试发现,ReLU 激活函数对于较大模型的性能影响较小。\n",
"\n",
"\n",
"#### 4.2.5 SE 模块\n",
"\n",
"虽然 SE 模块能够显著提高模型性能,但其对模型速度的影响同样不可忽视,在 PP-LCNetV1 中,我们发现在模型中后部使用 SE 模块能够获得最大化的收益。在 PP-LCNetV2 的优化过程中,我们以 Stage 为单位对 SE 模块的位置做了进一步实验,并发现在 Stage4 中使用能够取得更好的平衡。"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 5. 注意事项\n",
"PP-LCNetV2 系列模型在 Intel CPU 端延时测试基于 Intel Xeon Gold 6271C 硬件平台完成,推理框架使用 OpenVINO 2021.4.2,推理 batch size 为 1,线程数为 10。"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 6. 相关论文以及引用信息"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.8"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 1. PP-LCNetV2 Introduction\n",
"PP-LCNetV2 series model is a lightweight convolution neural network model proposed by PaddleCV team. This series model is improved based on PP-LCNetv1 and focuses more on higher model performance. The accuracy of this model can reach 77.04% on the ImageNet1k dataset. Meanwhile, the inference latency is about 4.32ms. In addition, considering the extensive use of OpenVINO inference framework in the industry, PP-LCNetV2 series model is specially optimized for Intel CPU combined with OpenVINO.\n",
"\n",
"The PP-LCNetV2 series model was developed and trained based on PaddleClas. For more information on PP-LCNet series models, see [PaddleClas-PPLCNetV2](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.5/docs/en/models/PP-LCNetV2_en.md)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 2. Performance\n",
"\n",
"The evaluation results of PP-LCNetV2 series models on ImageNet1k dataset are shown as follows:\n",
"\n",
"| Model | Params(M) | FLOPs(M) | Top-1 Acc(\\%) | Top-5 Acc(\\%) | Latency(ms) |\n",
"|:--:|:--:|:--:|:--:|:--:|:--:|:--:|:--:|\n",
"| <b>PPLCNetV2_base<b> | <b>6.6<b> | <b>604<b> | <b>77.04<b> | <b>93.27<b> | <b>4.32<b> |\n",
"| <b>PPLCNetV2_base_ssld<b> | <b>6.6<b> | <b>604<b> | <b>80.07<b> | <b>94.87<b> | <b>4.32<b> |\n",
"\n",
"`_ssld` represents the model after using `SSLD distillation`. For details about `SSLD distillation`, see [SSLD distillation](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.5/docs/en/advanced_tutorials/knowledge_distillation_en.md).\n",
"\n",
"Compared with other lightweight networks:\n",
"\n",
"| Model | Params(M) | FLOPs(M) | Top-1 Acc(\\%) | Top-5 Acc(\\%) | Latency(ms) |\n",
"|:--:|:--:|:--:|:--:|:--:|:--:|\n",
"| MobileNetV3_Large_x1_25 | 7.4 | 714 | 76.4 | 93.00 | 5.19 |\n",
"| PPLCNetv1_x2_5 | 9 | 906 | 76.60 | 93.00 | 7.25 |\n",
"| <b>PPLCNetV2_base<b> | <b>6.6<b> | <b>604<b> | <b>77.04<b> | <b>93.27<b> | <b>4.32<b> |\n",
"| <b>PPLCNetV2_base_ssld<b> | <b>6.6<b> | <b>604<b> | <b>80.07<b> | <b>94.87<b> | <b>4.32<b> |"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 3. Quick Start\n",
"\n",
"### 3.1 Inference:\n",
"* Install the relevant Python packages\n",
"\n",
"(Remove the\"!\" when not running on the Jupyter Notebook)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Run the following command to install if CUDA9、CUDA10 or CUDA11 is available."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!pip install paddlepaddle-gpu"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Run the following command to install if GPU device is unavailable."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!pip install paddlepaddle"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Install paddleclas"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
},
"scrolled": true,
"tags": []
},
"outputs": [],
"source": [
"!pip install paddleclas"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* Quick Start\n",
"\n",
"Congratulations! Now that you've successfully installed PaddleClas, you can experience the image classification effects."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true,
"tags": []
},
"outputs": [],
"source": [
"!wget https://gitee.com/paddlepaddle/PaddleClas/raw/release/2.5/docs/images/inference_deployment/whl_demo.jpg\n",
"!paddleclas --model_name=PPLCNetV2_base --infer_imgs=\"./whl_demo.jpg\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The above command results are as follows:\n",
"\n",
"class_ids: [8, 7, 86, 82, 83], scores: [0.8859, 0.07156, 0.00588, 0.00047, 0.00034], label_names: ['hen', 'cock', 'partridge', 'ruffed grouse, partridge, Bonasa umbellus', 'prairie chicken, prairie grouse, prairie fowl'], filename: docs/images/inference_deployment/whl_demo.jpg\n",
"Predict complete"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 3.2 Training\n",
"* PP-LCNetV2 series models are implemented based on PaddleClas. For details of model training, please refer to[Training, Evaluation and Inference](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.5/docs/en/models/PP-LCNetV2_en.md)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 4. Algorithm"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 4.1 Overall Structure\n",
"\n",
"The overall structure of the network is shown in the figure below:\n",
"\n",
"<div align=\"center\">\n",
"<img src=\"https://user-images.githubusercontent.com/12560511/200776415-19f7f09d-f8e9-4b64-bbcd-72ac418c23cf.png\" width = \"80%\" />\n",
"</div>\n",
"\n",
"### 4.2 Model Details\n",
"\n",
"PP-LCNetV2 model is optimized on the basis of PP-LCNetV1. It mainly uses the reparameterization strategy to combine the depthwise convolutions with different kernel sizes, and optimize the point convolution and Shortcut, etc.\n",
"\n",
"#### 4.2.1 Re-parameterization\n",
"\n",
"The size of the convolution kernel affects the size of the model's receptive field, which affects the model's ability to capture more global or local features. In order to help the model build different scales features, we use 5\\*5, 3\\*3 and 1\\*1 size convolution kernel. The details is shown in the figure below.\n",
"\n",
"<div align=\"center\">\n",
"<img src=\"https://user-images.githubusercontent.com/12560511/201664156-be8f5dc6-5345-436a-962e-079139f378d5.png\" width = \"80%\" />\n",
"</div>\n",
"\n",
"#### 4.2.2 PW Conv\n",
"\n",
"The depthwise separable convolution usually consists of a layer of DW convolution and a layer of PW convolution to replace the standard convolution. In order to make the depth separable convolution have a stronger fitting ability, we try to use two layers of PW convolution. Meanwhile, in order to control the efficiency of the model, the two-layer PW convolution is set as: The first squeeze the feature map on the channel dimension, and the second expand to restore the feature map channel, as shown in the figure below. Experiments show that this strategy can significantly improve model performance. Meanwhile, in order to balance the impact on model efficiency, PPLCNetV2 only uses this strategy in Stage4.\n",
"\n",
"<div align=\"center\">\n",
"<img src=\"https://user-images.githubusercontent.com/12560511/201664376-e3cdd4ac-0767-4773-a6cc-b6885796bc1e.png\" width = \"80%\" />\n",
"</div>\n",
"\n",
"#### 4.2.3 Shortcut\n",
"\n",
"The residual structure has been widely used by many models since it was proposed, but in lightweight convolutional neural networks, the elementwise addition operation brought by the residual structure will affect the speed of the model. We experimented on the influence of shortcut on the model at different stage. Finally, we only used Shortcut in the last block, as shown in the figure below.\n",
"\n",
"<div align=\"center\">\n",
"<img src=\"https://user-images.githubusercontent.com/12560511/201664472-42139a13-28a1-43b9-92d7-d355f10ed56d.png\" width = \"80%\" />\n",
"</div>\n",
"\n",
"#### 4.2.4 Activation Function\n",
"\n",
"In the current lightweight convolutional neural networks, ReLU and Hard-Swish activation functions are most commonly used. Although Hard-Swish is usually better in terms of model performance, we found that some inference platforms have unsatisfactory efficiency optimization for Hard-Swish activation functions. Therefore, in order to give consideration to universality, PP-LCNetV2 uses the ReLU activation function by default, and our tests show that the ReLU activation function has little impact on the performance of larger models.\n",
"\n",
"\n",
"#### 4.2.5 SE\n",
"\n",
"Although SE module can significantly improve model performance, its impact on model speed should not be ignored. In PP-LCNetV1, we found that the use of SE module in the back of the model can obtain the maximum benefit. In the optimization process of PP-LCNetV2, we did further experiments on the position of SE module by Stage, and found that better balance could be achieved by using it in Stage4."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 5. Notes\n",
"The inference speed of PP-LCNet series model were tested at Intel Xeon Gold 6271C CPU with PaddlePaddle inference framework, the batch size was 1 and the number of threads was 10."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 6. Relevant Papers and Citations"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.8"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册