数据
数据集结构
├── train
│ ├── n01440764
│ │ ├── n01440764_10026.JPEG
│ │ ├── n01440764_10027.JPEG
├── train_list.txt
…
├── val
│ ├── ILSVRC2012_val_00000001.JPEG
│ ├── ILSVRC2012_val_00000002.JPEG
├── val_list.txt
训练
- 修改配置文件
使用PPLCNET预训练模型,使用位于ppcls/configs/ImageNet/PPLCNet/PPLCNet_x1_0.yaml为模型进行修改,设置参数如下:
#设置训练次数
Global:
epochs: 1000
DataLoader:
Train:
dataset:
name: ImageNetDataset
image_root: ./dataset/fl/
cls_label_path: ./dataset/fl/train_list.txt
sampler:
batch_size: 10 # 一次训练图片数量
loader:
num_workers: 6 #子进程数
- 开始训练命令
python3 -m paddle.distributed.launch --gpus="0,1,2,3" tools/train.py -c PPLCNet/PPLCNet_x1_0.yaml
测试
python3 tools/eval.py -c PPLCNet/PPLCNet_x1_0.yaml -o Global.pretrained_model=output/PPLCNet_x1_0/best_model
部署
- 导出模型
python3 tools/export_model.py PPLCNet/PPLCNet_x1_0.yaml -o Global.pretrained_model=output/PPLCNet_x1_0/best_model -o Global.save_inference_dir=deploy/models/PPLCNet_x1_0_infer
- 基于代码的模型使用
from paddleclas import PaddleClas
clas = PaddleClas(inference_model_dir='deploy/models/PPLCNet_x1_0_infer')
infer_imgs='docs/images/deployment/whl_demo.jpg'
result=clas.predict(infer_imgs)
print(next(result))