diff --git a/README.md b/README.md index 1ce6db0f6f84b78804e4563c4ef5f990bcd55f78..9be6c8bc66b5cf01f9ec7671b3c4afa4c8523693 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/README_cn.md b/README_cn.md index 717abd76c4ceecd4cd6acf2a252f9299605d9974..f1f273bac97076998e40c45fd1e437cf60910fc7 100644 --- a/README_cn.md +++ b/README_cn.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) diff --git a/docs/en/advanced_tutorials/index.rst b/docs/en/advanced_tutorials/index.rst index 2042d4541aa9a0de6d538eca6bc22f8f573fd1e2..2dba33220700136218d52c414fbbcfb080d132a2 100644 --- a/docs/en/advanced_tutorials/index.rst +++ b/docs/en/advanced_tutorials/index.rst @@ -6,4 +6,4 @@ advanced_tutorials image_augmentation/index distillation/index - + multilabel/index diff --git a/docs/en/advanced_tutorials/multilabel/index.rst b/docs/en/advanced_tutorials/multilabel/index.rst new file mode 100644 index 0000000000000000000000000000000000000000..1e8acfdfb3c0d93101f78fdee05ce364041c1882 --- /dev/null +++ b/docs/en/advanced_tutorials/multilabel/index.rst @@ -0,0 +1,7 @@ +Multilabel Classification +================================ + +.. toctree:: + :maxdepth: 3 + + multilabel.md \ No newline at end of file diff --git a/docs/en/advanced_tutorials/multilabel/multilabel_en.md b/docs/en/advanced_tutorials/multilabel/multilabel_en.md new file mode 100644 index 0000000000000000000000000000000000000000..29a18c181bb2dc474a7a368c5db81dd198d7a5e2 --- /dev/null +++ b/docs/en/advanced_tutorials/multilabel/multilabel_en.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 +``` \ No newline at end of file diff --git a/docs/zh_CN/advanced_tutorials/index.rst b/docs/zh_CN/advanced_tutorials/index.rst index c48f204739559ec23265a83c0af8c6326e59e00f..e3bda60be938c4a8ac29bfd51f5f682405f4d0f1 100644 --- a/docs/zh_CN/advanced_tutorials/index.rst +++ b/docs/zh_CN/advanced_tutorials/index.rst @@ -6,4 +6,4 @@ image_augmentation/index distillation/index - + multilabel/index diff --git a/docs/zh_CN/advanced_tutorials/multilabel/index.rst b/docs/zh_CN/advanced_tutorials/multilabel/index.rst new file mode 100644 index 0000000000000000000000000000000000000000..28d5b69dac6347c90381e5112e60210429fca730 --- /dev/null +++ b/docs/zh_CN/advanced_tutorials/multilabel/index.rst @@ -0,0 +1,7 @@ +多标签分类 +================================ + +.. toctree:: + :maxdepth: 3 + + multilabel.md \ No newline at end of file diff --git a/docs/zh_CN/advanced_tutorials/multilabel/multilabel.md b/docs/zh_CN/advanced_tutorials/multilabel/multilabel.md new file mode 100644 index 0000000000000000000000000000000000000000..ef445ca82b7cdb2061d5c48f00cd86fa133b8449 --- /dev/null +++ b/docs/zh_CN/advanced_tutorials/multilabel/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 +``` \ No newline at end of file