diff --git a/docs/en/advanced_tutorials/multilabel/multilabel_en.md b/docs/en/advanced_tutorials/multilabel/multilabel_en.md index 29a18c181bb2dc474a7a368c5db81dd198d7a5e2..eab2890843e0caa0d86ff25739e876fd31a60eca 100644 --- a/docs/en/advanced_tutorials/multilabel/multilabel_en.md +++ b/docs/en/advanced_tutorials/multilabel/multilabel_en.md @@ -25,58 +25,68 @@ tar -xf NUS-SCENE-dataset.tar cd ../../ ``` -## Environment +## Training -### Download pretrained model +```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 +``` -You can use the following commands to download the pretrained model of ResNet50_vd. +After training for 10 epochs, the best accuracy over the validation set should be around 0.95. + +## Evaluation ```bash -mkdir pretrained -cd pretrained -wget https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/ResNet50_vd_pretrained.pdparams -cd ../ +python tools/eval.py \ + -c ./ppcls/configs/quick_start/professional/MobileNetV1_multilabel.yaml \ + -o Arch.pretrained="./output/MobileNetV1/best_model" ``` -## Training +## Prediction -```shell -export CUDA_VISIBLE_DEVICES=0 -python -m paddle.distributed.launch \ - --gpus="0" \ - tools/train.py \ - -c ./configs/quick_start/ResNet50_vd_multilabel.yaml +```bash +python3 tools/infer.py + -c ./ppcls/configs/quick_start/professional/MobileNetV1_multilabel.yaml \ + -o Arch.pretrained="./output/MobileNetV1/best_model" ``` -After training for 10 epochs, the best accuracy over the validation set should be around 0.72. +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': []}] +``` -## Evaluation +## Prediction based on prediction engine + +### Export model ```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 +python3 tools/export_model.py \ + -c ./ppcls/configs/quick_start/professional/MobileNetV1_multilabel.yaml \ + -o Arch.pretrained="./output/MobileNetV1/best_model" ``` -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. +The default path of the inference model is under the current path `./inference` -## Prediction +### Prediction based on prediction engine + +Enter the deploy directory: ```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 +cd ./deploy +``` + +Prediction based on prediction engine: + +``` +python3 python/predict_cls.py \ + -c configs/inference_multilabel_cls.yaml ``` 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 + +``` +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): [] +``` diff --git a/ppcls/configs/quick_start/MobileNetV1_multilabel.yaml b/ppcls/configs/quick_start/MobileNetV1_multilabel.yaml deleted file mode 100644 index e9c021b65200ca6d3df369c52717f10078f9d9ee..0000000000000000000000000000000000000000 --- a/ppcls/configs/quick_start/MobileNetV1_multilabel.yaml +++ /dev/null @@ -1,129 +0,0 @@ -# global configs -Global: - checkpoints: null - pretrained_model: null - output_dir: ./output/ - device: gpu - save_interval: 1 - eval_during_train: True - eval_interval: 1 - epochs: 10 - print_batch_step: 10 - use_visualdl: False - # used for static mode and model export - image_shape: [3, 224, 224] - save_inference_dir: ./inference - use_multilabel: True -# model architecture -Arch: - name: MobileNetV1 - class_num: 33 - pretrained: True - -# loss function config for traing/eval process -Loss: - Train: - - MultiLabelLoss: - weight: 1.0 - Eval: - - MultiLabelLoss: - weight: 1.0 - - -Optimizer: - name: Momentum - momentum: 0.9 - lr: - name: Cosine - learning_rate: 0.1 - regularizer: - name: 'L2' - coeff: 0.00004 - - -# data loader for train and eval -DataLoader: - Train: - dataset: - name: MultiLabelDataset - image_root: ./dataset/NUS-SCENE-dataset/images/ - cls_label_path: ./dataset/NUS-SCENE-dataset/multilabel_train_list.txt - transform_ops: - - DecodeImage: - to_rgb: True - channel_first: False - - RandCropImage: - size: 224 - - RandFlipImage: - flip_code: 1 - - NormalizeImage: - scale: 1.0/255.0 - mean: [0.485, 0.456, 0.406] - std: [0.229, 0.224, 0.225] - order: '' - - sampler: - name: DistributedBatchSampler - batch_size: 64 - drop_last: False - shuffle: True - loader: - num_workers: 4 - use_shared_memory: True - - Eval: - dataset: - name: MultiLabelDataset - image_root: ./dataset/NUS-SCENE-dataset/images/ - cls_label_path: ./dataset/NUS-SCENE-dataset/multilabel_test_list.txt - transform_ops: - - DecodeImage: - to_rgb: True - channel_first: False - - ResizeImage: - resize_short: 256 - - CropImage: - size: 224 - - NormalizeImage: - scale: 1.0/255.0 - mean: [0.485, 0.456, 0.406] - std: [0.229, 0.224, 0.225] - order: '' - sampler: - name: DistributedBatchSampler - batch_size: 256 - drop_last: False - shuffle: False - loader: - num_workers: 4 - use_shared_memory: True - -Infer: - infer_imgs: dataset/NUS-SCENE-dataset/images/0001_109549716.jpg - batch_size: 10 - transforms: - - DecodeImage: - to_rgb: True - channel_first: False - - ResizeImage: - resize_short: 256 - - CropImage: - size: 224 - - NormalizeImage: - scale: 1.0/255.0 - mean: [0.485, 0.456, 0.406] - std: [0.229, 0.224, 0.225] - order: '' - - ToCHWImage: - PostProcess: - name: MutiLabelTopk - topk: 5 - class_id_map_file: None - -Metric: - Train: - - HammingDistance: - - AccuracyScore: - Eval: - - HammingDistance: - - AccuracyScore: diff --git a/train.sh b/train.sh deleted file mode 100755 index 47ae2a68ee94fdd27cc43364b3a9f59bf874f439..0000000000000000000000000000000000000000 --- a/train.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env bash - -# for single card train -# python3.7 tools/train.py -c ./ppcls/configs/ImageNet/ResNet/ResNet50.yaml - -# for multi-cards train -python3.7 -m paddle.distributed.launch --gpus="0" tools/train.py -c ./MobileNetV2.yaml