{ "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", "| PPHGNet_tiny | 79.83 | 95.04 | 1.77 |\n", "| PPHGNet_tiny_ssld | 81.95 | 96.12 | 1.77 |\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", "| PPHGNet_small | 81.51| 95.82 | 2.52 |\n", "| PPHGNet_small_ssld | 83.82| 96.81 | 2.52 |\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", "| PPHGNet_base_ssld | 85.00| 97.35 | 5.97 |" ] }, { "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": { "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", "
\n", "\n", "
\n", "\n", "其中,PP-HGNet是由多个HG-Block组成,HG-Block的细节如下:\n", "\n", "
\n", "\n", "
" ] }, { "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 }