用PaddlePaddle实现图像分类-ShuffleNetV2(动态图版)

项目简介

本项目使用paddle实现图像分类模型 ShuffleNet-V2网络的训练和预测,建议使用GPU训练。静态图版本请查看:用PaddlePaddle实现图像分类-ShuffleNetV2

下载安装命令

## CPU版本安装命令
pip install -f https://paddlepaddle.org.cn/pip/oschina/cpu paddlepaddle

## GPU版本安装命令
pip install -f https://paddlepaddle.org.cn/pip/oschina/gpu paddlepaddle-gpu

模型简介

设计准则

作者首先测试了几个轻量级网络模型的运行时间,并进行了分解,从而提出了四个轻量级网络的准则,不同模型在相同FLOPs情况下运行时间对比图如下: 用PaddlePaddle实现图像分类-ShuffleNetV2(动态图版)
上图a)和图b)分别是在GPU和ARM运行相同FLOPs的模型的时间对比图,由上图我们可以发现尽管模型的FLOPs相同,但是模型的运行速度还是存在差异,所以需要进一步的去分析模型中各个模块的运行速度,如下图: 用PaddlePaddle实现图像分类-ShuffleNetV2(动态图版)
由上图可以看到,相同FLOPs的两个模型,各部分的运行时间存在着明显的差异。这种不一致主要归结为两个原因:1)影响速度的不仅仅是FLOPs,还有内存访问成本(Memory Access Cost,MAC);2)模型的并行程度也会影响速度,并行度高的模型速度相对更快。因此作者结合理论与实践得到了四条实用的设计原则。

  1. 同等通道大小最小化内存访问成本——使用1×11/times 11×1卷积平衡输入和输出的通道大小
  2. 过量使用分组卷积会增加MAC——分组卷积要谨慎实用,注意分组数
  3. 网络碎片化会降低并行度,一些网络如inception等倾向于采用”多路”结构,既存在一个block中有很多不同的小卷积或pooling,这容易造成网络碎片化,降低并行度。——避免网络碎片化
  4. 不能忽略元素级别的操作,例如ReLU和Add等操作,这些操作虽然FLOPs较小,但是MAC较大。——减少元素级运算

网络结构

根据上述四条准则,作者分析了ShuffleNet-V1设计的不足,并在此基础上改进得到了Shuffle-V2,两者模块上的对比如下图所示: 用PaddlePaddle实现图像分类-ShuffleNetV2(动态图版)
(a): the basic ShuffleNet-V1 unit; (b) the ShuffleNet-V1 unit for spatial down sampling (2×); (c) ShuffleNet-V2 basic unit; (d) ShuffleNet-V2 unit for spatial down sampling (2×)
ShuffleNet-V2 相对与V1,引入了一种新的运算:channel split。具体来说,在开始时先将输入特征图在通道维度分成两个分支:通道数分别为 C′C^{‘}C  C−C′C – C^{‘}CC ,实际实现时 C′=C/2C^{‘} = C / 2C=C/2 。左边分支做同等映射,右边的分支包含3个连续的卷积,并且输入和输出通道相同,这符合准则1。而且两个1×1卷积不再是组卷积,这符合准则2,另外两个分支相当于已经分成两组。两个分支的输出不再是Add元素,而是concat在一起,紧接着是对两个分支concat结果进行channle shuffle,以保证两个分支信息交流。其实concat和channel shuffle可以和下一个模块单元的channel split合成一个元素级运算,这符合准则4。整体网络结果如下表:
用PaddlePaddle实现图像分类-ShuffleNetV2(动态图版)
论文原文:ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design
参考链接:ShuffleNetV2:轻量级CNN网络中的桂冠

 

整体项目资源

In[1]

!tree
.
├── 169424.ipynb
├── data
│   └── data2815
│       └── flower_photos.zip
├── logs
│   └── train.log
├── model-params
│   └── params.pdparams
└── work
    ├── config.py
    ├── eval.py
    ├── network.py
    ├── __pycache__
    │   ├── config.cpython-35.pyc
    │   ├── config.cpython-37.pyc
    │   ├── network.cpython-35.pyc
    │   ├── network.cpython-37.pyc
    │   ├── reader.cpython-35.pyc
    │   ├── reader.cpython-37.pyc
    │   ├── utils.cpython-35.pyc
    │   └── utils.cpython-37.pyc
    ├── reader.py
    ├── train.py
    └── utils.py

6 directories, 18 files

 

数据介绍

使用公开鲜花据集,数据集压缩包里包含五个文件夹,每个文件夹一种花卉。分别是雏菊,蒲公英,玫瑰,向日葵,郁金香。每种各690-890张不等

In[1]

# 解压花朵数据集
!cd data/data2815 && unzip -qo flower_photos.zip

 

预处理数据,将其转化为需要的格式

In[2]

# 预处理数据,将其转化为标准格式。同时将数据拆分成两份,以便训练和计算预估准确率
import codecs
import os
import random
import shutil
from PIL import Image

train_ratio = 4.0 / 5

all_file_dir = 'data/data2815'
class_list = [c for c in os.listdir(all_file_dir) if os.path.isdir(os.path.join(all_file_dir, c)) and not c.endswith('Set') and not c.startswith('.')]
class_list.sort()
print(class_list)
train_image_dir = os.path.join(all_file_dir, "trainImageSet")
if not os.path.exists(train_image_dir):
    os.makedirs(train_image_dir)
    
eval_image_dir = os.path.join(all_file_dir, "evalImageSet")
if not os.path.exists(eval_image_dir):
    os.makedirs(eval_image_dir)

train_file = codecs.open(os.path.join(all_file_dir, "train.txt"), 'w')
eval_file = codecs.open(os.path.join(all_file_dir, "eval.txt"), 'w')

with codecs.open(os.path.join(all_file_dir, "label_list.txt"), "w") as label_list:
    label_id = 0
    for class_dir in class_list:
        label_list.write("{0}/t{1}/n".format(label_id, class_dir))
        image_path_pre = os.path.join(all_file_dir, class_dir)
        for file in os.listdir(image_path_pre):
            try:
                img = Image.open(os.path.join(image_path_pre, file))
                if random.uniform(0, 1) <= train_ratio:
                    shutil.copyfile(os.path.join(image_path_pre, file), os.path.join(train_image_dir, file))
                    train_file.write("{0}/t{1}/n".format(os.path.join(train_image_dir, file), label_id))
                else:
                    shutil.copyfile(os.path.join(image_path_pre, file), os.path.join(eval_image_dir, file))
                    eval_file.write("{0}/t{1}/n".format(os.path.join(eval_image_dir, file), label_id))
            except Exception as e:
                pass
                # 存在一些文件打不开,此处需要稍作清洗
        label_id += 1
            
train_file.close()
eval_file.close()
['daisy', 'dandelion', 'roses', 'sunflowers', 'tulips']

 

训练主体

In[3]

!python work/train.py
2020-03-09 13:33:01,475-INFO: input_size: [3, 224, 224]
[2020-03-09 13:33:01,475.475] config.py [line:77] INFO: input_size: [3, 224, 224]
2020-03-09 13:33:01,475-INFO: class_dim: 5
[2020-03-09 13:33:01,475.475] config.py [line:78] INFO: class_dim: 5
2020-03-09 13:33:01,476-INFO: continue_train: True
[2020-03-09 13:33:01,476.476] config.py [line:79] INFO: continue_train: True
2020-03-09 13:33:01,476-INFO: train_image_count: 2893
[2020-03-09 13:33:01,476.476] config.py [line:80] INFO: train_image_count: 2893
2020-03-09 13:33:01,476-INFO: eval_image_count: 777
[2020-03-09 13:33:01,476.476] config.py [line:81] INFO: eval_image_count: 777
2020-03-09 13:33:01,476-INFO: num_epochs: 20
[2020-03-09 13:33:01,476.476] config.py [line:82] INFO: num_epochs: 20
2020-03-09 13:33:01,476-INFO: train_batch_size: 128
[2020-03-09 13:33:01,476.476] config.py [line:83] INFO: train_batch_size: 128
2020-03-09 13:33:01,476-INFO: mean_rgb: [127.5, 127.5, 127.5]
[2020-03-09 13:33:01,476.476] config.py [line:84] INFO: mean_rgb: [127.5, 127.5, 127.5]
2020-03-09 13:33:01,476-INFO: save_model_dir: ./model-params/params
[2020-03-09 13:33:01,476.476] config.py [line:85] INFO: save_model_dir: ./model-params/params
2020-03-09 13:33:01,479-INFO: start train
[2020-03-09 13:33:01,479.479] train.py [line:56] INFO: start train
W0309 13:33:02.382967    93 device_context.cc:237] Please NOTE: device: 0, CUDA Capability: 70, Driver API Version: 10.1, Runtime API Version: 9.0
W0309 13:33:02.386919    93 device_context.cc:245] device: 0, cuDNN Version: 7.3.
2020-03-09 13:33:03,926-INFO: use SGD optimizer, learning rate boundaries: [176, 308, 396] values: [0.002, 0.001, 0.0005, 0.0002]
[2020-03-09 13:33:03,926.926] train.py [line:28] INFO: use SGD optimizer, learning rate boundaries: [176, 308, 396] values: [0.002, 0.001, 0.0005, 0.0002]
2020-03-09 13:33:12,329-INFO: loss at epoch 0 step 5: [1.5741346], acc: [0.3515625]
[2020-03-09 13:33:12,329.329] train.py [line:93] INFO: loss at epoch 0 step 5: [1.5741346], acc: [0.3515625]
2020-03-09 13:33:18,794-INFO: loss at epoch 0 step 10: [1.4842154], acc: [0.3984375]
[2020-03-09 13:33:18,794.794] train.py [line:93] INFO: loss at epoch 0 step 10: [1.4842154], acc: [0.3984375]
2020-03-09 13:33:25,579-INFO: loss at epoch 0 step 15: [1.427836], acc: [0.4140625]
[2020-03-09 13:33:25,579.579] train.py [line:93] INFO: loss at epoch 0 step 15: [1.427836], acc: [0.4140625]
2020-03-09 13:33:32,131-INFO: loss at epoch 0 step 20: [1.2791212], acc: [0.4765625]
[2020-03-09 13:33:32,131.131] train.py [line:93] INFO: loss at epoch 0 step 20: [1.2791212], acc: [0.4765625]
2020-03-09 13:33:34,221-INFO: epoch 0 acc: [0.3643466]
[2020-03-09 13:33:34,221.221] train.py [line:96] INFO: epoch 0 acc: [0.3643466]
2020-03-09 13:33:34,222-INFO: current epoch 0 acc: [0.3643466] better than last acc: 0.0, save model
[2020-03-09 13:33:34,222.222] train.py [line:99] INFO: current epoch 0 acc: [0.3643466] better than last acc: 0.0, save model
2020-03-09 13:33:42,153-INFO: loss at epoch 1 step 5: [1.2742089], acc: [0.3984375]
[2020-03-09 13:33:42,153.153] train.py [line:93] INFO: loss at epoch 1 step 5: [1.2742089], acc: [0.3984375]
2020-03-09 13:33:48,791-INFO: loss at epoch 1 step 10: [1.2646637], acc: [0.53125]
[2020-03-09 13:33:48,791.791] train.py [line:93] INFO: loss at epoch 1 step 10: [1.2646637], acc: [0.53125]
2020-03-09 13:33:55,507-INFO: loss at epoch 1 step 15: [1.3255358], acc: [0.4765625]
[2020-03-09 13:33:55,507.507] train.py [line:93] INFO: loss at epoch 1 step 15: [1.3255358], acc: [0.4765625]
2020-03-09 13:34:02,203-INFO: loss at epoch 1 step 20: [1.1859796], acc: [0.4765625]
[2020-03-09 13:34:02,203.203] train.py [line:93] INFO: loss at epoch 1 step 20: [1.1859796], acc: [0.4765625]
2020-03-09 13:34:04,257-INFO: epoch 1 acc: [0.4786932]
[2020-03-09 13:34:04,257.257] train.py [line:96] INFO: epoch 1 acc: [0.4786932]
2020-03-09 13:34:04,258-INFO: current epoch 1 acc: [0.4786932] better than last acc: [0.3643466], save model
[2020-03-09 13:34:04,258.258] train.py [line:99] INFO: current epoch 1 acc: [0.4786932] better than last acc: [0.3643466], save model
2020-03-09 13:34:12,327-INFO: loss at epoch 2 step 5: [1.1912868], acc: [0.5234375]
[2020-03-09 13:34:12,327.327] train.py [line:93] INFO: loss at epoch 2 step 5: [1.1912868], acc: [0.5234375]
2020-03-09 13:34:19,022-INFO: loss at epoch 2 step 10: [1.2731875], acc: [0.5]
[2020-03-09 13:34:19,022.022] train.py [line:93] INFO: loss at epoch 2 step 10: [1.2731875], acc: [0.5]
2020-03-09 13:34:25,925-INFO: loss at epoch 2 step 15: [1.27143], acc: [0.4921875]
[2020-03-09 13:34:25,925.925] train.py [line:93] INFO: loss at epoch 2 step 15: [1.27143], acc: [0.4921875]
2020-03-09 13:34:32,804-INFO: loss at epoch 2 step 20: [1.1583318], acc: [0.53125]
[2020-03-09 13:34:32,804.804] train.py [line:93] INFO: loss at epoch 2 step 20: [1.1583318], acc: [0.53125]
2020-03-09 13:34:34,829-INFO: epoch 2 acc: [0.52166194]
[2020-03-09 13:34:34,829.829] train.py [line:96] INFO: epoch 2 acc: [0.52166194]
2020-03-09 13:34:34,830-INFO: current epoch 2 acc: [0.52166194] better than last acc: [0.4786932], save model
[2020-03-09 13:34:34,830.830] train.py [line:99] INFO: current epoch 2 acc: [0.52166194] better than last acc: [0.4786932], save model
2020-03-09 13:34:43,101-INFO: loss at epoch 3 step 5: [1.2183974], acc: [0.53125]
[2020-03-09 13:34:43,101.101] train.py [line:93] INFO: loss at epoch 3 step 5: [1.2183974], acc: [0.53125]
2020-03-09 13:34:49,825-INFO: loss at epoch 3 step 10: [1.0820289], acc: [0.5234375]
[2020-03-09 13:34:49,825.825] train.py [line:93] INFO: loss at epoch 3 step 10: [1.0820289], acc: [0.5234375]
2020-03-09 13:34:56,419-INFO: loss at epoch 3 step 15: [1.0166322], acc: [0.5625]
[2020-03-09 13:34:56,419.419] train.py [line:93] INFO: loss at epoch 3 step 15: [1.0166322], acc: [0.5625]
2020-03-09 13:35:03,272-INFO: loss at epoch 3 step 20: [1.1699996], acc: [0.5]
[2020-03-09 13:35:03,272.272] train.py [line:93] INFO: loss at epoch 3 step 20: [1.1699996], acc: [0.5]
2020-03-09 13:35:05,229-INFO: epoch 3 acc: [0.54403406]
[2020-03-09 13:35:05,229.229] train.py [line:96] INFO: epoch 3 acc: [0.54403406]
2020-03-09 13:35:05,230-INFO: current epoch 3 acc: [0.54403406] better than last acc: [0.52166194], save model
[2020-03-09 13:35:05,230.230] train.py [line:99] INFO: current epoch 3 acc: [0.54403406] better than last acc: [0.52166194], save model
2020-03-09 13:35:13,675-INFO: loss at epoch 4 step 5: [1.0161449], acc: [0.609375]
[2020-03-09 13:35:13,675.675] train.py [line:93] INFO: loss at epoch 4 step 5: [1.0161449], acc: [0.609375]
2020-03-09 13:35:20,440-INFO: loss at epoch 4 step 10: [1.2599362], acc: [0.46875]
[2020-03-09 13:35:20,440.440] train.py [line:93] INFO: loss at epoch 4 step 10: [1.2599362], acc: [0.46875]
2020-03-09 13:35:27,089-INFO: loss at epoch 4 step 15: [0.97799814], acc: [0.6328125]
[2020-03-09 13:35:27,089.089] train.py [line:93] INFO: loss at epoch 4 step 15: [0.97799814], acc: [0.6328125]
2020-03-09 13:35:33,762-INFO: loss at epoch 4 step 20: [0.85721034], acc: [0.6796875]
[2020-03-09 13:35:33,762.762] train.py [line:93] INFO: loss at epoch 4 step 20: [0.85721034], acc: [0.6796875]
2020-03-09 13:35:35,799-INFO: epoch 4 acc: [0.58309656]
[2020-03-09 13:35:35,799.799] train.py [line:96] INFO: epoch 4 acc: [0.58309656]
2020-03-09 13:35:35,799-INFO: current epoch 4 acc: [0.58309656] better than last acc: [0.54403406], save model
[2020-03-09 13:35:35,799.799] train.py [line:99] INFO: current epoch 4 acc: [0.58309656] better than last acc: [0.54403406], save model
2020-03-09 13:35:44,066-INFO: loss at epoch 5 step 5: [0.9623274], acc: [0.625]
[2020-03-09 13:35:44,066.066] train.py [line:93] INFO: loss at epoch 5 step 5: [0.9623274], acc: [0.625]
2020-03-09 13:35:50,697-INFO: loss at epoch 5 step 10: [1.0486143], acc: [0.609375]
[2020-03-09 13:35:50,697.697] train.py [line:93] INFO: loss at epoch 5 step 10: [1.0486143], acc: [0.609375]
2020-03-09 13:35:57,737-INFO: loss at epoch 5 step 15: [0.9463243], acc: [0.625]
[2020-03-09 13:35:57,737.737] train.py [line:93] INFO: loss at epoch 5 step 15: [0.9463243], acc: [0.625]
2020-03-09 13:36:04,793-INFO: loss at epoch 5 step 20: [0.9887617], acc: [0.6484375]
[2020-03-09 13:36:04,793.793] train.py [line:93] INFO: loss at epoch 5 step 20: [0.9887617], acc: [0.6484375]
2020-03-09 13:36:06,725-INFO: epoch 5 acc: [0.5894886]
[2020-03-09 13:36:06,725.725] train.py [line:96] INFO: epoch 5 acc: [0.5894886]
2020-03-09 13:36:06,725-INFO: current epoch 5 acc: [0.5894886] better than last acc: [0.58309656], save model
[2020-03-09 13:36:06,725.725] train.py [line:99] INFO: current epoch 5 acc: [0.5894886] better than last acc: [0.58309656], save model
2020-03-09 13:36:14,745-INFO: loss at epoch 6 step 5: [1.0089675], acc: [0.5703125]
[2020-03-09 13:36:14,745.745] train.py [line:93] INFO: loss at epoch 6 step 5: [1.0089675], acc: [0.5703125]
2020-03-09 13:36:21,496-INFO: loss at epoch 6 step 10: [0.8850716], acc: [0.671875]
[2020-03-09 13:36:21,496.496] train.py [line:93] INFO: loss at epoch 6 step 10: [0.8850716], acc: [0.671875]
2020-03-09 13:36:28,043-INFO: loss at epoch 6 step 15: [1.0524786], acc: [0.5859375]
[2020-03-09 13:36:28,043.043] train.py [line:93] INFO: loss at epoch 6 step 15: [1.0524786], acc: [0.5859375]
2020-03-09 13:36:34,810-INFO: loss at epoch 6 step 20: [0.93651426], acc: [0.640625]
[2020-03-09 13:36:34,810.810] train.py [line:93] INFO: loss at epoch 6 step 20: [0.93651426], acc: [0.640625]
2020-03-09 13:36:36,774-INFO: epoch 6 acc: [0.6068892]
[2020-03-09 13:36:36,774.774] train.py [line:96] INFO: epoch 6 acc: [0.6068892]
2020-03-09 13:36:36,775-INFO: current epoch 6 acc: [0.6068892] better than last acc: [0.5894886], save model
[2020-03-09 13:36:36,775.775] train.py [line:99] INFO: current epoch 6 acc: [0.6068892] better than last acc: [0.5894886], save model
2020-03-09 13:36:44,843-INFO: loss at epoch 7 step 5: [1.0634739], acc: [0.5703125]
[2020-03-09 13:36:44,843.843] train.py [line:93] INFO: loss at epoch 7 step 5: [1.0634739], acc: [0.5703125]
2020-03-09 13:36:51,652-INFO: loss at epoch 7 step 10: [1.0115774], acc: [0.6171875]
[2020-03-09 13:36:51,652.652] train.py [line:93] INFO: loss at epoch 7 step 10: [1.0115774], acc: [0.6171875]
2020-03-09 13:36:58,487-INFO: loss at epoch 7 step 15: [0.9448753], acc: [0.5859375]
[2020-03-09 13:36:58,487.487] train.py [line:93] INFO: loss at epoch 7 step 15: [0.9448753], acc: [0.5859375]
2020-03-09 13:37:05,067-INFO: loss at epoch 7 step 20: [0.99608904], acc: [0.6796875]
[2020-03-09 13:37:05,067.067] train.py [line:93] INFO: loss at epoch 7 step 20: [0.99608904], acc: [0.6796875]
2020-03-09 13:37:07,071-INFO: epoch 7 acc: [0.60866475]
[2020-03-09 13:37:07,071.071] train.py [line:96] INFO: epoch 7 acc: [0.60866475]
2020-03-09 13:37:07,071-INFO: current epoch 7 acc: [0.60866475] better than last acc: [0.6068892], save model
[2020-03-09 13:37:07,071.071] train.py [line:99] INFO: current epoch 7 acc: [0.60866475] better than last acc: [0.6068892], save model
2020-03-09 13:37:15,141-INFO: loss at epoch 8 step 5: [0.97817945], acc: [0.59375]
[2020-03-09 13:37:15,141.141] train.py [line:93] INFO: loss at epoch 8 step 5: [0.97817945], acc: [0.59375]
2020-03-09 13:37:21,896-INFO: loss at epoch 8 step 10: [0.8277987], acc: [0.6640625]
[2020-03-09 13:37:21,896.896] train.py [line:93] INFO: loss at epoch 8 step 10: [0.8277987], acc: [0.6640625]
2020-03-09 13:37:28,627-INFO: loss at epoch 8 step 15: [0.89281774], acc: [0.6953125]
[2020-03-09 13:37:28,627.627] train.py [line:93] INFO: loss at epoch 8 step 15: [0.89281774], acc: [0.6953125]
2020-03-09 13:37:35,492-INFO: loss at epoch 8 step 20: [0.94381404], acc: [0.609375]
[2020-03-09 13:37:35,492.492] train.py [line:93] INFO: loss at epoch 8 step 20: [0.94381404], acc: [0.609375]
2020-03-09 13:37:37,504-INFO: epoch 8 acc: [0.6292614]
[2020-03-09 13:37:37,504.504] train.py [line:96] INFO: epoch 8 acc: [0.6292614]
2020-03-09 13:37:37,505-INFO: current epoch 8 acc: [0.6292614] better than last acc: [0.60866475], save model
[2020-03-09 13:37:37,505.505] train.py [line:99] INFO: current epoch 8 acc: [0.6292614] better than last acc: [0.60866475], save model
2020-03-09 13:37:45,753-INFO: loss at epoch 9 step 5: [0.99051356], acc: [0.5625]
[2020-03-09 13:37:45,753.753] train.py [line:93] INFO: loss at epoch 9 step 5: [0.99051356], acc: [0.5625]
2020-03-09 13:37:52,413-INFO: loss at epoch 9 step 10: [0.9042212], acc: [0.6328125]
[2020-03-09 13:37:52,413.413] train.py [line:93] INFO: loss at epoch 9 step 10: [0.9042212], acc: [0.6328125]
2020-03-09 13:37:59,324-INFO: loss at epoch 9 step 15: [0.8842303], acc: [0.625]
[2020-03-09 13:37:59,324.324] train.py [line:93] INFO: loss at epoch 9 step 15: [0.8842303], acc: [0.625]
2020-03-09 13:38:06,279-INFO: loss at epoch 9 step 20: [1.0185038], acc: [0.609375]
[2020-03-09 13:38:06,279.279] train.py [line:93] INFO: loss at epoch 9 step 20: [1.0185038], acc: [0.609375]
2020-03-09 13:38:08,368-INFO: epoch 9 acc: [0.63352275]
[2020-03-09 13:38:08,368.368] train.py [line:96] INFO: epoch 9 acc: [0.63352275]
2020-03-09 13:38:08,369-INFO: current epoch 9 acc: [0.63352275] better than last acc: [0.6292614], save model
[2020-03-09 13:38:08,369.369] train.py [line:99] INFO: current epoch 9 acc: [0.63352275] better than last acc: [0.6292614], save model
2020-03-09 13:38:16,405-INFO: loss at epoch 10 step 5: [1.0421901], acc: [0.609375]
[2020-03-09 13:38:16,405.405] train.py [line:93] INFO: loss at epoch 10 step 5: [1.0421901], acc: [0.609375]
2020-03-09 13:38:23,234-INFO: loss at epoch 10 step 10: [0.7311858], acc: [0.7109375]
[2020-03-09 13:38:23,234.234] train.py [line:93] INFO: loss at epoch 10 step 10: [0.7311858], acc: [0.7109375]
2020-03-09 13:38:29,982-INFO: loss at epoch 10 step 15: [0.8692049], acc: [0.671875]
[2020-03-09 13:38:29,982.982] train.py [line:93] INFO: loss at epoch 10 step 15: [0.8692049], acc: [0.671875]
2020-03-09 13:38:37,200-INFO: loss at epoch 10 step 20: [0.9256623], acc: [0.640625]
[2020-03-09 13:38:37,200.200] train.py [line:93] INFO: loss at epoch 10 step 20: [0.9256623], acc: [0.640625]
2020-03-09 13:38:39,216-INFO: epoch 10 acc: [0.65553975]
[2020-03-09 13:38:39,216.216] train.py [line:96] INFO: epoch 10 acc: [0.65553975]
2020-03-09 13:38:39,217-INFO: current epoch 10 acc: [0.65553975] better than last acc: [0.63352275], save model
[2020-03-09 13:38:39,217.217] train.py [line:99] INFO: current epoch 10 acc: [0.65553975] better than last acc: [0.63352275], save model
2020-03-09 13:38:47,372-INFO: loss at epoch 11 step 5: [0.7734097], acc: [0.6796875]
[2020-03-09 13:38:47,372.372] train.py [line:93] INFO: loss at epoch 11 step 5: [0.7734097], acc: [0.6796875]
2020-03-09 13:38:54,053-INFO: loss at epoch 11 step 10: [0.9217919], acc: [0.7265625]
[2020-03-09 13:38:54,053.053] train.py [line:93] INFO: loss at epoch 11 step 10: [0.9217919], acc: [0.7265625]
2020-03-09 13:39:00,869-INFO: loss at epoch 11 step 15: [0.8378419], acc: [0.71875]
[2020-03-09 13:39:00,869.869] train.py [line:93] INFO: loss at epoch 11 step 15: [0.8378419], acc: [0.71875]
2020-03-09 13:39:07,769-INFO: loss at epoch 11 step 20: [0.88202447], acc: [0.671875]
[2020-03-09 13:39:07,769.769] train.py [line:93] INFO: loss at epoch 11 step 20: [0.88202447], acc: [0.671875]
2020-03-09 13:39:09,800-INFO: epoch 11 acc: [0.6697443]
[2020-03-09 13:39:09,800.800] train.py [line:96] INFO: epoch 11 acc: [0.6697443]
2020-03-09 13:39:09,801-INFO: current epoch 11 acc: [0.6697443] better than last acc: [0.65553975], save model
[2020-03-09 13:39:09,801.801] train.py [line:99] INFO: current epoch 11 acc: [0.6697443] better than last acc: [0.65553975], save model
2020-03-09 13:39:17,956-INFO: loss at epoch 12 step 5: [0.8373075], acc: [0.6796875]
[2020-03-09 13:39:17,956.956] train.py [line:93] INFO: loss at epoch 12 step 5: [0.8373075], acc: [0.6796875]
2020-03-09 13:39:25,045-INFO: loss at epoch 12 step 10: [1.0463818], acc: [0.578125]
[2020-03-09 13:39:25,045.045] train.py [line:93] INFO: loss at epoch 12 step 10: [1.0463818], acc: [0.578125]
2020-03-09 13:39:31,759-INFO: loss at epoch 12 step 15: [0.90400654], acc: [0.6484375]
[2020-03-09 13:39:31,759.759] train.py [line:93] INFO: loss at epoch 12 step 15: [0.90400654], acc: [0.6484375]
2020-03-09 13:39:38,526-INFO: loss at epoch 12 step 20: [0.81026363], acc: [0.6796875]
[2020-03-09 13:39:38,526.526] train.py [line:93] INFO: loss at epoch 12 step 20: [0.81026363], acc: [0.6796875]
2020-03-09 13:39:40,608-INFO: epoch 12 acc: [0.675071]
[2020-03-09 13:39:40,608.608] train.py [line:96] INFO: epoch 12 acc: [0.675071]
2020-03-09 13:39:40,608-INFO: current epoch 12 acc: [0.675071] better than last acc: [0.6697443], save model
[2020-03-09 13:39:40,608.608] train.py [line:99] INFO: current epoch 12 acc: [0.675071] better than last acc: [0.6697443], save model
2020-03-09 13:39:49,100-INFO: loss at epoch 13 step 5: [0.8827349], acc: [0.6171875]
[2020-03-09 13:39:49,100.100] train.py [line:93] INFO: loss at epoch 13 step 5: [0.8827349], acc: [0.6171875]
2020-03-09 13:39:55,869-INFO: loss at epoch 13 step 10: [0.79526913], acc: [0.71875]
[2020-03-09 13:39:55,869.869] train.py [line:93] INFO: loss at epoch 13 step 10: [0.79526913], acc: [0.71875]
2020-03-09 13:40:02,662-INFO: loss at epoch 13 step 15: [0.8414843], acc: [0.6796875]
[2020-03-09 13:40:02,662.662] train.py [line:93] INFO: loss at epoch 13 step 15: [0.8414843], acc: [0.6796875]
2020-03-09 13:40:09,138-INFO: loss at epoch 13 step 20: [0.78467536], acc: [0.7109375]
[2020-03-09 13:40:09,138.138] train.py [line:93] INFO: loss at epoch 13 step 20: [0.78467536], acc: [0.7109375]
2020-03-09 13:40:11,148-INFO: epoch 13 acc: [0.690696]
[2020-03-09 13:40:11,148.148] train.py [line:96] INFO: epoch 13 acc: [0.690696]
2020-03-09 13:40:11,149-INFO: current epoch 13 acc: [0.690696] better than last acc: [0.675071], save model
[2020-03-09 13:40:11,149.149] train.py [line:99] INFO: current epoch 13 acc: [0.690696] better than last acc: [0.675071], save model
2020-03-09 13:40:19,230-INFO: loss at epoch 14 step 5: [0.7627206], acc: [0.7421875]
[2020-03-09 13:40:19,230.230] train.py [line:93] INFO: loss at epoch 14 step 5: [0.7627206], acc: [0.7421875]
2020-03-09 13:40:26,448-INFO: loss at epoch 14 step 10: [0.7642057], acc: [0.71875]
[2020-03-09 13:40:26,448.448] train.py [line:93] INFO: loss at epoch 14 step 10: [0.7642057], acc: [0.71875]
2020-03-09 13:40:33,340-INFO: loss at epoch 14 step 15: [0.63255274], acc: [0.7109375]
[2020-03-09 13:40:33,340.340] train.py [line:93] INFO: loss at epoch 14 step 15: [0.63255274], acc: [0.7109375]
2020-03-09 13:40:39,813-INFO: loss at epoch 14 step 20: [0.72512174], acc: [0.71875]
[2020-03-09 13:40:39,813.813] train.py [line:93] INFO: loss at epoch 14 step 20: [0.72512174], acc: [0.71875]
2020-03-09 13:40:41,782-INFO: epoch 14 acc: [0.6910511]
[2020-03-09 13:40:41,782.782] train.py [line:96] INFO: epoch 14 acc: [0.6910511]
2020-03-09 13:40:41,783-INFO: current epoch 14 acc: [0.6910511] better than last acc: [0.690696], save model
[2020-03-09 13:40:41,783.783] train.py [line:99] INFO: current epoch 14 acc: [0.6910511] better than last acc: [0.690696], save model
2020-03-09 13:40:49,986-INFO: loss at epoch 15 step 5: [0.7011621], acc: [0.734375]
[2020-03-09 13:40:49,986.986] train.py [line:93] INFO: loss at epoch 15 step 5: [0.7011621], acc: [0.734375]
2020-03-09 13:40:56,803-INFO: loss at epoch 15 step 10: [0.71920556], acc: [0.6640625]
[2020-03-09 13:40:56,803.803] train.py [line:93] INFO: loss at epoch 15 step 10: [0.71920556], acc: [0.6640625]
2020-03-09 13:41:03,856-INFO: loss at epoch 15 step 15: [0.84328777], acc: [0.71875]
[2020-03-09 13:41:03,856.856] train.py [line:93] INFO: loss at epoch 15 step 15: [0.84328777], acc: [0.71875]
2020-03-09 13:41:10,680-INFO: loss at epoch 15 step 20: [0.84927607], acc: [0.65625]
[2020-03-09 13:41:10,680.680] train.py [line:93] INFO: loss at epoch 15 step 20: [0.84927607], acc: [0.65625]
2020-03-09 13:41:12,689-INFO: epoch 15 acc: [0.6953125]
[2020-03-09 13:41:12,689.689] train.py [line:96] INFO: epoch 15 acc: [0.6953125]
2020-03-09 13:41:12,690-INFO: current epoch 15 acc: [0.6953125] better than last acc: [0.6910511], save model
[2020-03-09 13:41:12,690.690] train.py [line:99] INFO: current epoch 15 acc: [0.6953125] better than last acc: [0.6910511], save model
2020-03-09 13:41:20,912-INFO: loss at epoch 16 step 5: [0.71949565], acc: [0.703125]
[2020-03-09 13:41:20,912.912] train.py [line:93] INFO: loss at epoch 16 step 5: [0.71949565], acc: [0.703125]
2020-03-09 13:41:27,381-INFO: loss at epoch 16 step 10: [0.7439419], acc: [0.6953125]
[2020-03-09 13:41:27,381.381] train.py [line:93] INFO: loss at epoch 16 step 10: [0.7439419], acc: [0.6953125]
2020-03-09 13:41:34,190-INFO: loss at epoch 16 step 15: [0.91501576], acc: [0.6328125]
[2020-03-09 13:41:34,190.190] train.py [line:93] INFO: loss at epoch 16 step 15: [0.91501576], acc: [0.6328125]
2020-03-09 13:41:41,291-INFO: loss at epoch 16 step 20: [0.6131062], acc: [0.7734375]
[2020-03-09 13:41:41,291.291] train.py [line:93] INFO: loss at epoch 16 step 20: [0.6131062], acc: [0.7734375]
2020-03-09 13:41:43,181-INFO: epoch 16 acc: [0.70170456]
[2020-03-09 13:41:43,181.181] train.py [line:96] INFO: epoch 16 acc: [0.70170456]
2020-03-09 13:41:43,181-INFO: current epoch 16 acc: [0.70170456] better than last acc: [0.6953125], save model
[2020-03-09 13:41:43,181.181] train.py [line:99] INFO: current epoch 16 acc: [0.70170456] better than last acc: [0.6953125], save model
2020-03-09 13:41:51,068-INFO: loss at epoch 17 step 5: [0.57439685], acc: [0.78125]
[2020-03-09 13:41:51,068.068] train.py [line:93] INFO: loss at epoch 17 step 5: [0.57439685], acc: [0.78125]
2020-03-09 13:41:57,816-INFO: loss at epoch 17 step 10: [0.79444146], acc: [0.6875]
[2020-03-09 13:41:57,816.816] train.py [line:93] INFO: loss at epoch 17 step 10: [0.79444146], acc: [0.6875]
2020-03-09 13:42:04,738-INFO: loss at epoch 17 step 15: [0.71589935], acc: [0.7421875]
[2020-03-09 13:42:04,738.738] train.py [line:93] INFO: loss at epoch 17 step 15: [0.71589935], acc: [0.7421875]
2020-03-09 13:42:11,533-INFO: loss at epoch 17 step 20: [0.7336781], acc: [0.703125]
[2020-03-09 13:42:11,533.533] train.py [line:93] INFO: loss at epoch 17 step 20: [0.7336781], acc: [0.703125]
2020-03-09 13:42:13,660-INFO: epoch 17 acc: [0.72052556]
[2020-03-09 13:42:13,660.660] train.py [line:96] INFO: epoch 17 acc: [0.72052556]
2020-03-09 13:42:13,660-INFO: current epoch 17 acc: [0.72052556] better than last acc: [0.70170456], save model
[2020-03-09 13:42:13,660.660] train.py [line:99] INFO: current epoch 17 acc: [0.72052556] better than last acc: [0.70170456], save model
2020-03-09 13:42:22,121-INFO: loss at epoch 18 step 5: [0.76754904], acc: [0.71875]
[2020-03-09 13:42:22,121.121] train.py [line:93] INFO: loss at epoch 18 step 5: [0.76754904], acc: [0.71875]
2020-03-09 13:42:29,107-INFO: loss at epoch 18 step 10: [0.64395803], acc: [0.7734375]
[2020-03-09 13:42:29,107.107] train.py [line:93] INFO: loss at epoch 18 step 10: [0.64395803], acc: [0.7734375]
2020-03-09 13:42:35,640-INFO: loss at epoch 18 step 15: [0.73454803], acc: [0.71875]
[2020-03-09 13:42:35,640.640] train.py [line:93] INFO: loss at epoch 18 step 15: [0.73454803], acc: [0.71875]
2020-03-09 13:42:42,338-INFO: loss at epoch 18 step 20: [0.6830851], acc: [0.7578125]
[2020-03-09 13:42:42,338.338] train.py [line:93] INFO: loss at epoch 18 step 20: [0.6830851], acc: [0.7578125]
2020-03-09 13:42:44,330-INFO: epoch 18 acc: [0.72940344]
[2020-03-09 13:42:44,330.330] train.py [line:96] INFO: epoch 18 acc: [0.72940344]
2020-03-09 13:42:44,331-INFO: current epoch 18 acc: [0.72940344] better than last acc: [0.72052556], save model
[2020-03-09 13:42:44,331.331] train.py [line:99] INFO: current epoch 18 acc: [0.72940344] better than last acc: [0.72052556], save model
2020-03-09 13:42:52,470-INFO: loss at epoch 19 step 5: [0.54573315], acc: [0.78125]
[2020-03-09 13:42:52,470.470] train.py [line:93] INFO: loss at epoch 19 step 5: [0.54573315], acc: [0.78125]
2020-03-09 13:42:59,328-INFO: loss at epoch 19 step 10: [0.75273883], acc: [0.75]
[2020-03-09 13:42:59,328.328] train.py [line:93] INFO: loss at epoch 19 step 10: [0.75273883], acc: [0.75]
2020-03-09 13:43:05,949-INFO: loss at epoch 19 step 15: [0.5357485], acc: [0.765625]
[2020-03-09 13:43:05,949.949] train.py [line:93] INFO: loss at epoch 19 step 15: [0.5357485], acc: [0.765625]
2020-03-09 13:43:12,692-INFO: loss at epoch 19 step 20: [0.7270824], acc: [0.7421875]
[2020-03-09 13:43:12,692.692] train.py [line:93] INFO: loss at epoch 19 step 20: [0.7270824], acc: [0.7421875]
2020-03-09 13:43:14,723-INFO: epoch 19 acc: [0.7457386]
[2020-03-09 13:43:14,723.723] train.py [line:96] INFO: epoch 19 acc: [0.7457386]
2020-03-09 13:43:14,723-INFO: current epoch 19 acc: [0.7457386] better than last acc: [0.72940344], save model
[2020-03-09 13:43:14,723.723] train.py [line:99] INFO: current epoch 19 acc: [0.7457386] better than last acc: [0.72940344], save model
2020-03-09 13:43:14,776-INFO: train till end
[2020-03-09 13:43:14,776.776] train.py [line:102] INFO: train till end

 

加载训练保存的模型,验证效果

In[4]

!python work/eval.py
[2020-03-09 13:43:49,590.590] config.py [line:77] INFO: input_size: [3, 224, 224]
[2020-03-09 13:43:49,590.590] config.py [line:78] INFO: class_dim: 5
[2020-03-09 13:43:49,590.590] config.py [line:79] INFO: continue_train: True
[2020-03-09 13:43:49,590.590] config.py [line:80] INFO: train_image_count: 2893
[2020-03-09 13:43:49,590.590] config.py [line:81] INFO: eval_image_count: 777
[2020-03-09 13:43:49,590.590] config.py [line:82] INFO: num_epochs: 20
[2020-03-09 13:43:49,590.590] config.py [line:83] INFO: train_batch_size: 128
[2020-03-09 13:43:49,590.590] config.py [line:84] INFO: mean_rgb: [127.5, 127.5, 127.5]
[2020-03-09 13:43:49,590.590] config.py [line:85] INFO: save_model_dir: ./model-params/params
[2020-03-09 13:43:49,591.591] eval.py [line:17] INFO: start eval
W0309 13:43:50.399327   162 device_context.cc:237] Please NOTE: device: 0, CUDA Capability: 70, Driver API Version: 10.1, Runtime API Version: 9.0
W0309 13:43:50.402669   162 device_context.cc:245] device: 0, cuDNN Version: 7.3.
[2020-03-09 13:44:09,705.705] eval.py [line:51] INFO: test count: 777 , acc: 0.6821106672286987 cost time: 17.740089654922485

 点击链接,使用AI Studio一键上手实践项目吧:https://aistudio.baidu.com/aistudio/projectdetail/169424

下载安装命令

## CPU版本安装命令
pip install -f https://paddlepaddle.org.cn/pip/oschina/cpu paddlepaddle

## GPU版本安装命令
pip install -f https://paddlepaddle.org.cn/pip/oschina/gpu paddlepaddle-gpu

>> 访问 PaddlePaddle 官网,了解更多相关内容

{{o.name}}


{{m.name}}

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/72695.html

(0)
上一篇 2021年8月11日 22:20
下一篇 2021年8月11日 22:20

相关推荐

发表回复

登录后才能评论