还记得你的童年嘛?奥特曼分类他来了!
欢迎fork我的基于paddleclas的奥特曼图像分类项目,已经在社区开源,按照流程运行即可跑通项目
项目链接:https://aistudio.baidu.com/aistudio/projectdetail/2219455 如果还跑不通,没关系,本人在B站发了教程手把手教你完成奥特曼分类,跟着视频去运行项目, 视频链接:https://www.bilibili.com/video/BV1v341167M5 包教包会,希望对你们有帮助
项目背景
新的风暴已经出现,怎么能够停滞不前~
本人亲情之作,花费了不少的时间去完成了现在的数据集
包含
四类奥特曼:
迪迦、杰克、赛文和泰罗奥特曼。
唤醒你的童年~
女朋友还不认识奥特曼是什么?
甩给她!(当然后续搞个口红色号分类??也不是不可QAQ)
虽然只有四类奥特曼,但聪明的你自行补充完善这个项目我猜没什么毛病吧~
其实想偷懒,截图截得手麻了,中途试了用爬虫,感觉不带劲
项目如何实现?
采用paddleclas进行图像分类任务。 paddleclas官方文档连接如下:
https://gitee.com/paddlepaddle/PaddleClas/blob/release/2.2/docs/zh_CN/tutorials/quick_start_new_user.md
项目数据集介绍
包含四类奥特曼,迪迦200张、杰克100张、赛文100张和泰罗奥特曼150张。
!!!数据集完全由我一张一张截图而来,切勿作为其他用途,仅供个人学习!!! 友情提示:数据集仅供学习和个人使用,如果被告我不负责(孩子怕极了)
├── aoteman
│ ├── dijia
│ │ ├── 001.jpg
│ │ ├── 002.jpg
│ │ ├── 003.jpg
│ │ ├── ......
│ │ ├── 198.jpg
│ │ ├── 199.jpg
│ │ └── 200.jpg
│ ├── jieke
│ │ ├── 001.jpg
│ │ ├── 002.jpg
│ │ ├── 003.jpg
│ │ ├── ......
│ │ ├── 098.jpg
│ │ ├── 099.jpg
│ │ └── 100.jpg
│ ├── saiwen
│ │ ├── 001.jpg
│ │ ├── 002.jpg
│ │ ├── 003.jpg
│ │ ├── ......
│ │ ├── 098.jpg
│ │ ├── 099.jpg
│ │ └── 100.jpg
│ ├── tailuo
│ │ ├── 001.jpg
│ │ ├── 002.jpg
│ │ ├── 003.jpg
│ │ ├── ......
│ │ ├── 148.jpg
│ │ ├── 149.jpg
│ │ └── 150.jpg
话不多说,开整!
!python3 -c "import paddle; print(paddle.__version__)"
2.1.0
!unzip -oq /home/aistudio/data/data101651/aoteman.zip
!tree
!git clone https://gitee.com/paddlepaddle/PaddleClas.git -b release/2.2
Cloning into 'PaddleClas'...
remote: Enumerating objects: 538, done.[K
remote: Counting objects: 100% (538/538), done.[K
remote: Compressing objects: 100% (323/323), done.[K
remote: Total 15290 (delta 344), reused 349 (delta 210), pack-reused 14752[K
Receiving objects: 100% (15290/15290), 113.56 MiB | 12.55 MiB/s, done.
Resolving deltas: 100% (10236/10236), done.
Checking connectivity... done.
!pip list package
import warnings
warnings.filterwarnings("ignore")
数据处理
正常的代码逻辑:如下
1 读取数据
2 打乱数据
3 划分数据
4 数据预处理
(4数据预处理这个在paddleclas中进行处理了)
from sklearn.utils import shuffle
import os
import pandas as pd
import numpy as np
from PIL import Image
import paddle
import paddle.nn as nn
from paddle.io import Dataset
import paddle.vision.transforms as T
import paddle.nn.functional as F
from paddle.metric import Accuracy
import random
dirpath = "aoteman"
def get_all_txt():
all_list = []
i = 0
for root,dirs,files in os.walk(dirpath):
for file in files:
i = i + 1
if("dijia" in root):
all_list.append(os.path.join(root,file)+" 0\n")
if("jieke" in root):
all_list.append(os.path.join(root,file)+" 1\n")
if("saiwen" in root):
all_list.append(os.path.join(root,file)+" 2\n")
if("tailuo" in root):
all_list.append(os.path.join(root,file)+" 3\n")
allstr = ''.join(all_list)
f = open('all_list.txt','w',encoding='utf-8')
f.write(allstr)
return all_list , i
all_list,all_lenth = get_all_txt()
print(all_lenth-1)
550
random.shuffle(all_list)
random.shuffle(all_list)
train_size = int(all_lenth * 0.8)
train_list = all_list[:train_size]
val_list = all_list[train_size:]
print(len(train_list))
print(len(val_list))
440
110
train_txt = ''.join(train_list)
f_train = open('train_list.txt','w',encoding='utf-8')
f_train.write(train_txt)
f_train.close()
print("train_list.txt 生成成功!")
train_list.txt 生成成功!
val_txt = ''.join(val_list)
f_val = open('val_list.txt','w',encoding='utf-8')
f_val.write(val_txt)
f_val.close()
print("val_list.txt 生成成功!")
val_list.txt 生成成功!
!mv aoteman/ PaddleClas/dataset/
!mv all_list.txt PaddleClas/dataset/aoteman
!mv train_list.txt PaddleClas/dataset/aoteman
!mv val_list.txt PaddleClas/dataset/aoteman
采用paddleclas进行训练
数据集核实完搞定成功的前提下,可以准备更改原文档的参数进行实现自己的图片分类了!
%cd PaddleClas
!ls
/home/aistudio/PaddleClas
dataset hubconf.py MANIFEST.in README_ch.md requirements.txt
deploy __init__.py paddleclas.py README_en.md setup.py
docs LICENSE ppcls README.md tools
修改配置文件
主要是以下几点:分类数、图片总量、训练和验证的路径、图像尺寸、训练和预测的num_workers: 0才可以在aistudio跑通。
PaddleClas/ppcls/configs/quick_start/new_user/ShuffleNetV2_x0_25.yaml
# global configs
Global:
checkpoints: null
pretrained_model: null
device: gpu
output_dir: ./output/
save_interval: 20
eval_during_train: True
eval_interval: 10
epochs: 600
print_batch_step: 10
use_visualdl: True
# used for static mode and model export
image_shape: [3, 224, 224]
save_inference_dir: ./inference
# model architecture
Arch:
name: ShuffleNetV2_x0_25
class_num: 4
# loss function config for traing/eval process
Loss:
Train:
- CELoss:
weight: 1.0
Eval:
- CELoss:
weight: 1.0
Optimizer:
name: Momentum
momentum: 0.9
lr:
name: Cosine
learning_rate: 0.0125
warmup_epoch: 5
regularizer:
name: 'L2'
coeff: 0.00001
# data loader for train and eval
DataLoader:
Train:
dataset:
name: ImageNetDataset
image_root: ./dataset/
cls_label_path: ./dataset/aoteman/train_list.txt
transform_ops:
- DecodeImage:
to_rgb: True
channel_first: False
- ResizeImage:
resize_short: 256
- CropImage:
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: 16
drop_last: False
shuffle: True
loader:
num_workers: 0
use_shared_memory: True
Eval:
dataset:
name: ImageNetDataset
image_root: ./dataset/
cls_label_path: ./dataset/aoteman/val_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: 64
drop_last: False
shuffle: False
loader:
num_workers: 0
use_shared_memory: True
Infer:
infer_imgs: dataset/aoteman/predict_demo.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: Topk
topk: 4
class_id_map_file: ppcls/configs/quick_start/new_user/aoteman_label_list.txt
Metric:
Train:
- TopkAcc:
topk: [1, 4]
Eval:
- TopkAcc:
topk: [1, 4]
PaddleClas/ppcls/configs/quick_start/new_user/aoteman_label_list.txt
0 迪迦奥特曼
1 杰克奥特曼
2 赛文奥特曼
3 泰罗奥特曼
!export CUDA_VISIBLE_DEVICES=0
!python tools/train.py \
-c ./ppcls/configs/quick_start/new_user/ShuffleNetV2_x0_25.yaml
或许因为奥特曼之间的区别还是挺大的,最后的结果基本上都接近1了!
模型预测
验证
!python3 tools/infer.py \
-c ./ppcls/configs/quick_start/new_user/ShuffleNetV2_x0_25.yaml \
-o Infer.infer_imgs=dataset/aoteman/predict_demo.jpg \
-o Global.pretrained_model=output/ShuffleNetV2_x0_25/latest
/home/aistudio/PaddleClas/ppcls/arch/backbone/model_zoo/vision_transformer.py:15: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
from collections import Callable
[2021/07/26 09:56:19] root INFO:
===========================================================
== PaddleClas is powered by PaddlePaddle ! ==
===========================================================
== ==
== For more info please go to the following website. ==
== ==
== https://github.com/PaddlePaddle/PaddleClas ==
===========================================================
[2021/07/26 09:56:19] root INFO: Arch :
[2021/07/26 09:56:19] root INFO: class_num : 4
[2021/07/26 09:56:19] root INFO: name : ShuffleNetV2_x0_25
[2021/07/26 09:56:19] root INFO: DataLoader :
[2021/07/26 09:56:19] root INFO: Eval :
[2021/07/26 09:56:19] root INFO: dataset :
[2021/07/26 09:56:19] root INFO: cls_label_path : ./dataset/aoteman/val_list.txt
[2021/07/26 09:56:19] root INFO: image_root : ./dataset/
[2021/07/26 09:56:19] root INFO: name : ImageNetDataset
[2021/07/26 09:56:19] root INFO: transform_ops :
[2021/07/26 09:56:19] root INFO: DecodeImage :
[2021/07/26 09:56:19] root INFO: channel_first : False
[2021/07/26 09:56:19] root INFO: to_rgb : True
[2021/07/26 09:56:19] root INFO: ResizeImage :
[2021/07/26 09:56:19] root INFO: resize_short : 256
[2021/07/26 09:56:19] root INFO: CropImage :
[2021/07/26 09:56:19] root INFO: size : 224
[2021/07/26 09:56:19] root INFO: NormalizeImage :
[2021/07/26 09:56:19] root INFO: mean : [0.485, 0.456, 0.406]
[2021/07/26 09:56:19] root INFO: order :
[2021/07/26 09:56:19] root INFO: scale : 1.0/255.0
[2021/07/26 09:56:19] root INFO: std : [0.229, 0.224, 0.225]
[2021/07/26 09:56:19] root INFO: loader :
[2021/07/26 09:56:19] root INFO: num_workers : 0
[2021/07/26 09:56:19] root INFO: use_shared_memory : True
[2021/07/26 09:56:19] root INFO: sampler :
[2021/07/26 09:56:19] root INFO: batch_size : 64
[2021/07/26 09:56:19] root INFO: drop_last : False
[2021/07/26 09:56:19] root INFO: name : DistributedBatchSampler
[2021/07/26 09:56:19] root INFO: shuffle : False
[2021/07/26 09:56:19] root INFO: Train :
[2021/07/26 09:56:19] root INFO: dataset :
[2021/07/26 09:56:19] root INFO: cls_label_path : ./dataset/aoteman/train_list.txt
[2021/07/26 09:56:19] root INFO: image_root : ./dataset/
[2021/07/26 09:56:19] root INFO: name : ImageNetDataset
[2021/07/26 09:56:19] root INFO: transform_ops :
[2021/07/26 09:56:19] root INFO: DecodeImage :
[2021/07/26 09:56:19] root INFO: channel_first : False
[2021/07/26 09:56:19] root INFO: to_rgb : True
[2021/07/26 09:56:19] root INFO: ResizeImage :
[2021/07/26 09:56:19] root INFO: resize_short : 256
[2021/07/26 09:56:19] root INFO: CropImage :
[2021/07/26 09:56:19] root INFO: size : 224
[2021/07/26 09:56:19] root INFO: RandFlipImage :
[2021/07/26 09:56:19] root INFO: flip_code : 1
[2021/07/26 09:56:19] root INFO: NormalizeImage :
[2021/07/26 09:56:19] root INFO: mean : [0.485, 0.456, 0.406]
[2021/07/26 09:56:19] root INFO: order :
[2021/07/26 09:56:19] root INFO: scale : 1.0/255.0
[2021/07/26 09:56:19] root INFO: std : [0.229, 0.224, 0.225]
[2021/07/26 09:56:19] root INFO: loader :
[2021/07/26 09:56:19] root INFO: num_workers : 0
[2021/07/26 09:56:19] root INFO: use_shared_memory : True
[2021/07/26 09:56:19] root INFO: sampler :
[2021/07/26 09:56:19] root INFO: batch_size : 16
[2021/07/26 09:56:19] root INFO: drop_last : False
[2021/07/26 09:56:19] root INFO: name : DistributedBatchSampler
[2021/07/26 09:56:19] root INFO: shuffle : True
[2021/07/26 09:56:19] root INFO: Global :
[2021/07/26 09:56:19] root INFO: checkpoints : None
[2021/07/26 09:56:19] root INFO: device : gpu
[2021/07/26 09:56:19] root INFO: epochs : 600
[2021/07/26 09:56:19] root INFO: eval_during_train : True
[2021/07/26 09:56:19] root INFO: eval_interval : 10
[2021/07/26 09:56:19] root INFO: image_shape : [3, 224, 224]
[2021/07/26 09:56:19] root INFO: output_dir : ./output/
[2021/07/26 09:56:19] root INFO: pretrained_model : output/ShuffleNetV2_x0_25/latest
[2021/07/26 09:56:19] root INFO: print_batch_step : 10
[2021/07/26 09:56:19] root INFO: save_inference_dir : ./inference
[2021/07/26 09:56:19] root INFO: save_interval : 20
[2021/07/26 09:56:19] root INFO: use_visualdl : True
[2021/07/26 09:56:19] root INFO: Infer :
[2021/07/26 09:56:19] root INFO: PostProcess :
[2021/07/26 09:56:19] root INFO: class_id_map_file : ppcls/configs/quick_start/new_user/aoteman_label_list.txt
[2021/07/26 09:56:19] root INFO: name : Topk
[2021/07/26 09:56:19] root INFO: topk : 4
[2021/07/26 09:56:19] root INFO: batch_size : 10
[2021/07/26 09:56:19] root INFO: infer_imgs : dataset/aoteman/predict_demo.jpg
[2021/07/26 09:56:19] root INFO: transforms :
[2021/07/26 09:56:19] root INFO: DecodeImage :
[2021/07/26 09:56:19] root INFO: channel_first : False
[2021/07/26 09:56:19] root INFO: to_rgb : True
[2021/07/26 09:56:19] root INFO: ResizeImage :
[2021/07/26 09:56:19] root INFO: resize_short : 256
[2021/07/26 09:56:19] root INFO: CropImage :
[2021/07/26 09:56:19] root INFO: size : 224
[2021/07/26 09:56:19] root INFO: NormalizeImage :
[2021/07/26 09:56:19] root INFO: mean : [0.485, 0.456, 0.406]
[2021/07/26 09:56:19] root INFO: order :
[2021/07/26 09:56:19] root INFO: scale : 1.0/255.0
[2021/07/26 09:56:19] root INFO: std : [0.229, 0.224, 0.225]
[2021/07/26 09:56:19] root INFO: ToCHWImage : None
[2021/07/26 09:56:19] root INFO: Loss :
[2021/07/26 09:56:19] root INFO: Eval :
[2021/07/26 09:56:19] root INFO: CELoss :
[2021/07/26 09:56:19] root INFO: weight : 1.0
[2021/07/26 09:56:19] root INFO: Train :
[2021/07/26 09:56:19] root INFO: CELoss :
[2021/07/26 09:56:19] root INFO: weight : 1.0
[2021/07/26 09:56:19] root INFO: Metric :
[2021/07/26 09:56:19] root INFO: Eval :
[2021/07/26 09:56:19] root INFO: TopkAcc :
[2021/07/26 09:56:19] root INFO: topk : [1, 4]
[2021/07/26 09:56:19] root INFO: Train :
[2021/07/26 09:56:19] root INFO: TopkAcc :
[2021/07/26 09:56:19] root INFO: topk : [1, 4]
[2021/07/26 09:56:19] root INFO: Optimizer :
[2021/07/26 09:56:19] root INFO: lr :
[2021/07/26 09:56:19] root INFO: learning_rate : 0.0125
[2021/07/26 09:56:19] root INFO: name : Cosine
[2021/07/26 09:56:19] root INFO: warmup_epoch : 5
[2021/07/26 09:56:19] root INFO: momentum : 0.9
[2021/07/26 09:56:19] root INFO: name : Momentum
[2021/07/26 09:56:19] root INFO: regularizer :
[2021/07/26 09:56:19] root INFO: coeff : 1e-05
[2021/07/26 09:56:19] root INFO: name : L2
W0726 09:56:19.698617 32194 device_context.cc:404] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 10.1, Runtime API Version: 10.1
W0726 09:56:19.703610 32194 device_context.cc:422] device: 0, cuDNN Version: 7.6.
[2021/07/26 09:56:24] root INFO: train with paddle 2.1.0 and device CUDAPlace(0)
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/tensor/creation.py:125: DeprecationWarning: `np.object` is a deprecated alias for the builtin `object`. To silence this warning, use `object` by itself. Doing this will not modify any behavior and is safe.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
if data.dtype == np.object:
[{'class_ids': [0, 3, 1, 2], 'scores': [0.99999, 1e-05, 0.0, 0.0], 'file_name': 'dataset/aoteman/predict_demo.jpg', 'label_names': ['迪迦奥特曼', '泰罗奥特曼', '杰克奥特曼', '赛文奥特曼']}]
真实的图片是:
预测的结果是:
‘class_ids’: [0, 3, 1, 2], ‘scores’: [0.99999, 1e-05, 0.0, 0.0],‘label_names’: [‘迪迦奥特曼’, ‘泰罗奥特曼’, ‘杰克奥特曼’, ‘赛文奥特曼’]
也就是说0的概率最大,0对应的结果是迪迦,也就是说结果为迪迦,预测无误。
再次验证
!python3 tools/infer.py \
-c ./ppcls/configs/quick_start/new_user/ShuffleNetV2_x0_25.yaml \
-o Infer.infer_imgs=dataset/aoteman/predict_tailuo.jpg \
-o Global.pretrained_model=output/ShuffleNetV2_x0_25/latest
/home/aistudio/PaddleClas/ppcls/arch/backbone/model_zoo/vision_transformer.py:15: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
from collections import Callable
[2021/07/26 09:57:12] root INFO:
===========================================================
== PaddleClas is powered by PaddlePaddle ! ==
===========================================================
== ==
== For more info please go to the following website. ==
== ==
== https://github.com/PaddlePaddle/PaddleClas ==
===========================================================
[2021/07/26 09:57:12] root INFO: Arch :
[2021/07/26 09:57:12] root INFO: class_num : 4
[2021/07/26 09:57:12] root INFO: name : ShuffleNetV2_x0_25
[2021/07/26 09:57:12] root INFO: DataLoader :
[2021/07/26 09:57:12] root INFO: Eval :
[2021/07/26 09:57:12] root INFO: dataset :
[2021/07/26 09:57:12] root INFO: cls_label_path : ./dataset/aoteman/val_list.txt
[2021/07/26 09:57:12] root INFO: image_root : ./dataset/
[2021/07/26 09:57:12] root INFO: name : ImageNetDataset
[2021/07/26 09:57:12] root INFO: transform_ops :
[2021/07/26 09:57:12] root INFO: DecodeImage :
[2021/07/26 09:57:12] root INFO: channel_first : False
[2021/07/26 09:57:12] root INFO: to_rgb : True
[2021/07/26 09:57:12] root INFO: ResizeImage :
[2021/07/26 09:57:12] root INFO: resize_short : 256
[2021/07/26 09:57:12] root INFO: CropImage :
[2021/07/26 09:57:12] root INFO: size : 224
[2021/07/26 09:57:12] root INFO: NormalizeImage :
[2021/07/26 09:57:12] root INFO: mean : [0.485, 0.456, 0.406]
[2021/07/26 09:57:12] root INFO: order :
[2021/07/26 09:57:12] root INFO: scale : 1.0/255.0
[2021/07/26 09:57:12] root INFO: std : [0.229, 0.224, 0.225]
[2021/07/26 09:57:12] root INFO: loader :
[2021/07/26 09:57:12] root INFO: num_workers : 0
[2021/07/26 09:57:12] root INFO: use_shared_memory : True
[2021/07/26 09:57:12] root INFO: sampler :
[2021/07/26 09:57:12] root INFO: batch_size : 64
[2021/07/26 09:57:12] root INFO: drop_last : False
[2021/07/26 09:57:12] root INFO: name : DistributedBatchSampler
[2021/07/26 09:57:12] root INFO: shuffle : False
[2021/07/26 09:57:12] root INFO: Train :
[2021/07/26 09:57:12] root INFO: dataset :
[2021/07/26 09:57:12] root INFO: cls_label_path : ./dataset/aoteman/train_list.txt
[2021/07/26 09:57:12] root INFO: image_root : ./dataset/
[2021/07/26 09:57:12] root INFO: name : ImageNetDataset
[2021/07/26 09:57:12] root INFO: transform_ops :
[2021/07/26 09:57:12] root INFO: DecodeImage :
[2021/07/26 09:57:12] root INFO: channel_first : False
[2021/07/26 09:57:12] root INFO: to_rgb : True
[2021/07/26 09:57:12] root INFO: ResizeImage :
[2021/07/26 09:57:12] root INFO: resize_short : 256
[2021/07/26 09:57:12] root INFO: CropImage :
[2021/07/26 09:57:12] root INFO: size : 224
[2021/07/26 09:57:12] root INFO: RandFlipImage :
[2021/07/26 09:57:12] root INFO: flip_code : 1
[2021/07/26 09:57:12] root INFO: NormalizeImage :
[2021/07/26 09:57:12] root INFO: mean : [0.485, 0.456, 0.406]
[2021/07/26 09:57:12] root INFO: order :
[2021/07/26 09:57:12] root INFO: scale : 1.0/255.0
[2021/07/26 09:57:12] root INFO: std : [0.229, 0.224, 0.225]
[2021/07/26 09:57:12] root INFO: loader :
[2021/07/26 09:57:12] root INFO: num_workers : 0
[2021/07/26 09:57:12] root INFO: use_shared_memory : True
[2021/07/26 09:57:12] root INFO: sampler :
[2021/07/26 09:57:12] root INFO: batch_size : 16
[2021/07/26 09:57:12] root INFO: drop_last : False
[2021/07/26 09:57:12] root INFO: name : DistributedBatchSampler
[2021/07/26 09:57:12] root INFO: shuffle : True
[2021/07/26 09:57:12] root INFO: Global :
[2021/07/26 09:57:12] root INFO: checkpoints : None
[2021/07/26 09:57:12] root INFO: device : gpu
[2021/07/26 09:57:12] root INFO: epochs : 600
[2021/07/26 09:57:12] root INFO: eval_during_train : True
[2021/07/26 09:57:12] root INFO: eval_interval : 10
[2021/07/26 09:57:12] root INFO: image_shape : [3, 224, 224]
[2021/07/26 09:57:12] root INFO: output_dir : ./output/
[2021/07/26 09:57:12] root INFO: pretrained_model : output/ShuffleNetV2_x0_25/latest
[2021/07/26 09:57:12] root INFO: print_batch_step : 10
[2021/07/26 09:57:12] root INFO: save_inference_dir : ./inference
[2021/07/26 09:57:12] root INFO: save_interval : 20
[2021/07/26 09:57:12] root INFO: use_visualdl : True
[2021/07/26 09:57:12] root INFO: Infer :
[2021/07/26 09:57:12] root INFO: PostProcess :
[2021/07/26 09:57:12] root INFO: class_id_map_file : ppcls/configs/quick_start/new_user/aoteman_label_list.txt
[2021/07/26 09:57:12] root INFO: name : Topk
[2021/07/26 09:57:12] root INFO: topk : 4
[2021/07/26 09:57:12] root INFO: batch_size : 10
[2021/07/26 09:57:12] root INFO: infer_imgs : dataset/aoteman/predict_tailuo.jpg
[2021/07/26 09:57:12] root INFO: transforms :
[2021/07/26 09:57:12] root INFO: DecodeImage :
[2021/07/26 09:57:12] root INFO: channel_first : False
[2021/07/26 09:57:12] root INFO: to_rgb : True
[2021/07/26 09:57:12] root INFO: ResizeImage :
[2021/07/26 09:57:12] root INFO: resize_short : 256
[2021/07/26 09:57:12] root INFO: CropImage :
[2021/07/26 09:57:12] root INFO: size : 224
[2021/07/26 09:57:12] root INFO: NormalizeImage :
[2021/07/26 09:57:12] root INFO: mean : [0.485, 0.456, 0.406]
[2021/07/26 09:57:12] root INFO: order :
[2021/07/26 09:57:12] root INFO: scale : 1.0/255.0
[2021/07/26 09:57:12] root INFO: std : [0.229, 0.224, 0.225]
[2021/07/26 09:57:12] root INFO: ToCHWImage : None
[2021/07/26 09:57:12] root INFO: Loss :
[2021/07/26 09:57:12] root INFO: Eval :
[2021/07/26 09:57:12] root INFO: CELoss :
[2021/07/26 09:57:12] root INFO: weight : 1.0
[2021/07/26 09:57:12] root INFO: Train :
[2021/07/26 09:57:12] root INFO: CELoss :
[2021/07/26 09:57:12] root INFO: weight : 1.0
[2021/07/26 09:57:12] root INFO: Metric :
[2021/07/26 09:57:12] root INFO: Eval :
[2021/07/26 09:57:12] root INFO: TopkAcc :
[2021/07/26 09:57:12] root INFO: topk : [1, 4]
[2021/07/26 09:57:12] root INFO: Train :
[2021/07/26 09:57:12] root INFO: TopkAcc :
[2021/07/26 09:57:12] root INFO: topk : [1, 4]
[2021/07/26 09:57:12] root INFO: Optimizer :
[2021/07/26 09:57:12] root INFO: lr :
[2021/07/26 09:57:12] root INFO: learning_rate : 0.0125
[2021/07/26 09:57:12] root INFO: name : Cosine
[2021/07/26 09:57:12] root INFO: warmup_epoch : 5
[2021/07/26 09:57:12] root INFO: momentum : 0.9
[2021/07/26 09:57:12] root INFO: name : Momentum
[2021/07/26 09:57:12] root INFO: regularizer :
[2021/07/26 09:57:12] root INFO: coeff : 1e-05
[2021/07/26 09:57:12] root INFO: name : L2
W0726 09:57:12.110759 32311 device_context.cc:404] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 10.1, Runtime API Version: 10.1
W0726 09:57:12.115746 32311 device_context.cc:422] device: 0, cuDNN Version: 7.6.
[2021/07/26 09:57:17] root INFO: train with paddle 2.1.0 and device CUDAPlace(0)
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/tensor/creation.py:125: DeprecationWarning: `np.object` is a deprecated alias for the builtin `object`. To silence this warning, use `object` by itself. Doing this will not modify any behavior and is safe.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
if data.dtype == np.object:
[{'class_ids': [3, 2, 1, 0], 'scores': [0.98939, 0.01061, 0.0, 0.0], 'file_name': 'dataset/aoteman/predict_tailuo.jpg', 'label_names': ['泰罗奥特曼', '赛文奥特曼', '杰克奥特曼', '迪迦奥特曼']}]
真实的图片是:
预测的结果是:
‘class_ids’: [3, 2, 1, 0], ‘scores’: [0.98939, 0.01061, 0.0, 0.0],‘label_names’: [‘泰罗奥特曼’, ‘赛文奥特曼’, ‘杰克奥特曼’, ‘迪迦奥特曼’]
也就是说3的概率为0.98939,最大,3对应的结果是泰罗,也就是说结果为泰罗,预测无误。
总结
项目总结
- 使用下来,用了很多版本的paddleclas,比如2.1,2.2,develop最后还是选择使用了2.2
- 版本差异如下:
2.1 生成的模型是文件夹存储的形式,并且有最佳模型文件 2.2 生成的模型文件直接排序在一个大文件夹下、支持写一个预测类别文件,预测输出时直接可以对照看是哪个类别。 - 使用paddleclas不管是哪个版本,最主要的还是数据处理和调参
3.1 数据处理,将信息转变为txt:相对路径+空格+类别 3.2 调参,变成自己的对应信息 主要是以下几点:分类数、图片总量、训练和验证的路径、图像尺寸、训练和预测的num_workers: 0才可以在aistudio跑通。 - 后续我将推出安卓部署版本,冲冲冲!(如果我能行的话…)
个人总结
全网同名: iterhui
我在AI Studio上获得钻石等级,点亮9个徽章,来互关呀~
https://aistudio.baidu.com/aistudio/personalcenter/thirdview/643467
|