multilabel_en.md 2.4 KB
Newer Older
Y
yaohai 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
# 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 ../../
```

C
cuicheng01 已提交
28
## Training
Y
yaohai 已提交
29

C
cuicheng01 已提交
30 31 32 33 34 35 36
```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/quick_start/professional/MobileNetV1_multilabel.yaml
```
Y
yaohai 已提交
37

C
cuicheng01 已提交
38 39 40
After training for 10 epochs, the best accuracy over the validation set should be around 0.95.

## Evaluation
Y
yaohai 已提交
41 42

```bash
C
cuicheng01 已提交
43 44 45
python tools/eval.py \
    -c ./ppcls/configs/quick_start/professional/MobileNetV1_multilabel.yaml \
    -o Arch.pretrained="./output/MobileNetV1/best_model"
Y
yaohai 已提交
46 47
```

C
cuicheng01 已提交
48
## Prediction
Y
yaohai 已提交
49

C
cuicheng01 已提交
50 51 52 53
```bash
python3 tools/infer.py
    -c ./ppcls/configs/quick_start/professional/MobileNetV1_multilabel.yaml \
    -o Arch.pretrained="./output/MobileNetV1/best_model"
Y
yaohai 已提交
54 55
```

C
cuicheng01 已提交
56 57 58 59
You will get multiple output such as the following:
```
[{'class_ids': [6, 13, 17, 23, 26, 30], 'scores': [0.95683, 0.5567, 0.55211, 0.99088, 0.5943, 0.78767], 'file_name': './deploy/images/0517_2715693311.jpg', 'label_names': []}]  
```
Y
yaohai 已提交
60

C
cuicheng01 已提交
61 62 63
## Prediction based on prediction engine

### Export model
Y
yaohai 已提交
64 65

```bash
C
cuicheng01 已提交
66 67 68
python3 tools/export_model.py \
    -c ./ppcls/configs/quick_start/professional/MobileNetV1_multilabel.yaml \
    -o Arch.pretrained="./output/MobileNetV1/best_model"
Y
yaohai 已提交
69 70
```

C
cuicheng01 已提交
71
The default path of the inference model is under the current path `./inference`
Y
yaohai 已提交
72

C
cuicheng01 已提交
73 74 75
### Prediction based on prediction engine

Enter the deploy directory:
Y
yaohai 已提交
76 77

```bash
C
cuicheng01 已提交
78 79 80 81 82 83 84 85
cd ./deploy
```

Prediction based on prediction engine:

```
python3 python/predict_cls.py \
     -c configs/inference_multilabel_cls.yaml
Y
yaohai 已提交
86 87 88
```

You will get multiple output such as the following:
C
cuicheng01 已提交
89 90 91 92

```
0517_2715693311.jpg:    class id(s): [6, 13, 17, 23, 26, 30], score(s): [0.96, 0.56, 0.55, 0.99, 0.59, 0.79], label_name(s): []
```