提交 5992be4a 编写于 作者: C cuicheng01

add multilabel feature

上级 af9aae73
...@@ -25,58 +25,68 @@ tar -xf NUS-SCENE-dataset.tar ...@@ -25,58 +25,68 @@ tar -xf NUS-SCENE-dataset.tar
cd ../../ 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 ```bash
mkdir pretrained python tools/eval.py \
cd pretrained -c ./ppcls/configs/quick_start/professional/MobileNetV1_multilabel.yaml \
wget https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/ResNet50_vd_pretrained.pdparams -o Arch.pretrained="./output/MobileNetV1/best_model"
cd ../
``` ```
## Training ## Prediction
```shell ```bash
export CUDA_VISIBLE_DEVICES=0 python3 tools/infer.py
python -m paddle.distributed.launch \ -c ./ppcls/configs/quick_start/professional/MobileNetV1_multilabel.yaml \
--gpus="0" \ -o Arch.pretrained="./output/MobileNetV1/best_model"
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. 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 ```bash
python tools/eval.py \ python3 tools/export_model.py \
-c ./configs/quick_start/ResNet50_vd_multilabel.yaml \ -c ./ppcls/configs/quick_start/professional/MobileNetV1_multilabel.yaml \
-o pretrained_model="./output/ResNet50_vd/best_model/ppcls" \ -o Arch.pretrained="./output/MobileNetV1/best_model"
-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. The default path of the inference model is under the current path `./inference`
## Prediction ### Prediction based on prediction engine
Enter the deploy directory:
```bash ```bash
python tools/infer/infer.py \ cd ./deploy
-i "./dataset/NUS-WIDE-SCENE/NUS-SCENE-dataset/images/0199_434752251.jpg" \ ```
--model ResNet50_vd \
--pretrained_model "./output/ResNet50_vd/best_model/ppcls" \ Prediction based on prediction engine:
--use_gpu True \
--load_static_weights False \ ```
--multilabel True \ python3 python/predict_cls.py \
--class_num 33 -c configs/inference_multilabel_cls.yaml
``` ```
You will get multiple output such as the following: You will get multiple output such as the following:
```
class id: 3, probability: 0.6025 ```
class id: 23, probability: 0.5491 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): []
class id: 32, probability: 0.7006 ```
```
\ No newline at end of file
# 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:
#!/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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册