add document for multilabel
parent
fee32b555a
commit
2e10d5a4bb
|
@ -82,6 +82,7 @@ PaddleClas is a toolset for image classification tasks prepared for the industry
|
|||
- Advanced tutorials
|
||||
- [Knowledge distillation](./docs/en/advanced_tutorials/distillation/distillation_en.md)
|
||||
- [Data augmentation](./docs/en/advanced_tutorials/image_augmentation/ImageAugment_en.md)
|
||||
- [Multilabel classification](./docs/en/advanced_tutorials/multilabel/multilabel_en.md)
|
||||
- Applications
|
||||
- [Transfer learning](./docs/en/application/transfer_learning_en.md)
|
||||
- [Pretrained model with 100,000 categories](./docs/en/application/transfer_learning_en.md)
|
||||
|
|
|
@ -83,6 +83,7 @@
|
|||
- 高阶使用
|
||||
- [知识蒸馏](./docs/zh_CN/advanced_tutorials/distillation/distillation.md)
|
||||
- [数据增广](./docs/zh_CN/advanced_tutorials/image_augmentation/ImageAugment.md)
|
||||
- [多标签分类](./docs/zh_CN/advanced_tutorials/multilabel/multilabel.md)
|
||||
- 特色拓展应用
|
||||
- [迁移学习](./docs/zh_CN/application/transfer_learning.md)
|
||||
- [10万类图像分类预训练模型](./docs/zh_CN/application/transfer_learning.md)
|
||||
|
|
|
@ -6,4 +6,4 @@ advanced_tutorials
|
|||
|
||||
image_augmentation/index
|
||||
distillation/index
|
||||
|
||||
multilabel/index
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
Multilabel Classification
|
||||
================================
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 3
|
||||
|
||||
multilabel.md
|
|
@ -0,0 +1,82 @@
|
|||
# Multilabel classification quick start
|
||||
|
||||
Based on the [NUS-WIDE-SCENE](https://lms.comp.nus.edu.sg/wp-content/uploads/2019/research/nuswide/NUS-WIDE.html) dataset which is a subset of NUS-WIDE dataset, you can experience multilabel of PaddleClas, include training, evaluation and prediction. Please refer to [Installation](install.md) to install at first.
|
||||
|
||||
## Preparation
|
||||
|
||||
* Enter PaddleClas directory
|
||||
|
||||
```
|
||||
cd path_to_PaddleClas
|
||||
```
|
||||
|
||||
* Create and enter `dataset/NUS-WIDE-SCENE` directory, download and decompress NUS-WIDE-SCENE dataset
|
||||
|
||||
```shell
|
||||
mkdir dataset/NUS-WIDE-SCENE
|
||||
cd dataset/NUS-WIDE-SCENE
|
||||
wget https://paddle-imagenet-models-name.bj.bcebos.com/data/NUS-SCENE-dataset.tar
|
||||
tar -xf NUS-SCENE-dataset.tar
|
||||
```
|
||||
|
||||
* Return `PaddleClas` root home
|
||||
|
||||
```
|
||||
cd ../../
|
||||
```
|
||||
|
||||
## Environment
|
||||
|
||||
### Download pretrained model
|
||||
|
||||
You can use the following commands to download the pretrained model of ResNet50_vd.
|
||||
|
||||
```bash
|
||||
mkdir pretrained
|
||||
cd pretrained
|
||||
wget https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/ResNet50_vd_pretrained.pdparams
|
||||
cd ../
|
||||
```
|
||||
|
||||
## Training
|
||||
|
||||
```shell
|
||||
export CUDA_VISIBLE_DEVICES=0
|
||||
python -m paddle.distributed.launch \
|
||||
--gpus="0" \
|
||||
tools/train.py \
|
||||
-c ./configs/quick_start/ResNet50_vd_multilabel.yaml
|
||||
```
|
||||
|
||||
After training for 10 epochs, the best accuracy over the validation set should be around 0.72.
|
||||
|
||||
## Evaluation
|
||||
|
||||
```bash
|
||||
python tools/eval.py \
|
||||
-c ./configs/quick_start/ResNet50_vd_multilabel.yaml \
|
||||
-o pretrained_model="./output/ResNet50_vd/best_model/ppcls" \
|
||||
-o load_static_weights=False
|
||||
```
|
||||
|
||||
The metric of evaluation is based on mAP, which is commonly used in multilabel task to show model perfermance. The mAP over validation set should be around 0.57.
|
||||
|
||||
## Prediction
|
||||
|
||||
```bash
|
||||
python tools/infer/infer.py \
|
||||
-i "./dataset/NUS-WIDE-SCENE/NUS-SCENE-dataset/images/0199_434752251.jpg" \
|
||||
--model ResNet50_vd \
|
||||
--pretrained_model "./output/ResNet50_vd/best_model/ppcls" \
|
||||
--use_gpu True \
|
||||
--load_static_weights False \
|
||||
--multilabel True \
|
||||
--class_num 33
|
||||
```
|
||||
|
||||
You will get multiple output such as the following:
|
||||
```
|
||||
class id: 3, probability: 0.6025
|
||||
class id: 23, probability: 0.5491
|
||||
class id: 32, probability: 0.7006
|
||||
```
|
|
@ -6,4 +6,4 @@
|
|||
|
||||
image_augmentation/index
|
||||
distillation/index
|
||||
|
||||
multilabel/index
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
多标签分类
|
||||
================================
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 3
|
||||
|
||||
multilabel.md
|
|
@ -0,0 +1,82 @@
|
|||
# 多标签分类quick start
|
||||
|
||||
基于[NUS-WIDE-SCENE](https://lms.comp.nus.edu.sg/wp-content/uploads/2019/research/nuswide/NUS-WIDE.html)数据集,体验多标签分类的训练、评估、预测的过程,该数据集是NUS-WIDE数据集的一个子集。请事先参考[安装指南](install.md)配置运行环境和克隆PaddleClas代码。
|
||||
|
||||
## 一、数据和模型准备
|
||||
|
||||
* 进入PaddleClas目录。
|
||||
|
||||
```
|
||||
cd path_to_PaddleClas
|
||||
```
|
||||
|
||||
* 创建并进入`dataset/NUS-WIDE-SCENE`目录,下载并解压NUS-WIDE-SCENE数据集。
|
||||
|
||||
```shell
|
||||
mkdir dataset/NUS-WIDE-SCENE
|
||||
cd dataset/NUS-WIDE-SCENE
|
||||
wget https://paddle-imagenet-models-name.bj.bcebos.com/data/NUS-SCENE-dataset.tar
|
||||
tar -xf NUS-SCENE-dataset.tar
|
||||
```
|
||||
|
||||
* 返回`PaddleClas`根目录
|
||||
|
||||
```
|
||||
cd ../../
|
||||
```
|
||||
|
||||
## 二、环境准备
|
||||
|
||||
### 2.1 下载预训练模型
|
||||
|
||||
本例展示基于ResNet50_vd模型的多标签分类流程,因此首先下载ResNet50_vd的预训练模型
|
||||
|
||||
```bash
|
||||
mkdir pretrained
|
||||
cd pretrained
|
||||
wget https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/ResNet50_vd_pretrained.pdparams
|
||||
cd ../
|
||||
```
|
||||
|
||||
## 三、模型训练
|
||||
|
||||
```shell
|
||||
export CUDA_VISIBLE_DEVICES=0
|
||||
python -m paddle.distributed.launch \
|
||||
--gpus="0" \
|
||||
tools/train.py \
|
||||
-c ./configs/quick_start/ResNet50_vd_multilabel.yaml
|
||||
```
|
||||
|
||||
训练10epoch之后,验证集最好的正确率应该在0.72左右。
|
||||
|
||||
## 四、模型评估
|
||||
|
||||
```bash
|
||||
python tools/eval.py \
|
||||
-c ./configs/quick_start/ResNet50_vd_multilabel.yaml \
|
||||
-o pretrained_model="./output/ResNet50_vd/best_model/ppcls" \
|
||||
-o load_static_weights=False
|
||||
```
|
||||
|
||||
评估指标采用mAP,验证集的mAP应该在0.57左右。
|
||||
|
||||
## 五、模型预测
|
||||
|
||||
```bash
|
||||
python tools/infer/infer.py \
|
||||
-i "./dataset/NUS-WIDE-SCENE/NUS-SCENE-dataset/images/0199_434752251.jpg" \
|
||||
--model ResNet50_vd \
|
||||
--pretrained_model "./output/ResNet50_vd/best_model/ppcls" \
|
||||
--use_gpu True \
|
||||
--load_static_weights False \
|
||||
--multilabel True \
|
||||
--class_num 33
|
||||
```
|
||||
|
||||
得到类似下面的输出:
|
||||
```
|
||||
class id: 3, probability: 0.6025
|
||||
class id: 23, probability: 0.5491
|
||||
class id: 32, probability: 0.7006
|
||||
```
|
Loading…
Reference in New Issue