quick_start_en.md 5.9 KB
Newer Older
1 2
# Trial in 30mins

3
Based on the flowers102 dataset, it takes only 30 mins to experience PaddleClas, include training varieties of backbone and pretrained model, SSLD distillation, and multiple data augmentation, Please refer to [Installation](install_en.md) to install at first.
4 5 6 7


## Preparation

littletomatodonkey's avatar
fix doc  
littletomatodonkey 已提交
8
* Enter insatallation dir.
9 10 11 12 13

```
cd path_to_PaddleClas
```

14
* Enter `dataset/flowers102`, download and decompress flowers102 dataset.
15 16 17

```shell
cd dataset/flowers102
18
# If you want to download from the brower, you can copy the link, visit it
littletomatodonkey's avatar
fix doc  
littletomatodonkey 已提交
19
# in the browser, download and then decommpress.
20 21
wget https://paddle-imagenet-models-name.bj.bcebos.com/data/flowers102.zip
unzip flowers102.zip
22 23
```

24
* Return `PaddleClas` dir
25 26 27 28 29 30 31 32 33

```
cd ../../
```

## Environment

### Download pretrained model

littletomatodonkey's avatar
littletomatodonkey 已提交
34
You can use the following commands to downdload the pretrained models.
35 36

```bash
littletomatodonkey's avatar
littletomatodonkey 已提交
37 38
mkdir pretrained
cd pretrained
39 40 41 42
wget https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/ResNet50_vd_pretrained.pdparams
wget https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/ResNet50_vd_ssld_pretrained.pdparams
wget https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/MobileNetV3_large_x1_0_pretrained.pdparams

littletomatodonkey's avatar
littletomatodonkey 已提交
43
cd ../
44 45
```

46
**Note**: If you want to download the pretrained models on Windows environment, you can copy the links to the browser and download.
littletomatodonkey's avatar
littletomatodonkey 已提交
47

48

littletomatodonkey's avatar
littletomatodonkey 已提交
49
## Training
50

L
littletomatodonkey 已提交
51
* All experiments are running on the NVIDIA® Tesla® V100 single card.
littletomatodonkey's avatar
fix doc  
littletomatodonkey 已提交
52 53 54 55 56 57 58 59 60 61 62 63 64
* First of all, use the following command to set visible device.

If you use mac or linux, you can use the following command:

```shell
export CUDA_VISIBLE_DEVICES=0
```

* If you use windows, you can use the following command.

```shell
set CUDA_VISIBLE_DEVICES=0
```
65 66 67 68 69 70

### Train from scratch

* Train ResNet50_vd

```shell
71
python3 tools/train.py -c ./configs/quick_start/ResNet50_vd.yaml
72 73
```

B
Bin Lu 已提交
74
The validation `Top1 Acc` curve is shown below.
75 76 77 78 79 80

![](../../images/quick_start/r50_vd_acc.png)


### Finetune - ResNet50_vd pretrained model (Acc 79.12\%)

littletomatodonkey's avatar
fix doc  
littletomatodonkey 已提交
81
* Finetune ResNet50_vd model pretrained on the 1000-class Imagenet dataset
82 83

```shell
84
python3 tools/train.py -c ./configs/quick_start/ResNet50_vd_finetune.yaml
85 86 87 88 89 90 91 92 93
```

The validation `Top1 Acc` curve is shown below

![](../../images/quick_start/r50_vd_pretrained_acc.png)

Compare with training from scratch, it improve by 65\% to 94.02\%


94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
You can use the trained model to infer the result of image `docs/images/quick_start/flowers102/image_06739.jpg`. The command is as follows.


```shell
python3 tools/infer/infer.py \
    -i docs/images/quick_start/flowers102/image_06739.jpg \
    --model=ResNet50_vd \
    --pretrained_model="output/ResNet50_vd/best_model/ppcls" \
    --class_num=102
```

The output is as follows. Top-5 class ids and their scores are printed.

```
Current image file: docs/images/quick_start/flowers102/image_06739.jpg
    top1, class id: 0, probability: 0.5129
    top2, class id: 50, probability: 0.0671
    top3, class id: 18, probability: 0.0377
    top4, class id: 82, probability: 0.0238
    top5, class id: 54, probability: 0.0231
```

* Note: Results are different for different models, so you might get different results for the command.


119 120 121 122 123 124 125 126
### SSLD finetune - ResNet50_vd_ssld pretrained model (Acc 82.39\%)

Note: when finetuning model, which has been trained by SSLD, please use smaller learning rate in the middle of net.

```yaml
ARCHITECTURE:
    name: 'ResNet50_vd'
    params:
L
littletomatodonkey 已提交
127
        lr_mult_list: [0.5, 0.5, 0.6, 0.6, 0.8]
128 129 130 131 132 133
pretrained_model: "./pretrained/ResNet50_vd_ssld_pretrained"
```

Tringing script

```shell
134
python3 tools/train.py -c ./configs/quick_start/ResNet50_vd_ssld_finetune.yaml
135 136
```

littletomatodonkey's avatar
fix doc  
littletomatodonkey 已提交
137
Compare with finetune on the 79.12% pretrained model, it improve by 0.98\% to 95\%.
138 139 140 141 142 143 144


### More architecture - MobileNetV3

Training script

```shell
145
python3 tools/train.py -c ./configs/quick_start/MobileNetV3_large_x1_0_finetune.yaml
146 147 148 149 150 151 152 153 154 155 156 157
```

Compare with ResNet50_vd pretrained model, it decrease by 5% to 90%. Different architecture generates different performance, actually it is a task-oriented decision to apply the best performance model, should consider the inference time, storage, heterogeneous device, etc.


### RandomErasing

Data augmentation works when training data is small.

Training script

```shell
158
python3 tools/train.py -c ./configs/quick_start/ResNet50_vd_ssld_random_erasing_finetune.yaml
159 160 161 162 163 164 165 166 167 168 169 170
```

It improves by 1.27\% to 96.27\%

* Save ResNet50_vd pretrained model to experience next chapter.

```shell
cp -r output/ResNet50_vd/19/  ./pretrained/flowers102_R50_vd_final/
```

### Distillation

171
* Use `extra_list.txt` as unlabeled data, Note:
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
    * Samples in the `extra_list.txt` and `val_list.txt` don't have intersection
    * Because of in the source code, label information is unused, This is still unlabeled distillation
    * Teacher model use the pretrained_model trained on the flowers102 dataset, and student model use the MobileNetV3_large_x1_0 pretrained model(Acc 75.32\%) trained on the ImageNet1K dataset


```yaml
total_images: 7169
ARCHITECTURE:
    name: 'ResNet50_vd_distill_MobileNetV3_large_x1_0'
pretrained_model:
    - "./pretrained/flowers102_R50_vd_final/ppcls"
    - "./pretrained/MobileNetV3_large_x1_0_pretrained/”
TRAIN:
    file_list: "./dataset/flowers102/train_extra_list.txt"
```

Final training script

```shell
191
python3 tools/train.py -c ./configs/quick_start/R50_vd_distill_MV3_large_x1_0.yaml
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
```

It significantly imporve by 6.47% to 96.47% with more unlabeled data and teacher model.

### All accuracy


|Configuration | Top1 Acc |
|- |:-: |
| ResNet50_vd.yaml | 0.2735 |
| MobileNetV3_large_x1_0_finetune.yaml | 0.9000 |
| ResNet50_vd_finetune.yaml | 0.9402 |
| ResNet50_vd_ssld_finetune.yaml | 0.9500 |
| ResNet50_vd_ssld_random_erasing_finetune.yaml | 0.9627 |
| R50_vd_distill_MV3_large_x1_0.yaml | 0.9647 |


The whole accuracy curves are shown below


![](../../images/quick_start/all_acc.png)



* **NOTE**: As flowers102 is a small dataset, validatation accuracy maybe float 1%.

218
* Please refer to [Getting_started](./getting_started_en.md) for more details