Merge branch 'develop' into add_cpp_serving
commit
7cd3a5b027
|
@ -53,6 +53,7 @@ PP-ShiTu图像识别快速体验:[点击这里](./docs/zh_CN/quick_start/quick
|
|||
## 文档教程
|
||||
- [环境准备](docs/zh_CN/installation/install_paddleclas.md)
|
||||
- [PULC超轻量图像分类实用方案](docs/zh_CN/PULC/PULC_train.md)
|
||||
- [超轻量图像分类快速体验](docs/zh_CN/PULC/PULC_quickstart.md)
|
||||
- [超轻量图像分类模型库](docs/zh_CN/PULC/PULC_model_list.md)
|
||||
- [PULC有人/无人分类模型](docs/zh_CN/PULC/PULC_person_exists.md)
|
||||
- [PULC人体属性识别模型](docs/zh_CN/PULC/PULC_person_attribute.md)
|
||||
|
|
|
@ -7,8 +7,9 @@
|
|||
|
||||
- [1. 模型和应用场景介绍](#1)
|
||||
- [2. 模型快速体验](#2)
|
||||
- [2.1 安装 paddleclas](#2.1)
|
||||
- [2.2 预测](#2.2)
|
||||
- [2.1 安装 paddlepaddle](#2.1)
|
||||
- [2.2 安装 paddleclas](#2.2)
|
||||
- [2.3 预测](#2.3)
|
||||
- [3. 模型训练、评估和预测](#3)
|
||||
- [3.1 环境配置](#3.1)
|
||||
- [3.2 数据准备](#3.2)
|
||||
|
@ -59,35 +60,56 @@
|
|||
|
||||
* `Tpr`指标的介绍可以参考 [3.2 小节](#3.2)的备注部分,延时是基于 Intel(R) Xeon(R) Gold 6148 CPU @ 2.40GHz 测试得到,开启 MKLDNN 加速策略,线程数为10。
|
||||
* 关于PP-LCNet的介绍可以参考[PP-LCNet介绍](../models/PP-LCNet.md),相关论文可以查阅[PP-LCNet paper](https://arxiv.org/abs/2109.15099)。
|
||||
|
||||
|
||||
|
||||
|
||||
<a name="2"></a>
|
||||
|
||||
## 2. 模型快速体验
|
||||
|
||||
<a name="2.1"></a>
|
||||
|
||||
### 2.1 安装 paddlepaddle
|
||||
|
||||
- 您的机器安装的是 CUDA9 或 CUDA10,请运行以下命令安装
|
||||
|
||||
### 2.1 安装 paddleclas
|
||||
```bash
|
||||
python3 -m pip install paddlepaddle-gpu -i https://mirror.baidu.com/pypi/simple
|
||||
```
|
||||
|
||||
使用如下命令快速安装 paddlepaddle, paddleclas
|
||||
- 您的机器是CPU,请运行以下命令安装
|
||||
|
||||
```bash
|
||||
python3 -m pip install paddlepaddle -i https://mirror.baidu.com/pypi/simple
|
||||
```
|
||||
|
||||
更多的版本需求,请参照[飞桨官网安装文档](https://www.paddlepaddle.org.cn/install/quick)中的说明进行操作。
|
||||
|
||||
<a name="2.2"></a>
|
||||
|
||||
### 2.2 安装 paddleclas
|
||||
|
||||
使用如下命令快速安装 paddleclas
|
||||
|
||||
```
|
||||
pip3 install paddlepaddle paddleclas
|
||||
pip3 install paddleclas
|
||||
```
|
||||
<a name="2.2"></a>
|
||||
|
||||
<a name="2.3"></a>
|
||||
|
||||
### 2.2 预测
|
||||
### 2.3 预测
|
||||
|
||||
点击[这里](https://paddleclas.bj.bcebos.com/data/PULC/pulc_demo_imgs.zip)下载 demo 数据并解压,然后在终端中切换到相应目录。
|
||||
|
||||
* 使用命令行快速预测
|
||||
|
||||
```bash
|
||||
paddleclas --model_name=car_exists --infer_imgs=deploy/images/PULC/car_exists/objects365_00001507.jpeg
|
||||
paddleclas --model_name=car_exists --infer_imgs=pulc_demo_imgs/car_exists/objects365_00001507.jpeg
|
||||
```
|
||||
|
||||
结果如下:
|
||||
```
|
||||
>>> result
|
||||
class_ids: [1], scores: [0.9871138], label_names: ['contains_vehicle'], filename: deploy/images/PULC/car_exists/objects365_00001507.jpeg
|
||||
class_ids: [1], scores: [0.9871138], label_names: ['contains_car'], filename: pulc_demo_imgs/car_exists/objects365_00001507.jpeg
|
||||
Predict complete!
|
||||
```
|
||||
|
||||
|
@ -98,7 +120,7 @@ Predict complete!
|
|||
```python
|
||||
import paddleclas
|
||||
model = paddleclas.PaddleClas(model_name="car_exists")
|
||||
result = model.predict(input_data="deploy/images/PULC/car_exists/objects365_00001507.jpeg")
|
||||
result = model.predict(input_data="pulc_demo_imgs/car_exists/objects365_00001507.jpeg")
|
||||
print(next(result))
|
||||
```
|
||||
|
||||
|
@ -106,8 +128,9 @@ print(next(result))
|
|||
|
||||
```
|
||||
>>> result
|
||||
[{'class_ids': [1], 'scores': [0.9871138], 'label_names': ['contains_vehicle'], 'filename': 'deploy/images/PULC/car_exists/objects365_00001507.jpeg'}]
|
||||
[{'class_ids': [1], 'scores': [0.9871138], 'label_names': ['contains_car'], 'filename': 'pulc_demo_imgs/car_exists/objects365_00001507.jpeg'}]
|
||||
```
|
||||
|
||||
|
||||
<a name="3"></a>
|
||||
|
||||
|
@ -411,10 +434,10 @@ python3.7 python/predict_cls.py -c configs/PULC/car_exists/inference_car_exists.
|
|||
|
||||
```
|
||||
objects365_00001507.jpeg: class id(s): [1], score(s): [0.99], label_name(s): ['contains_car']
|
||||
objects365_00001521.jpeg: class id(s): [0], score(s): [0.99], label_name(s): ['nocar']
|
||||
objects365_00001521.jpeg: class id(s): [0], score(s): [0.99], label_name(s): ['no_car']
|
||||
```
|
||||
|
||||
其中,`contains_car` 表示该图里存在车,`nocar` 表示该图里不存在车。
|
||||
其中,`contains_car` 表示该图里存在车,`no_car` 表示该图里不存在车。
|
||||
|
||||
<a name="6.3"></a>
|
||||
|
||||
|
|
|
@ -4,8 +4,9 @@
|
|||
|
||||
- [1. 模型和应用场景介绍](#1)
|
||||
- [2. 模型快速体验](#2)
|
||||
- [2.1 安装 paddleclas](#2.1)
|
||||
- [2.2 预测](#2.2)
|
||||
- [2.1 安装 paddlepaddle](#2.1)
|
||||
- [2.2 安装 paddleclas](#2.2)
|
||||
- [2.3 预测](#2.3)
|
||||
- [3. 模型训练、评估和预测](#3)
|
||||
- [3.1 环境配置](#3.1)
|
||||
- [3.2 数据准备](#3.2)
|
||||
|
@ -58,52 +59,72 @@
|
|||
|
||||
## 2. 模型快速体验
|
||||
|
||||
<a name="2.1"></a>
|
||||
<a name="2.1"></a>
|
||||
|
||||
### 2.1 安装 paddlepaddle
|
||||
|
||||
- 您的机器安装的是 CUDA9 或 CUDA10,请运行以下命令安装
|
||||
|
||||
### 2.1 安装 paddleclas
|
||||
```bash
|
||||
python3 -m pip install paddlepaddle-gpu -i https://mirror.baidu.com/pypi/simple
|
||||
```
|
||||
|
||||
- 您的机器是CPU,请运行以下命令安装
|
||||
|
||||
```bash
|
||||
python3 -m pip install paddlepaddle -i https://mirror.baidu.com/pypi/simple
|
||||
```
|
||||
|
||||
更多的版本需求,请参照[飞桨官网安装文档](https://www.paddlepaddle.org.cn/install/quick)中的说明进行操作。
|
||||
|
||||
<a name="2.2"></a>
|
||||
|
||||
### 2.2 安装 paddleclas
|
||||
|
||||
使用如下命令快速安装 paddleclas
|
||||
|
||||
```
|
||||
```
|
||||
pip3 install paddleclas
|
||||
```
|
||||
```
|
||||
|
||||
<a name="2.3"></a>
|
||||
|
||||
<a name="2.2"></a>
|
||||
### 2.3 预测
|
||||
|
||||
点击[这里](https://paddleclas.bj.bcebos.com/data/PULC/pulc_demo_imgs.zip)下载 demo 数据并解压,然后在终端中切换到相应目录。
|
||||
|
||||
### 2.2 预测
|
||||
* 使用命令行快速预测
|
||||
|
||||
- 使用命令行快速预测
|
||||
|
||||
```
|
||||
paddleclas --model_name=language_classification --infer_imgs=deploy/images/PULC/language_classification/word_35404.png
|
||||
```bash
|
||||
paddleclas --model_name=language_classification --infer_imgs=pulc_demo_imgs/language_classification/word_35404.png
|
||||
```
|
||||
|
||||
结果如下:
|
||||
|
||||
```
|
||||
>>> result
|
||||
class_ids: [4, 6], scores: [0.88672, 0.01434], label_names: ['japan', 'korean'], filename: deploy/images/PULC/language_classification/word_35404.png
|
||||
class_ids: [4, 6], scores: [0.88672, 0.01434], label_names: ['japan', 'korean'], filename: pulc_demo_imgs/language_classification/word_35404.png
|
||||
Predict complete!
|
||||
```
|
||||
|
||||
**备注**: 更换其他预测的数据时,只需要改变 `--infer_imgs=xx` 中的字段即可,支持传入整个文件夹。
|
||||
|
||||
- 在 Python 代码中预测
|
||||
|
||||
```
|
||||
* 在 Python 代码中预测
|
||||
```python
|
||||
import paddleclas
|
||||
model = paddleclas.PaddleClas(model_name="language_classification")
|
||||
result = model.predict(input_data="deploy/images/PULC/language_classification/word_35404.png")
|
||||
result = model.predict(input_data="pulc_demo_imgs/language_classification/word_35404.png")
|
||||
print(next(result))
|
||||
```
|
||||
|
||||
**备注**:`model.predict()` 为可迭代对象(`generator`),因此需要使用 `next()` 函数或 `for` 循环对其迭代调用。每次调用将以 `batch_size` 为单位进行一次预测,并返回预测结果, 默认 `batch_size` 为 1,如果需要更改 `batch_size`,实例化模型时,需要指定 `batch_size`,如 `model = paddleclas.PaddleClas(model_name="language_classification", batch_size=2)`, 使用默认的代码返回结果示例如下:
|
||||
**备注**:`model.predict()` 为可迭代对象(`generator`),因此需要使用 `next()` 函数或 `for` 循环对其迭代调用。每次调用将以 `batch_size` 为单位进行一次预测,并返回预测结果, 默认 `batch_size` 为 1,如果需要更改 `batch_size`,实例化模型时,需要指定 `batch_size`,如 `model = paddleclas.PaddleClas(model_name="language_classification", batch_size=2)`, 使用默认的代码返回结果示例如下:
|
||||
|
||||
```
|
||||
>>> result
|
||||
[{'class_ids': [4, 6], 'scores': [0.88672, 0.01434], 'label_names': ['japan', 'korean'], 'filename': '/deploy/images/PULC/language_classification/word_35404.png'}]
|
||||
[{'class_ids': [4, 6], 'scores': [0.88672, 0.01434], 'label_names': ['japan', 'korean'], 'filename': 'pulc_demo_imgs/language_classification/word_35404.png'}]
|
||||
```
|
||||
|
||||
|
||||
<a name="3"></a>
|
||||
|
||||
## 3. 模型训练、评估和预测
|
||||
|
@ -112,7 +133,7 @@ print(next(result))
|
|||
|
||||
### 3.1 环境配置
|
||||
|
||||
- 安装:请先参考 [Paddle 安装教程](../installation/install_paddle.md) 以及 [PaddleClas 安装教程](../installation/install_paddleclas.md) 配置 PaddleClas 运行环境。
|
||||
* 安装:请先参考文档 [环境准备](../installation/install_paddleclas.md) 配置 PaddleClas 运行环境。
|
||||
|
||||
<a name="3.2"></a>
|
||||
|
||||
|
@ -134,7 +155,7 @@ print(next(result))
|
|||
|
||||
`0` 表示阿拉伯语(arabic);`1` 表示中文繁体(chinese_cht);`2` 表示斯拉夫语(cyrillic);`3` 表示梵文(devanagari);`4` 表示日语(japan);`5` 表示卡纳达文(ka);`6` 表示韩语(korean);`7` 表示泰米尔文(ta);`8` 表示泰卢固文(te);`9` 表示拉丁语(latin)。
|
||||
|
||||
在 Multi-lingual scene text detection and recognition 数据集中,仅包含了阿拉伯语、日语、韩语和拉丁语数据,这里分别将4个语种的数据各抽取120张作为本案例的训练数据,50张作为测试数据,以及30张作为补充数据和训练数据混合用于本案例的`SKL-UGI知识蒸馏策略`实验。
|
||||
在 Multi-lingual scene text detection and recognition 数据集中,仅包含了阿拉伯语、日语、韩语和拉丁语数据,这里分别将 4 个语种的数据各抽取 1600 张作为本案例的训练数据,300 张作为测试数据,以及 400 张作为补充数据和训练数据混合用于本案例的`SKL-UGI知识蒸馏策略`实验。
|
||||
|
||||
因此,对于本案例中的demo数据集,类别为:
|
||||
|
||||
|
@ -142,7 +163,7 @@ print(next(result))
|
|||
|
||||
如果想要制作自己的多语种数据集,可以按照需求收集并整理自己任务中需要语种的数据,此处提供了经过上述方法处理好的demo数据,可以直接下载得到。
|
||||
|
||||
**备注:**语种分类任务中的图片数据需要将整图中的文字区域抠取出来,仅仅使用文本行部分作为图片数据。
|
||||
**备注:** 语种分类任务中的图片数据需要将整图中的文字区域抠取出来,仅仅使用文本行部分作为图片数据。
|
||||
|
||||
进入 PaddleClas 目录。
|
||||
|
||||
|
@ -172,13 +193,12 @@ cd ../
|
|||
└── label_list.txt
|
||||
```
|
||||
|
||||
其中`img/`存放了4种语言总计800张数据。`train_list.txt`和`test_list.txt`分别为训练集和验证集的标签文件,`label_list.txt`是4类语言分类模型对应的类别列表,`SKL-UGI知识蒸馏策略`对应的训练标签文件为`train_list_for_distill.txt`。用这些图片可以快速体验本案例中模型的训练预测过程。
|
||||
其中`img/`存放了 4 种语言总计 9200 张数据。`train_list.txt`和`test_list.txt`分别为训练集和验证集的标签文件,`label_list.txt`是 4 类语言分类模型对应的类别列表,`SKL-UGI 知识蒸馏策略`对应的训练标签文件为`train_list_for_distill.txt`。用这些图片可以快速体验本案例中模型的训练预测过程。
|
||||
|
||||
***备注:***
|
||||
|
||||
- 这里的`label_list.txt`是4类语种分类模型对应的类别列表,如果自己构造的数据集语种类别发生变化,需要自行调整。
|
||||
- 如果想要自己构造训练集和验证集,可以参考[PaddleClas分类数据集格式说明](../data_preparation/classification_dataset.md#1-数据集格式说明) 。
|
||||
- 当使用本文档中的demo数据集时,需要添加`-o Arch.class_num=4`来将模型的类别书指定为4。
|
||||
|
||||
<a name="3.3"></a>
|
||||
|
||||
|
@ -191,9 +211,12 @@ export CUDA_VISIBLE_DEVICES=0,1,2,3
|
|||
python3 -m paddle.distributed.launch \
|
||||
--gpus="0,1,2,3" \
|
||||
tools/train.py \
|
||||
-c ./ppcls/configs/PULC/language_classification/PPLCNet_x1_0.yaml
|
||||
-c ./ppcls/configs/PULC/language_classification/PPLCNet_x1_0.yaml \
|
||||
-o Arch.class_num=4
|
||||
```
|
||||
|
||||
- 由于本文档中的demo数据集的类别数量为 4,所以需要添加`-o Arch.class_num=4`来将模型的类别数量指定为4。
|
||||
|
||||
<a name="3.4"></a>
|
||||
|
||||
### 3.4 模型评估
|
||||
|
@ -203,7 +226,8 @@ python3 -m paddle.distributed.launch \
|
|||
```bash
|
||||
python3 tools/eval.py \
|
||||
-c ./ppcls/configs/PULC/language_classification/PPLCNet_x1_0.yaml \
|
||||
-o Global.pretrained_model="output/PPLCNet_x1_0/best_model"
|
||||
-o Global.pretrained_model="output/PPLCNet_x1_0/best_model" \
|
||||
-o Arch.class_num=4
|
||||
```
|
||||
|
||||
其中 `-o Global.pretrained_model="output/PPLCNet_x1_0/best_model"` 指定了当前最佳权重所在的路径,如果指定其他权重,只需替换对应的路径即可。
|
||||
|
@ -217,7 +241,8 @@ python3 tools/eval.py \
|
|||
```bash
|
||||
python3 tools/infer.py \
|
||||
-c ./ppcls/configs/PULC/language_classification/PPLCNet_x1_0.yaml \
|
||||
-o Global.pretrained_model="output/PPLCNet_x1_0/best_model"
|
||||
-o Global.pretrained_model="output/PPLCNet_x1_0/best_model" \
|
||||
-o Arch.class_num=4
|
||||
```
|
||||
|
||||
输出结果如下:
|
||||
|
@ -253,8 +278,9 @@ export CUDA_VISIBLE_DEVICES=0,1,2,3
|
|||
python3 -m paddle.distributed.launch \
|
||||
--gpus="0,1,2,3" \
|
||||
tools/train.py \
|
||||
-c ./ppcls/configs/PULC/language_classification/PPLCNet/PPLCNet_x1_0.yaml \
|
||||
-o Arch.name=ResNet101_vd
|
||||
-c ./ppcls/configs/PULC/language_classification/PPLCNet_x1_0.yaml \
|
||||
-o Arch.name=ResNet101_vd \
|
||||
-o Arch.class_num=4
|
||||
```
|
||||
|
||||
当前教师模型最好的权重保存在`output/ResNet101_vd/best_model.pdparams`。
|
||||
|
@ -273,7 +299,8 @@ python3 -m paddle.distributed.launch \
|
|||
--gpus="0,1,2,3" \
|
||||
tools/train.py \
|
||||
-c ./ppcls/configs/PULC/language_classification/PPLCNet_x1_0_distillation.yaml \
|
||||
-o Arch.models.0.Teacher.pretrained=output/ResNet101_vd/best_model
|
||||
-o Arch.models.0.Teacher.pretrained=output/ResNet101_vd/best_model \
|
||||
-o Arch.class_num=4
|
||||
```
|
||||
|
||||
当前模型最好的权重保存在`output/DistillationModel/best_model_student.pdparams`。
|
||||
|
|
|
@ -7,6 +7,9 @@
|
|||
|
||||
- [1. 模型和应用场景介绍](#1)
|
||||
- [2. 模型快速体验](#2)
|
||||
- [2.1 安装 paddlepaddle](#2.1)
|
||||
- [2.2 安装 paddleclas](#2.2)
|
||||
- [2.3 预测](#2.3)
|
||||
- [3. 模型训练、评估和预测](#3)
|
||||
- [3.1 环境配置](#3.1)
|
||||
- [3.2 数据准备](#3.2)
|
||||
|
@ -59,37 +62,55 @@
|
|||
* 关于PP-LCNet的介绍可以参考[PP-LCNet介绍](../models/PP-LCNet.md),相关论文可以查阅[PP-LCNet paper](https://arxiv.org/abs/2109.15099)。
|
||||
|
||||
|
||||
<a name="2"></a>
|
||||
|
||||
## 2. 模型快速体验
|
||||
|
||||
<a name="2"></a>
|
||||
|
||||
## 2. 模型快速体验
|
||||
|
||||
<a name="2.1"></a>
|
||||
|
||||
### 2.1 安装 paddlepaddle
|
||||
|
||||
- 您的机器安装的是 CUDA9 或 CUDA10,请运行以下命令安装
|
||||
|
||||
### 2.1 安装 paddleclas
|
||||
```bash
|
||||
python3 -m pip install paddlepaddle-gpu -i https://mirror.baidu.com/pypi/simple
|
||||
```
|
||||
|
||||
使用如下命令快速安装 paddlepaddle, paddleclas
|
||||
- 您的机器是CPU,请运行以下命令安装
|
||||
|
||||
```bash
|
||||
python3 -m pip install paddlepaddle -i https://mirror.baidu.com/pypi/simple
|
||||
```
|
||||
|
||||
更多的版本需求,请参照[飞桨官网安装文档](https://www.paddlepaddle.org.cn/install/quick)中的说明进行操作。
|
||||
|
||||
<a name="2.2"></a>
|
||||
|
||||
### 2.2 安装 paddleclas
|
||||
|
||||
使用如下命令快速安装 paddleclas
|
||||
|
||||
```
|
||||
pip3 install paddlepaddle paddleclas
|
||||
```
|
||||
<a name="2.2"></a>
|
||||
pip3 install paddleclas
|
||||
```
|
||||
|
||||
<a name="2.3"></a>
|
||||
|
||||
### 2.2 预测
|
||||
### 2.3 预测
|
||||
|
||||
点击[这里](https://paddleclas.bj.bcebos.com/data/PULC/pulc_demo_imgs.zip)下载 demo 数据并解压,然后在终端中切换到相应目录。
|
||||
|
||||
* 使用命令行快速预测
|
||||
|
||||
```bash
|
||||
paddleclas --model_name=person_attribute --infer_imgs=deploy/images/PULC/person_attribute/090004.jpg
|
||||
paddleclas --model_name=person_attribute --infer_imgs=pulc_demo_imgs/person_attribute/090004.jpg
|
||||
```
|
||||
|
||||
结果如下:
|
||||
```
|
||||
>>> result
|
||||
待补充
|
||||
attributes: ['Male', 'Age18-60', 'Back', 'Glasses: False', 'Hat: False', 'HoldObjectsInFront: False', 'Backpack', 'Upper: LongSleeve UpperPlaid', 'Lower: Trousers', 'No boots'], output: [0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1], filename: pulc_demo_imgs/person_attribute/090004.jpg
|
||||
Predict complete!
|
||||
```
|
||||
|
||||
**备注**: 更换其他预测的数据时,只需要改变 `--infer_imgs=xx` 中的字段即可,支持传入整个文件夹。
|
||||
|
@ -99,7 +120,7 @@ paddleclas --model_name=person_attribute --infer_imgs=deploy/images/PULC/person_
|
|||
```python
|
||||
import paddleclas
|
||||
model = paddleclas.PaddleClas(model_name="person_attribute")
|
||||
result = model.predict(input_data="deploy/images/PULC/person_attribute/090004.jpg")
|
||||
result = model.predict(input_data="pulc_demo_imgs/person_attribute/090004.jpg")
|
||||
print(next(result))
|
||||
```
|
||||
|
||||
|
@ -107,7 +128,7 @@ print(next(result))
|
|||
|
||||
```
|
||||
>>> result
|
||||
待补充
|
||||
[{'attributes': ['Male', 'Age18-60', 'Back', 'Glasses: False', 'Hat: False', 'HoldObjectsInFront: False', 'Backpack', 'Upper: LongSleeve UpperPlaid', 'Lower: Trousers', 'No boots'], 'output': [0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1], 'filename': 'pulc_demo_imgs/person_attribute/090004.jpg'}]
|
||||
```
|
||||
|
||||
<a name="3"></a>
|
||||
|
|
|
@ -7,8 +7,9 @@
|
|||
|
||||
- [1. 模型和应用场景介绍](#1)
|
||||
- [2. 模型快速体验](#2)
|
||||
- [2.1 安装 paddleclas](#2.1)
|
||||
- [2.2 预测](#2.2)
|
||||
- [2.1 安装 paddlepaddle](#2.1)
|
||||
- [2.2 安装 paddleclas](#2.2)
|
||||
- [2.3 预测](#2.3)
|
||||
- [3. 模型训练、评估和预测](#3)
|
||||
- [3.1 环境配置](#3.1)
|
||||
- [3.2 数据准备](#3.2)
|
||||
|
@ -66,28 +67,49 @@
|
|||
## 2. 模型快速体验
|
||||
|
||||
<a name="2.1"></a>
|
||||
|
||||
### 2.1 安装 paddlepaddle
|
||||
|
||||
- 您的机器安装的是 CUDA9 或 CUDA10,请运行以下命令安装
|
||||
|
||||
### 2.1 安装 paddleclas
|
||||
```bash
|
||||
python3 -m pip install paddlepaddle-gpu -i https://mirror.baidu.com/pypi/simple
|
||||
```
|
||||
|
||||
使用如下命令快速安装 paddlepaddle, paddleclas
|
||||
- 您的机器是CPU,请运行以下命令安装
|
||||
|
||||
```bash
|
||||
python3 -m pip install paddlepaddle -i https://mirror.baidu.com/pypi/simple
|
||||
```
|
||||
|
||||
更多的版本需求,请参照[飞桨官网安装文档](https://www.paddlepaddle.org.cn/install/quick)中的说明进行操作。
|
||||
|
||||
<a name="2.2"></a>
|
||||
|
||||
### 2.2 安装 paddleclas
|
||||
|
||||
使用如下命令快速安装 paddleclas
|
||||
|
||||
```
|
||||
pip3 install paddlepaddle paddleclas
|
||||
```
|
||||
<a name="2.2"></a>
|
||||
pip3 install paddleclas
|
||||
```
|
||||
|
||||
<a name="2.3"></a>
|
||||
|
||||
### 2.2 预测
|
||||
### 2.3 预测
|
||||
|
||||
点击[这里](https://paddleclas.bj.bcebos.com/data/PULC/pulc_demo_imgs.zip)下载 demo 数据并解压,然后在终端中切换到相应目录。
|
||||
|
||||
* 使用命令行快速预测
|
||||
|
||||
```bash
|
||||
paddleclas --model_name=person_exists --infer_imgs=deploy/images/PULC/person_exists/objects365_01780782.jpg
|
||||
paddleclas --model_name=person_exists --infer_imgs=pulc_demo_imgs/person_exists/objects365_01780782.jpg
|
||||
```
|
||||
|
||||
结果如下:
|
||||
```
|
||||
>>> result
|
||||
class_ids: [0], scores: [0.9955421453341842], label_names: ['nobody'], filename: deploy/images/PULC/person_exists/objects365_01780782.jpg
|
||||
class_ids: [0], scores: [0.9955421453341842], label_names: ['nobody'], filename: pulc_demo_imgs/person_exists/objects365_01780782.jpg
|
||||
Predict complete!
|
||||
```
|
||||
|
||||
|
@ -98,7 +120,7 @@ Predict complete!
|
|||
```python
|
||||
import paddleclas
|
||||
model = paddleclas.PaddleClas(model_name="person_exists")
|
||||
result = model.predict(input_data="deploy/images/PULC/person_exists/objects365_01780782.jpg")
|
||||
result = model.predict(input_data="pulc_demo_imgs/person_exists/objects365_01780782.jpg")
|
||||
print(next(result))
|
||||
```
|
||||
|
||||
|
@ -106,7 +128,7 @@ print(next(result))
|
|||
|
||||
```
|
||||
>>> result
|
||||
[{'class_ids': [0], 'scores': [0.9955421453341842], 'label_names': ['nobody'], 'filename': 'PaddleClas/deploy/images/PULC/person_exists/objects365_01780782.jpg'}]
|
||||
[{'class_ids': [0], 'scores': [0.9955421453341842], 'label_names': ['nobody'], 'filename': 'pulc_demo_imgs/person_exists/objects365_01780782.jpg'}]
|
||||
```
|
||||
|
||||
<a name="3"></a>
|
||||
|
|
|
@ -6,6 +6,9 @@
|
|||
|
||||
- [1. 模型和应用场景介绍](#1)
|
||||
- [2. 模型快速体验](#2)
|
||||
- [2.1 安装 paddlepaddle](#2.1)
|
||||
- [2.2 安装 paddleclas](#2.2)
|
||||
- [2.3 预测](#2.3)
|
||||
- [3. 模型训练、评估和预测](#3)
|
||||
- [3.1 环境配置](#3.1)
|
||||
- [3.2 数据准备](#3.2)
|
||||
|
@ -58,52 +61,74 @@
|
|||
|
||||
* 关于PP-LCNet的介绍可以参考[PP-LCNet介绍](../models/PP-LCNet.md),相关论文可以查阅[PP-LCNet paper](https://arxiv.org/abs/2109.15099)。
|
||||
|
||||
|
||||
<a name="2"></a>
|
||||
|
||||
## 2. 模型快速体验
|
||||
|
||||
<a name="2.1"></a>
|
||||
|
||||
### 2.1 安装 paddlepaddle
|
||||
|
||||
- 您的机器安装的是 CUDA9 或 CUDA10,请运行以下命令安装
|
||||
|
||||
### 2.1 安装 paddleclas
|
||||
```bash
|
||||
python3 -m pip install paddlepaddle-gpu -i https://mirror.baidu.com/pypi/simple
|
||||
```
|
||||
|
||||
- 您的机器是CPU,请运行以下命令安装
|
||||
|
||||
```bash
|
||||
python3 -m pip install paddlepaddle -i https://mirror.baidu.com/pypi/simple
|
||||
```
|
||||
|
||||
更多的版本需求,请参照[飞桨官网安装文档](https://www.paddlepaddle.org.cn/install/quick)中的说明进行操作。
|
||||
|
||||
<a name="2.2"></a>
|
||||
|
||||
### 2.2 安装 paddleclas
|
||||
|
||||
使用如下命令快速安装 paddleclas
|
||||
|
||||
```
|
||||
pip3 install paddlepaddle paddleclas
|
||||
```
|
||||
pip3 install paddleclas
|
||||
```
|
||||
|
||||
<a name="2.3"></a>
|
||||
|
||||
<a name="2.2"></a>
|
||||
|
||||
### 2.2 预测
|
||||
### 2.3 预测
|
||||
|
||||
点击[这里](https://paddleclas.bj.bcebos.com/data/PULC/pulc_demo_imgs.zip)下载 demo 数据并解压,然后在终端中切换到相应目录。
|
||||
|
||||
* 使用命令行快速预测
|
||||
|
||||
```bash
|
||||
paddleclas --model_name=safety_helmet --infer_imgs=deploy/images/PULC/safety_helmet/safety_helmet_test_1.png
|
||||
paddleclas --model_name=safety_helmet --infer_imgs=pulc_demo_imgs/safety_helmet/safety_helmet_test_1.png
|
||||
```
|
||||
|
||||
结果如下:
|
||||
```
|
||||
>>> result
|
||||
class_ids: [1], scores: [0.9986255], label_names: ['unwearing_helmet'], filename: deploy/images/PULC/safety_helmet/safety_helmet_test_1.png
|
||||
class_ids: [1], scores: [0.9986255], label_names: ['unwearing_helmet'], filename: pulc_demo_imgs/safety_helmet/safety_helmet_test_1.png
|
||||
Predict complete!
|
||||
```
|
||||
|
||||
**备注**: 更换其他预测的数据时,只需要改变 `--infer_imgs=xxx` 中的字段即可,支持传入整个文件夹。
|
||||
**备注**: 更换其他预测的数据时,只需要改变 `--infer_imgs=xx` 中的字段即可,支持传入整个文件夹。
|
||||
|
||||
|
||||
* 在 Python 代码中预测
|
||||
```python
|
||||
import paddleclas
|
||||
model = paddleclas.PaddleClas(model_name="safety_helmet")
|
||||
result = model.predict(input_data="deploy/images/PULC/safety_helmet/safety_helmet_test_1.png")
|
||||
result = model.predict(input_data="pulc_demo_imgs/safety_helmet/safety_helmet_test_1.png")
|
||||
print(next(result))
|
||||
```
|
||||
|
||||
**备注**:`model.predict()` 为可迭代对象(`generator`),因此需要使用 `next()` 函数或 `for` 循环对其迭代调用。每次调用将以 `batch_size` 为单位进行一次预测,并返回预测结果, 默认 `batch_size` 为 1,如果需要更改 `batch_size`,实例化模型时,需要指定 `batch_size`,如 `model = paddleclas.PaddleClas(model_name="safety_helmet", batch_size=2)`, 使用上述测试代码返回结果示例如下:
|
||||
**备注**:`model.predict()` 为可迭代对象(`generator`),因此需要使用 `next()` 函数或 `for` 循环对其迭代调用。每次调用将以 `batch_size` 为单位进行一次预测,并返回预测结果, 默认 `batch_size` 为 1,如果需要更改 `batch_size`,实例化模型时,需要指定 `batch_size`,如 `model = paddleclas.PaddleClas(model_name="safety_helmet", batch_size=2)`, 使用默认的代码返回结果示例如下:
|
||||
|
||||
```
|
||||
>>> result
|
||||
[{'class_ids': [1], 'scores': [0.9986255], 'label_names': ['unwearing_helmet'], 'filename': 'deploy/images/PULC/safety_helmet/safety_helmet_test_1.png'}]
|
||||
[{'class_ids': [1], 'scores': [0.9986255], 'label_names': ['unwearing_helmet'], 'filename': 'pulc_demo_imgs/safety_helmet/safety_helmet_test_1.png'}]
|
||||
```
|
||||
|
||||
<a name="3"></a>
|
||||
|
@ -114,7 +139,7 @@ print(next(result))
|
|||
|
||||
### 3.1 环境配置
|
||||
|
||||
* 安装:请先参考 [Paddle 安装教程](../installation/install_paddle.md) 以及 [PaddleClas 安装教程](../installation/install_paddleclas.md) 配置 PaddleClas 运行环境。
|
||||
* 安装:请先参考文档 [环境准备](../installation/install_paddleclas.md) 配置 PaddleClas 运行环境。
|
||||
|
||||
<a name="3.2"></a>
|
||||
|
||||
|
@ -349,7 +374,7 @@ cd ../
|
|||
|
||||
```shell
|
||||
# 使用下面的命令使用 GPU 进行预测
|
||||
python3.7 python/predict_cls.py -c configs/PULC/safety_helmet/inference_safety_helmet.yaml
|
||||
c
|
||||
# 使用下面的命令使用 CPU 进行预测
|
||||
python3.7 python/predict_cls.py -c configs/PULC/safety_helmet/inference_safety_helmet.yaml -o Global.use_gpu=False
|
||||
```
|
||||
|
|
|
@ -4,8 +4,9 @@
|
|||
|
||||
- [1. 模型和应用场景介绍](#1)
|
||||
- [2. 模型快速体验](#2)
|
||||
- [2.1 安装 paddleclas](#2.1)
|
||||
- [2.2 预测](#2.2)
|
||||
- [2.1 安装 paddlepaddle](#2.1)
|
||||
- [2.2 安装 paddleclas](#2.2)
|
||||
- [2.3 预测](#2.3)
|
||||
- [3. 模型训练、评估和预测](#3)
|
||||
- [3.1 环境配置](#3.1)
|
||||
- [3.2 数据准备](#3.2)
|
||||
|
@ -57,50 +58,69 @@
|
|||
|
||||
## 2. 模型快速体验
|
||||
|
||||
<a name="2.1"></a>
|
||||
<a name="2.1"></a>
|
||||
|
||||
### 2.1 安装 paddlepaddle
|
||||
|
||||
- 您的机器安装的是 CUDA9 或 CUDA10,请运行以下命令安装
|
||||
|
||||
### 2.1 安装 paddleclas
|
||||
```bash
|
||||
python3 -m pip install paddlepaddle-gpu -i https://mirror.baidu.com/pypi/simple
|
||||
```
|
||||
|
||||
- 您的机器是CPU,请运行以下命令安装
|
||||
|
||||
```bash
|
||||
python3 -m pip install paddlepaddle -i https://mirror.baidu.com/pypi/simple
|
||||
```
|
||||
|
||||
更多的版本需求,请参照[飞桨官网安装文档](https://www.paddlepaddle.org.cn/install/quick)中的说明进行操作。
|
||||
|
||||
<a name="2.2"></a>
|
||||
|
||||
### 2.2 安装 paddleclas
|
||||
|
||||
使用如下命令快速安装 paddleclas
|
||||
|
||||
```
|
||||
```
|
||||
pip3 install paddleclas
|
||||
```
|
||||
```
|
||||
|
||||
<a name="2.3"></a>
|
||||
|
||||
<a name="2.2"></a>
|
||||
### 2.3 预测
|
||||
|
||||
点击[这里](https://paddleclas.bj.bcebos.com/data/PULC/pulc_demo_imgs.zip)下载 demo 数据并解压,然后在终端中切换到相应目录。
|
||||
|
||||
### 2.2 预测
|
||||
* 使用命令行快速预测
|
||||
|
||||
- 使用命令行快速预测
|
||||
|
||||
```
|
||||
paddleclas --model_name=text_image_orientation --infer_imgs=deploy/images/PULC/text_image_orientation/img_rot0_demo.jpg
|
||||
```bash
|
||||
paddleclas --model_name=text_image_orientation --infer_imgs=pulc_demo_imgs/text_image_orientation/img_rot0_demo.jpg
|
||||
```
|
||||
|
||||
结果如下:
|
||||
|
||||
```
|
||||
>>> result
|
||||
class_ids: [0, 2], scores: [0.85615, 0.05046], label_names: ['0', '180'], filename: deploy/images/PULC/text_image_orientation/img_rot0_demo.jpg
|
||||
class_ids: [0, 2], scores: [0.85615, 0.05046], label_names: ['0', '180'], filename: pulc_demo_imgs/text_image_orientation/img_rot0_demo.jpg
|
||||
Predict complete!
|
||||
```
|
||||
|
||||
**备注**: 更换其他预测的数据时,只需要改变 `--infer_imgs=xx` 中的字段即可,支持传入整个文件夹。
|
||||
|
||||
- 在 Python 代码中预测
|
||||
|
||||
```
|
||||
* 在 Python 代码中预测
|
||||
```python
|
||||
import paddleclas
|
||||
model = paddleclas.PaddleClas(model_name="text_image_orientation")
|
||||
result = model.predict(input_data="deploy/images/PULC/text_image_orientation/img_rot0_demo.jpg")
|
||||
result = model.predict(input_data="pulc_demo_imgs/text_image_orientation/img_rot0_demo.jpg")
|
||||
print(next(result))
|
||||
```
|
||||
|
||||
**备注**:`model.predict()` 为可迭代对象(`generator`),因此需要使用 `next()` 函数或 `for` 循环对其迭代调用。每次调用将以 `batch_size` 为单位进行一次预测,并返回预测结果, 默认 `batch_size` 为 1,如果需要更改 `batch_size`,实例化模型时,需要指定 `batch_size`,如 `model = paddleclas.PaddleClas(model_name="text_image_orientation", batch_size=2)`, 使用默认的代码返回结果示例如下:
|
||||
**备注**:`model.predict()` 为可迭代对象(`generator`),因此需要使用 `next()` 函数或 `for` 循环对其迭代调用。每次调用将以 `batch_size` 为单位进行一次预测,并返回预测结果, 默认 `batch_size` 为 1,如果需要更改 `batch_size`,实例化模型时,需要指定 `batch_size`,如 `model = paddleclas.PaddleClas(model_name="text_image_orientation", batch_size=2)`, 使用默认的代码返回结果示例如下:
|
||||
|
||||
```
|
||||
>>> result
|
||||
[{'class_ids': [0, 2], 'scores': [0.85615, 0.05046], 'label_names': ['0', '180'], 'filename': 'deploy/images/PULC/text_image_orientation/img_rot0_demo.jpg'}]
|
||||
[{'class_ids': [0, 2], 'scores': [0.85615, 0.05046], 'label_names': ['0', '180'], 'filename': 'pulc_demo_imgs/text_image_orientation/img_rot0_demo.jpg'}]
|
||||
```
|
||||
|
||||
<a name="3"></a>
|
||||
|
@ -111,7 +131,7 @@ print(next(result))
|
|||
|
||||
### 3.1 环境配置
|
||||
|
||||
- 安装:请先参考 [Paddle 安装教程](../installation/install_paddle.md) 以及 [PaddleClas 安装教程](../installation/install_paddleclas.md) 配置 PaddleClas 运行环境。
|
||||
* 安装:请先参考文档 [环境准备](../installation/install_paddleclas.md) 配置 PaddleClas 运行环境。
|
||||
|
||||
<a name="3.2"></a>
|
||||
|
||||
|
@ -209,7 +229,7 @@ python3 -m paddle.distributed.launch \
|
|||
|
||||
验证集的最佳指标在0.99左右。
|
||||
|
||||
**备注**:本文档中提到的训练指标均为在大规模内部数据上的训练指标,使用demo数据训练时,由于数据集规模较小且分布与大规模内部数据不同,无法达到该指标。可以进一步扩充自己的数据并且使用本案例中介绍的优化方法进行调优,从而达到更高的精度。
|
||||
**备注**:本文档中提到的训练指标均为在大规模内部数据上的训练指标,使用 demo 数据训练时,由于数据集规模较小且分布与大规模内部数据不同,无法达到该指标。可以进一步扩充自己的数据并且使用本案例中介绍的优化方法进行调优,从而达到更高的精度。
|
||||
|
||||
<a name="3.4"></a>
|
||||
|
||||
|
@ -274,15 +294,15 @@ python3 -m paddle.distributed.launch \
|
|||
-o Arch.name=ResNet101_vd
|
||||
```
|
||||
|
||||
验证集的最佳指标为0.996左右,当前教师模型最好的权重保存在`output/ResNet101_vd/best_model.pdparams`。
|
||||
验证集的最佳指标为 0.996 左右,当前教师模型最好的权重保存在`output/ResNet101_vd/best_model.pdparams`。
|
||||
|
||||
**备注:** 训练ResNet101_vd模型需要的显存较多,如果机器显存不够,可以将学习率和 batch size 同时缩小一定的倍数进行训练。
|
||||
**备注:** 训练 ResNet101_vd 模型需要的显存较多,如果机器显存不够,可以将学习率和 batch size 同时缩小一定的倍数进行训练。如在命令后添加以下参数 `-o DataLoader.Train.sampler.batch_size=64`, `Optimizer.lr.learning_rate=0.1`。
|
||||
|
||||
<a name="4.1.2"></a>
|
||||
|
||||
#### 4.1.2 蒸馏训练
|
||||
|
||||
配置文件`ppcls/configs/PULC/text_image_orientation/PPLCNet_x1_0_distillation.yaml`提供了`SKL-UGI知识蒸馏策略`的配置。该配置将`ResNet101_vd`当作教师模型,`PPLCNet_x1_0`当作学生模型,使用[3.2.2节](#3.2.2)中介绍的蒸馏数据作为新增的无标签数据。训练脚本如下:
|
||||
配置文件`ppcls/configs/PULC/text_image_orientation/PPLCNet_x1_0_distillation.yaml`提供了`SKL-UGI 知识蒸馏策略`的配置。该配置将 `ResNet101_vd` 当作教师模型,`PPLCNet_x1_0` 当作学生模型,使用[3.2.2节](#3.2.2)中介绍的蒸馏数据作为新增的无标签数据。训练脚本如下:
|
||||
|
||||
```shell
|
||||
export CUDA_VISIBLE_DEVICES=0,1,2,3
|
||||
|
|
|
@ -7,6 +7,9 @@
|
|||
|
||||
- [1. 模型和应用场景介绍](#1)
|
||||
- [2. 模型快速体验](#2)
|
||||
- [2.1 安装 paddlepaddle](#2.1)
|
||||
- [2.2 安装 paddleclas](#2.2)
|
||||
- [2.3 预测](#2.3)
|
||||
- [3. 模型训练、评估和预测](#3)
|
||||
- [3.1 环境配置](#3.1)
|
||||
- [3.2 数据准备](#3.2)
|
||||
|
@ -64,30 +67,50 @@
|
|||
|
||||
## 2. 模型快速体验
|
||||
|
||||
|
||||
<a name="2.1"></a>
|
||||
|
||||
### 2.1 安装 paddlepaddle
|
||||
|
||||
- 您的机器安装的是 CUDA9 或 CUDA10,请运行以下命令安装
|
||||
|
||||
### 2.1 安装 paddleclas
|
||||
```bash
|
||||
python3 -m pip install paddlepaddle-gpu -i https://mirror.baidu.com/pypi/simple
|
||||
```
|
||||
|
||||
使用如下命令快速安装 paddlepaddle, paddleclas
|
||||
- 您的机器是CPU,请运行以下命令安装
|
||||
|
||||
```bash
|
||||
python3 -m pip install paddlepaddle -i https://mirror.baidu.com/pypi/simple
|
||||
```
|
||||
|
||||
更多的版本需求,请参照[飞桨官网安装文档](https://www.paddlepaddle.org.cn/install/quick)中的说明进行操作。
|
||||
|
||||
<a name="2.2"></a>
|
||||
|
||||
### 2.2 安装 paddleclas
|
||||
|
||||
使用如下命令快速安装 paddleclas
|
||||
|
||||
```
|
||||
pip3 install paddlepaddle paddleclas
|
||||
```
|
||||
<a name="2.2"></a>
|
||||
pip3 install paddleclas
|
||||
```
|
||||
|
||||
<a name="2.3"></a>
|
||||
|
||||
### 2.2 预测
|
||||
### 2.3 预测
|
||||
|
||||
点击[这里](https://paddleclas.bj.bcebos.com/data/PULC/pulc_demo_imgs.zip)下载 demo 数据并解压,然后在终端中切换到相应目录。
|
||||
|
||||
* 使用命令行快速预测
|
||||
|
||||
```bash
|
||||
paddleclas --model_name=textline_orientation --infer_imgs=deploy/images/PULC/textline_orientation/textline_orientation_test_0_0.png
|
||||
paddleclas --model_name=textline_orientation --infer_imgs=pulc_demo_imgs/textline_orientation/textline_orientation_test_0_0.png
|
||||
```
|
||||
|
||||
结果如下:
|
||||
```
|
||||
>>> result
|
||||
class_ids: [0], scores: [1.00], label_names: ['0_degree'], filename: deploy/images/PULC/textline_orientation/textline_orientation_test_0_0.png
|
||||
class_ids: [0], scores: [1.0], label_names: ['0_degree'], filename: pulc_demo_imgs/textline_orientation/textline_orientation_test_0_0.png
|
||||
Predict complete!
|
||||
```
|
||||
|
||||
|
@ -98,18 +121,17 @@ Predict complete!
|
|||
```python
|
||||
import paddleclas
|
||||
model = paddleclas.PaddleClas(model_name="textline_orientation")
|
||||
result = model.predict(input_data="deploy/images/PULC/textline_orientation/textline_orientation_test_0_0.png")
|
||||
result = model.predict(input_data="pulc_demo_imgs/textline_orientation/textline_orientation_test_0_0.png")
|
||||
print(next(result))
|
||||
```
|
||||
|
||||
**备注**:`model.predict()` 为可迭代对象(`generator`),因此需要使用 `next()` 函数或 `for` 循环对其迭代调用。每次调用将以 `batch_size` 为单位进行一次预测,并返回预测结果, 默认 `batch_size` 为 1,如果需要更改 `batch_size`,实例化模型时,需要指定 `batch_size`,如 `model = paddleclas.PaddleClas(model_name="person_exists", batch_size=2)`, 使用默认的代码返回结果示例如下:
|
||||
**备注**:`model.predict()` 为可迭代对象(`generator`),因此需要使用 `next()` 函数或 `for` 循环对其迭代调用。每次调用将以 `batch_size` 为单位进行一次预测,并返回预测结果, 默认 `batch_size` 为 1,如果需要更改 `batch_size`,实例化模型时,需要指定 `batch_size`,如 `model = paddleclas.PaddleClas(model_name="textline_orientation", batch_size=2)`, 使用默认的代码返回结果示例如下:
|
||||
|
||||
```
|
||||
>>> result
|
||||
[{'class_ids': [0], 'scores': [1.00], 'label_names': ['0_degree'], 'filename': 'deploy/images/PULC/textline_orientation/textline_orientation_test_0_0.png'}]
|
||||
[{'class_ids': [0], 'scores': [1.0], 'label_names': ['0_degree'], 'filename': 'pulc_demo_imgs/textline_orientation/textline_orientation_test_0_0.png'}]
|
||||
```
|
||||
|
||||
|
||||
<a name="3"></a>
|
||||
|
||||
## 3. 模型训练、评估和预测
|
||||
|
|
|
@ -7,6 +7,9 @@
|
|||
|
||||
- [1. 模型和应用场景介绍](#1)
|
||||
- [2. 模型快速体验](#2)
|
||||
- [2.1 安装 paddlepaddle](#2.1)
|
||||
- [2.2 安装 paddleclas](#2.2)
|
||||
- [2.3 预测](#2.3)
|
||||
- [3. 模型训练、评估和预测](#3)
|
||||
- [3.1 环境配置](#3.1)
|
||||
- [3.2 数据准备](#3.2)
|
||||
|
@ -63,28 +66,50 @@
|
|||
## 2. 模型快速体验
|
||||
|
||||
<a name="2.1"></a>
|
||||
|
||||
### 2.1 安装 paddleclas
|
||||
|
||||
使用如下命令快速安装 paddlepaddle, paddleclas
|
||||
|
||||
### 2.1 安装 paddlepaddle
|
||||
|
||||
- 您的机器安装的是 CUDA9 或 CUDA10,请运行以下命令安装
|
||||
|
||||
```bash
|
||||
pip3 install paddlepaddle paddleclas
|
||||
python3 -m pip install paddlepaddle-gpu -i https://mirror.baidu.com/pypi/simple
|
||||
```
|
||||
<a name="2.2"></a>
|
||||
|
||||
### 2.2 预测
|
||||
- 您的机器是CPU,请运行以下命令安装
|
||||
|
||||
```bash
|
||||
python3 -m pip install paddlepaddle -i https://mirror.baidu.com/pypi/simple
|
||||
```
|
||||
|
||||
更多的版本需求,请参照[飞桨官网安装文档](https://www.paddlepaddle.org.cn/install/quick)中的说明进行操作。
|
||||
|
||||
<a name="2.2"></a>
|
||||
|
||||
### 2.2 安装 paddleclas
|
||||
|
||||
使用如下命令快速安装 paddleclas
|
||||
|
||||
```
|
||||
pip3 install paddleclas
|
||||
```
|
||||
|
||||
<a name="2.3"></a>
|
||||
|
||||
### 2.3 预测
|
||||
|
||||
点击[这里](https://paddleclas.bj.bcebos.com/data/PULC/pulc_demo_imgs.zip)下载 demo 数据并解压,然后在终端中切换到相应目录。
|
||||
|
||||
* 使用命令行快速预测
|
||||
|
||||
```bash
|
||||
paddleclas --model_name traffic_sign --infer_imgs deploy/images/PULC/traffic_sign/100999_83928.jpg
|
||||
paddleclas --model_name=traffic_sign --infer_imgs=pulc_demo_imgs/traffic_sign/100999_83928.jpg
|
||||
```
|
||||
|
||||
结果如下:
|
||||
```
|
||||
>>> result
|
||||
class_ids: [182, 179, 162, 128, 24], scores: [0.98623, 0.01255, 0.00022, 0.00021, 0.00012], label_names: ['pl110', 'pl100', 'pl120', 'p26', 'pm10'], filename: deploy/images/PULC/traffic_sign/100999_83928.jpg
|
||||
class_ids: [182, 179, 162, 128, 24], scores: [0.98623, 0.01255, 0.00022, 0.00021, 0.00012], label_names: ['pl110', 'pl100', 'pl120', 'p26', 'pm10'], filename: pulc_demo_imgs/traffic_sign/100999_83928.jpg
|
||||
Predict complete!
|
||||
```
|
||||
|
||||
**备注**: 更换其他预测的数据时,只需要改变 `--infer_imgs=xx` 中的字段即可,支持传入整个文件夹。
|
||||
|
@ -94,15 +119,15 @@ class_ids: [182, 179, 162, 128, 24], scores: [0.98623, 0.01255, 0.00022, 0.00021
|
|||
```python
|
||||
import paddleclas
|
||||
model = paddleclas.PaddleClas(model_name="traffic_sign")
|
||||
result = model.predict(input_data="deploy/images/PULC/traffic_sign/100999_83928.jpg")
|
||||
result = model.predict(input_data="pulc_demo_imgs/traffic_sign/100999_83928.jpg")
|
||||
print(next(result))
|
||||
```
|
||||
|
||||
**备注**:`model.predict()` 为可迭代对象(`generator`),因此需要使用 `next()` 函数或 `for` 循环对其迭代调用。每次调用将以 `batch_size` 为单位进行一次预测,并返回预测结果, 默认 `batch_size` 为 1,如果需要更改 `batch_size`,实例化模型时,需要指定 `batch_size`,如 `model = paddleclas.PaddleClas(model_name="person_exists", batch_size=2)`, 使用默认的代码返回结果示例如下:
|
||||
**备注**:`model.predict()` 为可迭代对象(`generator`),因此需要使用 `next()` 函数或 `for` 循环对其迭代调用。每次调用将以 `batch_size` 为单位进行一次预测,并返回预测结果, 默认 `batch_size` 为 1,如果需要更改 `batch_size`,实例化模型时,需要指定 `batch_size`,如 `model = paddleclas.PaddleClas(model_name="traffic_sign", batch_size=2)`, 使用默认的代码返回结果示例如下:
|
||||
|
||||
```
|
||||
result
|
||||
[{'class_ids': [182, 179, 162, 128, 24], 'scores': [0.98623, 0.01255, 0.00022, 0.00021, 0.00012], 'label_names': ['pl110', 'pl100', 'pl120', 'p26', 'pm10'], 'filename': 'deploy/images/PULC/traffic_sign/100999_83928.jpg'}]
|
||||
>>> result
|
||||
[{'class_ids': [182, 179, 162, 128, 24], 'scores': [0.98623, 0.01255, 0.00022, 0.00021, 0.00012], 'label_names': ['pl110', 'pl100', 'pl120', 'p26', 'pm10'], 'filename': 'pulc_demo_imgs/traffic_sign/100999_83928.jpg'}]
|
||||
```
|
||||
|
||||
<a name="3"></a>
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
图像分类是计算机视觉的基础算法之一,是企业应用中最常见的算法,也是许多 CV 应用的重要组成部分。近年来,骨干网络模型发展迅速,ImageNet 的精度纪录被不断刷新。然而,这些模型在实用场景的表现有时却不尽如人意。一方面,精度高的模型往往体积大,运算慢,常常难以满足实际部署需求;另一方面,选择了合适的模型之后,往往还需要经验丰富的工程师进行调参,费时费力。PaddleClas 为了解决企业应用难题,让分类模型的训练和调参更加容易,总结推出了实用轻量图像分类解决方案(PULC, Practical Ultra Lightweight Classification)。PULC融合了骨干网络、数据增广、蒸馏等多种前沿算法,可以自动训练得到轻量且高精度的图像分类模型。
|
||||
|
||||
PULC 方案在人、车、OCR等方向的多个场景中均验证有效,用超轻量模型就可实现与SwinTransformer模型接近的精度,预测速度提高 40+ 倍。
|
||||
PULC 方案在人、车、OCR等方向的多个场景中均验证有效,用超轻量模型就可实现与 SwinTransformer 模型接近的精度,预测速度提高 40+ 倍。
|
||||
|
||||
<div align="center">
|
||||
<img src="https://user-images.githubusercontent.com/19523330/173011854-b10fcd7a-b799-4dfd-a1cf-9504952a3c44.png" width = "800" />
|
||||
|
@ -78,7 +78,7 @@ train
|
|||
tree -r -i -f train | grep -E "jpg|JPG|jpeg|JPEG|png|PNG" | awk -F "/" '{print $0" "$2}' > train_list.txt
|
||||
```
|
||||
|
||||
其中,如果需要传入更多的数据类型,可以增加 `grep -E`后的内容, `$2`中的`2`为类别号文件夹的层级。
|
||||
其中,如果涉及更多的图片名称尾缀,可以增加 `grep -E`后的内容, `$2` 中的 `2` 为类别号文件夹的层级。
|
||||
|
||||
**备注:** 以上为数据集获取和生成的方法介绍,这里您可以直接下载有人/无人场景数据快速开始体验。
|
||||
|
||||
|
@ -105,20 +105,20 @@ cd ../
|
|||
|
||||
#### 3.1 骨干网络PP-LCNet
|
||||
|
||||
PULC采用了轻量骨干网络PP-LCNet,相比同精度竞品速度快50%,您可以在[PP-LCNet介绍](../models/PP-LCNet.md)查阅该骨干网络的详细介绍。
|
||||
直接使用PP-LCNet训练的命令为:
|
||||
PULC 采用了轻量骨干网络 PP-LCNet,相比同精度竞品速度快 50%,您可以在[PP-LCNet介绍](../models/PP-LCNet.md)查阅该骨干网络的详细介绍。
|
||||
直接使用 PP-LCNet 训练的命令为:
|
||||
|
||||
```shell
|
||||
export CUDA_VISIBLE_DEVICES=0,1,2,3
|
||||
python3 -m paddle.distributed.launch \
|
||||
--gpus="0,1,2,3" \
|
||||
tools/train.py \
|
||||
-c ./ppcls/configs/PULC/person_exists/PPLCNet_x1_0.yaml
|
||||
-c ./ppcls/configs/PULC/person_exists/PPLCNet_x1_0_search.yaml
|
||||
```
|
||||
|
||||
为了方便性能对比,我们也提供了大模型 SwinTransformer 和轻量模型 MobileNetV3 的配置文件,您可以使用命令训练:
|
||||
为了方便性能对比,我们也提供了大模型 SwinTransformer_tiny 和轻量模型 MobileNetV3_small_x0_35 的配置文件,您可以使用命令训练:
|
||||
|
||||
SwinTransformer:
|
||||
SwinTransformer_tiny:
|
||||
|
||||
```shell
|
||||
export CUDA_VISIBLE_DEVICES=0,1,2,3
|
||||
|
@ -128,7 +128,7 @@ python3 -m paddle.distributed.launch \
|
|||
-c ./ppcls/configs/PULC/person_exists/SwinTransformer_tiny_patch4_window7_224.yaml
|
||||
```
|
||||
|
||||
MobileNetV3:
|
||||
MobileNetV3_small_x0_35:
|
||||
|
||||
```shell
|
||||
export CUDA_VISIBLE_DEVICES=0,1,2,3
|
||||
|
|
|
@ -7,6 +7,9 @@
|
|||
|
||||
- [1. 模型和应用场景介绍](#1)
|
||||
- [2. 模型快速体验](#2)
|
||||
- [2.1 安装 paddlepaddle](#2.1)
|
||||
- [2.2 安装 paddleclas](#2.2)
|
||||
- [2.3 预测](#2.3)
|
||||
- [3. 模型训练、评估和预测](#3)
|
||||
- [3.1 环境配置](#3.1)
|
||||
- [3.2 数据准备](#3.2)
|
||||
|
@ -64,29 +67,50 @@
|
|||
## 2. 模型快速体验
|
||||
|
||||
<a name="2.1"></a>
|
||||
|
||||
### 2.1 安装 paddleclas
|
||||
|
||||
使用如下命令快速安装 paddlepaddle, paddleclas
|
||||
|
||||
### 2.1 安装 paddlepaddle
|
||||
|
||||
- 您的机器安装的是 CUDA9 或 CUDA10,请运行以下命令安装
|
||||
|
||||
```bash
|
||||
pip3 install paddlepaddle paddleclas
|
||||
python3 -m pip install paddlepaddle-gpu -i https://mirror.baidu.com/pypi/simple
|
||||
```
|
||||
<a name="2.2"></a>
|
||||
|
||||
### 2.2 预测
|
||||
- 您的机器是CPU,请运行以下命令安装
|
||||
|
||||
```bash
|
||||
python3 -m pip install paddlepaddle -i https://mirror.baidu.com/pypi/simple
|
||||
```
|
||||
|
||||
更多的版本需求,请参照[飞桨官网安装文档](https://www.paddlepaddle.org.cn/install/quick)中的说明进行操作。
|
||||
|
||||
<a name="2.2"></a>
|
||||
|
||||
### 2.2 安装 paddleclas
|
||||
|
||||
使用如下命令快速安装 paddleclas
|
||||
|
||||
```
|
||||
pip3 install paddleclas
|
||||
```
|
||||
|
||||
<a name="2.3"></a>
|
||||
|
||||
### 2.3 预测
|
||||
|
||||
点击[这里](https://paddleclas.bj.bcebos.com/data/PULC/pulc_demo_imgs.zip)下载 demo 数据并解压,然后在终端中切换到相应目录。
|
||||
|
||||
* 使用命令行快速预测
|
||||
|
||||
```bash
|
||||
paddleclas --model_name vehicle_attribute --infer_imgs deploy/images/PULC/vehicle_attribute/0002_c002_00030670_0.jpg
|
||||
paddleclas --model_name=vehicle_attribute --infer_imgs=pulc_demo_imgs/vehicle_attribute/0002_c002_00030670_0.jpg
|
||||
```
|
||||
|
||||
结果如下:
|
||||
```
|
||||
>>> result
|
||||
attributes: Color: (yellow, prob: 0.9893476963043213), Type: (hatchback, prob: 0.9734097719192505), output: [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0], filename: deploy/images/PULC/vehicle_attribute/0002_c002_00030670_0.jpg
|
||||
ppcls INFO: Predict complete!
|
||||
attributes: Color: (yellow, prob: 0.9893476963043213), Type: (hatchback, prob: 0.9734097719192505), output: [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0], filename: pulc_demo_imgs/vehicle_attribute/0002_c002_00030670_0.jpg
|
||||
Predict complete!
|
||||
```
|
||||
|
||||
**备注**: 更换其他预测的数据时,只需要改变 `--infer_imgs=xx` 中的字段即可,支持传入整个文件夹。
|
||||
|
@ -96,17 +120,18 @@ ppcls INFO: Predict complete!
|
|||
```python
|
||||
import paddleclas
|
||||
model = paddleclas.PaddleClas(model_name="vehicle_attribute")
|
||||
result = model.predict(input_data="deploy/images/PULC/vehicle_attribute/0002_c002_00030670_0.jpg")
|
||||
result = model.predict(input_data="pulc_demo_imgs/vehicle_attribute/0002_c002_00030670_0.jpg")
|
||||
print(next(result))
|
||||
```
|
||||
|
||||
**备注**:`model.predict()` 为可迭代对象(`generator`),因此需要使用 `next()` 函数或 `for` 循环对其迭代调用。每次调用将以 `batch_size` 为单位进行一次预测,并返回预测结果, 默认 `batch_size` 为 1,如果需要更改 `batch_size`,实例化模型时,需要指定 `batch_size`,如 `model = paddleclas.PaddleClas(model_name="person_exists", batch_size=2)`, 使用默认的代码返回结果示例如下:
|
||||
**备注**:`model.predict()` 为可迭代对象(`generator`),因此需要使用 `next()` 函数或 `for` 循环对其迭代调用。每次调用将以 `batch_size` 为单位进行一次预测,并返回预测结果, 默认 `batch_size` 为 1,如果需要更改 `batch_size`,实例化模型时,需要指定 `batch_size`,如 `model = paddleclas.PaddleClas(model_name="vehicle_attribute", batch_size=2)`, 使用默认的代码返回结果示例如下:
|
||||
|
||||
```
|
||||
result
|
||||
[{'attributes': 'Color: (yellow, prob: 0.9893476963043213), Type: (hatchback, prob: 0.9734097719192505)', 'output': [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0], 'filename': 'deploy/images/PULC/vehicle_attribute/0002_c002_00030670_0.jpg'}]
|
||||
>>> result
|
||||
[{'attributes': 'Color: (yellow, prob: 0.9893476963043213), Type: (hatchback, prob: 0.9734097719192505)', 'output': [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0], 'filename': 'pulc_demo_imgs/vehicle_attribute/0002_c002_00030670_0.jpg'}]
|
||||
```
|
||||
|
||||
|
||||
<a name="3"></a>
|
||||
|
||||
## 3. 模型训练、评估和预测
|
||||
|
|
|
@ -26,6 +26,7 @@ from paddle.nn.initializer import Uniform
|
|||
from paddle.regularizer import L2Decay
|
||||
import math
|
||||
|
||||
from ppcls.utils import logger
|
||||
from ppcls.arch.backbone.base.theseus_layer import TheseusLayer
|
||||
from ppcls.utils.save_load import load_dygraph_pretrain, load_dygraph_pretrain_from_url
|
||||
|
||||
|
@ -306,9 +307,9 @@ class ResNet(TheseusLayer):
|
|||
list, tuple
|
||||
)), "lr_mult_list should be in (list, tuple) but got {}".format(
|
||||
type(self.lr_mult_list))
|
||||
assert len(self.lr_mult_list
|
||||
) == 5, "lr_mult_list length should be 5 but got {}".format(
|
||||
len(self.lr_mult_list))
|
||||
if len(self.lr_mult_list) != 5:
|
||||
msg = "lr_mult_list length should be 5 but got {}, default lr_mult_list used".format(len(self.lr_mult_list))
|
||||
logger.warning(msg)
|
||||
|
||||
assert isinstance(self.stride_list, (
|
||||
list, tuple
|
||||
|
|
|
@ -54,7 +54,7 @@ DataLoader:
|
|||
dataset:
|
||||
name: ImageNetDataset
|
||||
image_root: ./dataset/
|
||||
cls_label_path: ./dataset/tt100k_clas_v2/label_list_train.txt
|
||||
cls_label_path: ./dataset/traffic_sign/label_list_train.txt
|
||||
delimiter: "\t"
|
||||
transform_ops:
|
||||
- DecodeImage:
|
||||
|
|
|
@ -118,8 +118,7 @@ DataLoader:
|
|||
use_shared_memory: True
|
||||
|
||||
Infer:
|
||||
# infer_imgs: dataset/traffic_sign_demo/
|
||||
infer_imgs: dataset/tt100k_clas_v2/test/
|
||||
infer_imgs: deploy/images/PULC/traffic_sign/99603_17806.jpg
|
||||
batch_size: 10
|
||||
transforms:
|
||||
- DecodeImage:
|
||||
|
|
|
@ -113,7 +113,7 @@ DataLoader:
|
|||
dataset:
|
||||
name: ImageNetDataset
|
||||
image_root: ./dataset/
|
||||
cls_label_path: ./dataset/tt100k_clas_v2/label_list_test.txt
|
||||
cls_label_path: ./dataset/traffic_sign/label_list_test.txt
|
||||
delimiter: "\t"
|
||||
transform_ops:
|
||||
- DecodeImage:
|
||||
|
|
|
@ -225,7 +225,7 @@ for batch_size in ${batch_size_list[*]}; do
|
|||
echo $cmd
|
||||
eval $cmd
|
||||
last_status=${PIPESTATUS[0]}
|
||||
status_check $last_status "${cmd}" "${status_log}"
|
||||
status_check $last_status "${cmd}" "${status_log}" "${model_name}"
|
||||
else
|
||||
IFS=";"
|
||||
unset_env=`unset CUDA_VISIBLE_DEVICES`
|
||||
|
@ -261,7 +261,7 @@ for batch_size in ${batch_size_list[*]}; do
|
|||
echo $cmd
|
||||
eval $cmd
|
||||
last_status=${PIPESTATUS[0]}
|
||||
status_check $last_status "${cmd}" "${status_log}"
|
||||
status_check $last_status "${cmd}" "${status_log}" "${model_name}"
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
|
|
@ -38,6 +38,7 @@ function func_set_params(){
|
|||
|
||||
function func_parser_params(){
|
||||
strs=$1
|
||||
MODE=$2
|
||||
IFS=":"
|
||||
array=(${strs})
|
||||
key=${array[0]}
|
||||
|
@ -64,10 +65,10 @@ function status_check(){
|
|||
last_status=$1 # the exit code
|
||||
run_command=$2
|
||||
run_log=$3
|
||||
model_name=$4
|
||||
if [ $last_status -eq 0 ]; then
|
||||
echo -e "\033[33m Run successfully with command - ${run_command}! \033[0m" | tee -a ${run_log}
|
||||
echo -e "\033[33m Run successfully with command - ${model_name} - ${run_command}! \033[0m" | tee -a ${run_log}
|
||||
else
|
||||
echo -e "\033[33m Run failed with command - ${run_command}! \033[0m" | tee -a ${run_log}
|
||||
echo -e "\033[33m Run failed with command - ${model_name} - ${run_command}! \033[0m" | tee -a ${run_log}
|
||||
fi
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ python:python3.7
|
|||
--model_filename:inference.pdmodel
|
||||
--params_filename:inference.pdiparams
|
||||
--save_file:./deploy/models/picodet_PPLCNet_x2_5_mainbody_lite_v1.0_infer/inference.onnx
|
||||
--opset_version:10
|
||||
--opset_version:11
|
||||
--enable_onnx_checker:True
|
||||
inference_model_url:https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/rec/models/inference/picodet_PPLCNet_x2_5_mainbody_lite_v1.0_infer.tar
|
||||
inference:./python/predict_cls.py
|
||||
|
|
|
@ -8,6 +8,7 @@ python:python3.7
|
|||
--save_file:./deploy/models/PPHGNet_small_infer/inference.onnx
|
||||
--opset_version:10
|
||||
--enable_onnx_checker:True
|
||||
inference_model_url:https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPHGNet_small_infer.tar
|
||||
inference:./python/predict_cls.py
|
||||
Global.use_onnx:True
|
||||
Global.inference_model_dir:./models/PPHGNet_small_infer
|
||||
|
|
|
@ -8,6 +8,7 @@ python:python3.7
|
|||
--save_file:./deploy/models/PPHGNet_tiny_infer/inference.onnx
|
||||
--opset_version:10
|
||||
--enable_onnx_checker:True
|
||||
inference_model_url:https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPHGNet_tiny_infer.tar
|
||||
inference:./python/predict_cls.py
|
||||
Global.use_onnx:True
|
||||
Global.inference_model_dir:./models/PPHGNet_tiny_infer
|
||||
|
|
|
@ -8,6 +8,7 @@ python:python3.7
|
|||
--save_file:./deploy/models/PPLCNet_x0_25_infer/inference.onnx
|
||||
--opset_version:10
|
||||
--enable_onnx_checker:True
|
||||
inference_model_url:https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPLCNet_x0_25_infer.tar
|
||||
inference:./python/predict_cls.py
|
||||
Global.use_onnx:True
|
||||
Global.inference_model_dir:./models/PPLCNet_x0_25_infer
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
===========================paddle2onnx_params===========================
|
||||
model_name:PPLCNet_x0_25
|
||||
model_name:PPLCNet_x0_35
|
||||
python:python3.7
|
||||
2onnx: paddle2onnx
|
||||
--model_dir:./deploy/models/PPLCNet_x0_25_infer/
|
||||
--model_dir:./deploy/models/PPLCNet_x0_35_infer/
|
||||
--model_filename:inference.pdmodel
|
||||
--params_filename:inference.pdiparams
|
||||
--save_file:./deploy/models/PPLCNet_x0_25_infer/inference.onnx
|
||||
--save_file:./deploy/models/PPLCNet_x0_35_infer/inference.onnx
|
||||
--opset_version:10
|
||||
--enable_onnx_checker:True
|
||||
inference_model_url:https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPLCNet_x0_25_infer.tar
|
||||
inference_model_url:https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPLCNet_x0_35_infer.tar
|
||||
inference:./python/predict_cls.py
|
||||
Global.use_onnx:True
|
||||
Global.inference_model_dir:./models/PPLCNet_x0_25_infer
|
||||
Global.inference_model_dir:./models/PPLCNet_x0_35_infer
|
||||
Global.use_gpu:False
|
||||
-c:configs/inference_cls.yaml
|
|
@ -1,16 +1,16 @@
|
|||
===========================paddle2onnx_params===========================
|
||||
model_name:PP-ShiTu_mainbody_det
|
||||
model_name:PPLCNet_x0_5
|
||||
python:python3.7
|
||||
2onnx: paddle2onnx
|
||||
--model_dir:./deploy/models/picodet_PPLCNet_x2_5_mainbody_lite_v1.0_infer/
|
||||
--model_dir:./deploy/models/PPLCNet_x0_5_infer/
|
||||
--model_filename:inference.pdmodel
|
||||
--params_filename:inference.pdiparams
|
||||
--save_file:./deploy/models/picodet_PPLCNet_x2_5_mainbody_lite_v1.0_infer/inference.onnx
|
||||
--save_file:./deploy/models/PPLCNet_x0_5_infer/inference.onnx
|
||||
--opset_version:10
|
||||
--enable_onnx_checker:True
|
||||
inference_model_url:https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/rec/models/inference/picodet_PPLCNet_x2_5_mainbody_lite_v1.0_infer.tar
|
||||
inference_model_url:https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPLCNet_x0_5_infer.tar
|
||||
inference:./python/predict_cls.py
|
||||
Global.use_onnx:True
|
||||
Global.inference_model_dir:./models/picodet_PPLCNet_x2_5_mainbody_lite_v1.0_infer
|
||||
Global.inference_model_dir:./models/PPLCNet_x0_5_infer
|
||||
Global.use_gpu:False
|
||||
-c:configs/inference_cls.yaml
|
|
@ -9,8 +9,8 @@ python:python3.7
|
|||
--opset_version:10
|
||||
--enable_onnx_checker:True
|
||||
inference_model_url:https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/ResNet50_vd_infer.tar
|
||||
inference: python/predict_cls.py -c configs/inference_cls.yaml
|
||||
inference:./python/predict_cls.py
|
||||
Global.use_onnx:True
|
||||
Global.inference_model_dir:models/ResNet50_vd_infer/
|
||||
Global.inference_model_dir:./models/ResNet50_vd_infer/
|
||||
Global.use_gpu:False
|
||||
-c:configs/inference_cls.yaml
|
||||
|
|
|
@ -240,7 +240,7 @@ if [[ ${MODE} = "paddle2onnx_infer" ]]; then
|
|||
inference_model_url=$(func_parser_value "${lines[10]}")
|
||||
tar_name=${inference_model_url##*/}
|
||||
|
||||
${python_name} -m pip install install paddle2onnx
|
||||
${python_name} -m pip install paddle2onnx
|
||||
${python_name} -m pip install onnxruntime
|
||||
cd deploy
|
||||
mkdir models
|
||||
|
|
|
@ -63,7 +63,7 @@ function func_shitu_cpp_inference(){
|
|||
command="${_script} > ${_save_log_path} 2>&1"
|
||||
eval $command
|
||||
last_status=${PIPESTATUS[0]}
|
||||
status_check $last_status "${command}" "${status_log}"
|
||||
status_check $last_status "${command}" "${status_log}" "${model_name}"
|
||||
done
|
||||
done
|
||||
done
|
||||
|
@ -87,7 +87,7 @@ function func_shitu_cpp_inference(){
|
|||
command="${_script} > ${_save_log_path} 2>&1"
|
||||
eval $command
|
||||
last_status=${PIPESTATUS[0]}
|
||||
status_check $last_status "${command}" "${status_log}"
|
||||
status_check $last_status "${command}" "${status_log}" "${model_name}"
|
||||
done
|
||||
done
|
||||
done
|
||||
|
@ -125,7 +125,7 @@ function func_cls_cpp_inference(){
|
|||
command1="${_script} > ${_save_log_path} 2>&1"
|
||||
eval ${command1}
|
||||
last_status=${PIPESTATUS[0]}
|
||||
status_check $last_status "${command1}" "${status_log}"
|
||||
status_check $last_status "${command1}" "${status_log}" "${model_name}"
|
||||
done
|
||||
done
|
||||
done
|
||||
|
@ -148,7 +148,7 @@ function func_cls_cpp_inference(){
|
|||
command="${_script} > ${_save_log_path} 2>&1"
|
||||
eval $command
|
||||
last_status=${PIPESTATUS[0]}
|
||||
status_check $last_status "${command}" "${status_log}"
|
||||
status_check $last_status "${command}" "${status_log}" "${model_name}"
|
||||
done
|
||||
done
|
||||
done
|
||||
|
|
|
@ -71,7 +71,7 @@ if [ ${MODE} = "whole_infer" ]; then
|
|||
echo $export_cmd
|
||||
eval $export_cmd
|
||||
status_export=$?
|
||||
status_check $status_export "${export_cmd}" "${status_log}"
|
||||
status_check $status_export "${export_cmd}" "${status_log}" "${model_name}"
|
||||
else
|
||||
save_infer_dir=${infer_model}
|
||||
fi
|
||||
|
|
|
@ -67,7 +67,7 @@ function func_test_tipc(){
|
|||
eval ${command1}
|
||||
command2="adb shell 'export LD_LIBRARY_PATH=${lite_arm_work_path}; ${real_inference_cmd}' > ${_save_log_path} 2>&1"
|
||||
eval ${command2}
|
||||
status_check $? "${command2}" "${status_log}"
|
||||
status_check $? "${command2}" "${status_log}" "${model_name}"
|
||||
done
|
||||
done
|
||||
done
|
||||
|
|
|
@ -3,13 +3,6 @@ source test_tipc/common_func.sh
|
|||
|
||||
FILENAME=$1
|
||||
|
||||
dataline=$(cat ${FILENAME})
|
||||
lines=(${dataline})
|
||||
# common params
|
||||
model_name=$(func_parser_value "${lines[1]}")
|
||||
python=$(func_parser_value "${lines[2]}")
|
||||
|
||||
|
||||
# parser params
|
||||
dataline=$(awk 'NR==1, NR==16{print}' $FILENAME)
|
||||
IFS=$'\n'
|
||||
|
@ -43,7 +36,7 @@ inference_config_key=$(func_parser_key "${lines[15]}")
|
|||
inference_config_value=$(func_parser_value "${lines[15]}")
|
||||
|
||||
LOG_PATH="./test_tipc/output/${model_name}"
|
||||
mkdir -p ./test_tipc/output
|
||||
mkdir -p ${LOG_PATH}
|
||||
status_log="${LOG_PATH}/results_paddle2onnx.log"
|
||||
|
||||
|
||||
|
@ -62,7 +55,8 @@ function func_paddle2onnx(){
|
|||
trans_model_cmd="${padlle2onnx_cmd} ${set_dirname} ${set_model_filename} ${set_params_filename} ${set_save_model} ${set_opset_version} ${set_enable_onnx_checker}"
|
||||
eval $trans_model_cmd
|
||||
last_status=${PIPESTATUS[0]}
|
||||
status_check $last_status "${trans_model_cmd}" "${status_log}"
|
||||
status_check $last_status "${trans_model_cmd}" "${status_log}" "${model_name}"
|
||||
|
||||
# python inference
|
||||
set_model_dir=$(func_set_params "${inference_model_dir_key}" "${inference_model_dir_value}")
|
||||
set_use_onnx=$(func_set_params "${use_onnx_key}" "${use_onnx_value}")
|
||||
|
@ -70,7 +64,7 @@ function func_paddle2onnx(){
|
|||
set_inference_config=$(func_set_params "${inference_config_key}" "${inference_config_value}")
|
||||
infer_model_cmd="cd deploy && ${python} ${inference_py} -o ${set_model_dir} -o ${set_use_onnx} -o ${set_hardware} ${set_inference_config} > ${_save_log_path} 2>&1 && cd ../"
|
||||
eval $infer_model_cmd
|
||||
status_check $last_status "${infer_model_cmd}" "${status_log}"
|
||||
status_check $last_status "${infer_model_cmd}" "${status_log}" "${model_name}"
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -126,7 +126,7 @@ function func_inference(){
|
|||
eval $command
|
||||
last_status=${PIPESTATUS[0]}
|
||||
eval "cat ${_save_log_path}"
|
||||
status_check $last_status "${command}" "../${status_log}"
|
||||
status_check $last_status "${command}" "../${status_log}" "${model_name}"
|
||||
done
|
||||
done
|
||||
done
|
||||
|
@ -151,7 +151,7 @@ function func_inference(){
|
|||
eval $command
|
||||
last_status=${PIPESTATUS[0]}
|
||||
eval "cat ${_save_log_path}"
|
||||
status_check $last_status "${command}" "../${status_log}"
|
||||
status_check $last_status "${command}" "../${status_log}" "${model_name}"
|
||||
done
|
||||
done
|
||||
done
|
||||
|
@ -198,7 +198,7 @@ elif [[ ${MODE} = "klquant_whole_infer" ]]; then
|
|||
command="${python} ${kl_quant_cmd_value}"
|
||||
eval $command
|
||||
last_status=${PIPESTATUS[0]}
|
||||
status_check $last_status "${command}" "${status_log}"
|
||||
status_check $last_status "${command}" "${status_log}" "${model_name}"
|
||||
cd inference/quant_post_static_model
|
||||
ln -s __model__ inference.pdmodel
|
||||
ln -s __params__ inference.pdiparams
|
||||
|
@ -301,7 +301,7 @@ else
|
|||
# export FLAGS_cudnn_deterministic=True
|
||||
sleep 5
|
||||
eval $cmd
|
||||
status_check $? "${cmd}" "${status_log}"
|
||||
status_check $? "${cmd}" "${status_log}" "${model_name}"
|
||||
sleep 5
|
||||
|
||||
if [[ $FILENAME == *GeneralRecognition* ]]; then
|
||||
|
@ -318,7 +318,7 @@ else
|
|||
set_eval_params1=$(func_set_params "${eval_key1}" "${eval_value1}")
|
||||
eval_cmd="${python} ${eval_py} ${set_eval_pretrain} ${set_use_gpu} ${set_eval_params1}"
|
||||
eval $eval_cmd
|
||||
status_check $? "${eval_cmd}" "${status_log}"
|
||||
status_check $? "${eval_cmd}" "${status_log}" "${model_name}"
|
||||
sleep 5
|
||||
fi
|
||||
# run export model
|
||||
|
@ -333,7 +333,7 @@ else
|
|||
set_save_infer_key=$(func_set_params "${save_infer_key}" "${save_infer_path}")
|
||||
export_cmd="${python} ${run_export} ${set_export_weight} ${set_save_infer_key}"
|
||||
eval $export_cmd
|
||||
status_check $? "${export_cmd}" "${status_log}"
|
||||
status_check $? "${export_cmd}" "${status_log}" "${model_name}"
|
||||
|
||||
#run inference
|
||||
eval $env
|
||||
|
|
|
@ -30,5 +30,7 @@ if __name__ == "__main__":
|
|||
args = config.parse_args()
|
||||
config = config.get_config(
|
||||
args.config, overrides=args.override, show=False)
|
||||
if config["Arch"].get("use_sync_bn", False):
|
||||
config["Arch"]["use_sync_bn"] = False
|
||||
engine = Engine(config, mode="export")
|
||||
engine.export()
|
||||
|
|
Loading…
Reference in New Issue