项目数据集介绍
包含四类奥特曼,迪迦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
# 安装paddleclas以及相关三方包(好像studio自带的已经够用了,无需安装了) !git clone https://gitee.com/paddlepaddle/PaddleClas.git -b release/2.2 # 我这里安装相关包时,花了30几分钟还有错误提示,不管他即可 #!pip install --upgrade -r PaddleClas/requirements.txt -i https://mirror.baidu.com/pypi/simple
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
# 忽略(垃圾)警告信息 # 在python中运行代码经常会遇到的情况是——代码可以正常运行但是会提示警告,有时特别讨厌。 # 那么如何来控制警告输出呢?其实很简单,python通过调用warnings模块中定义的warn()函数来发出警告。我们可以通过警告过滤器进行控制是否发出警告消息。 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
# -*- coding: utf-8 -*- # 根据官方paddleclas的提示,我们需要把图像变为两个txt文件 # 我们总共是200+100+100+150=550张图片,按照经典的划分方式0.8:0.2 # train_list.txt(训练集,440张图) # val_list.txt(验证集,110张图) # 先把路径搞定 比如:dataset/dijia/001.png ,读取到并写入txt # dataset/jieke/001.png # dataset/saiwen/001.png # dataset/tailuo/001.png dirpath = "aoteman" # 先得到总的txt后续再进行划分,因为要划分出验证集,所以要先打乱,因为原本是有序的 def get_all_txt(): all_list = [] i = 0 for root,dirs,files in os.walk(dirpath): # 分别代表根目录、文件夹、文件 for file in files: i = i + 1 # 文件中每行格式: 图像相对路径 图像的label_id(注意:中间有空格)。 # aoteman/dijia/001.png 0 # aoteman/jike/001.png 1 # aoteman/saiwen/001.png 2 # aoteman/tailuo/001.png 3 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
# 我们总共是200+100+100+150=550张图片,按照经典的划分方式0.8:0.2 # train_list.txt(训练集,440张图) # val_list.txt(验证集,110张图) # 思路 : 先把数据打乱,然后按照比例划分数据集 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
# 运行cell,生成txt 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 生成成功!
# 运行cell,生成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 生成成功!
# 将图片移动到paddleclas下面的数据集里面 # 至于为什么现在移动,也是我的一点小技巧,防止之前移动的话,生成的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进行训练
数据集核实完搞定成功的前提下,可以准备更改原文档的参数进行实现自己的图片分类了!
#windows在cmd中进入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对应的结果是迪迦,也就是说结果为迪迦,预测无误。
再次验证
# 再来一张其他试试,防止有意外情况,自行百度找图,在下面jpg替换即可 !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跑通。
后续我将推出安卓部署版本,冲冲冲!(如果我能行的话…)