用PaddlePaddle实现图像分类DPN算法(动态图版)

原创
2020/04/21 14:37
阅读数 1.2K

项目简介

本项目使用paddle的动态图机制实现了经典的图像分类网络:Dual Path Networks,并在公开的蔬菜数据集上进行了模型训练以及验证。静态图版本请查看:用PaddlePaddle实现图像分类-DPN算法

下载安装命令

## 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

模型简介

ResNet网络可以看作是对之前层级中已提取特征的复用,DenseNet网络能从靠前的层级中提取到新的特征,这两种结构都是比较热门的网络结构。DPN则是将两种网络结构的思想融合起来,具体的网络结构如下表。 
从上表可以看出DPN网络的结构其实和ResNeXt网络的结构很相似。最开始是一个7×77\times 77×7的卷积层和max pooling层,然后是4个stage,每个stage包含N个sub-stage,最后是一个global average pooling和全链接层。所以DPN的核心就在于stage中的结构。具体stage中是如何结合ResNet和DenseNet可以参考下图。

上图(a)中为ResNet网络中的一个子结构,左边矩形框代表输入输出内容,对于输入X,右边分支代表X经过1×11\times 11×1卷积、3×33\times 33×3卷积、1×11\times 11×1卷积后的输出X′X^{'}X,然后再将X与X′X^{'}X对应元素相加,得到下一个模块的输入。图(b)为DenseNet网络中的子结构,DenseNet中右边支路的输出会和X进行通道合并而不是相加,这样每个小模块的输入都在不断的累加。图中的(d)和(e)是DPN的两种不同表达,但是本质是一个意思,对于输入X,如果X是整个网络第一层卷积的输入,或某个stage的输入,那么会对X进行卷积,然后将输出按照channel划分为两个部分X_o1和X_o2,这两个部分分别进行resnet和densenet的操作,最后把这两个部分的输出拼接起来。
论文原文:Dual Path Networks 参考链接:DPN(Dual Path Network)算法详解

数据简介

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

In[1]
#代码结构
#├── config.py   # 参数脚本
#├── train.py   # 定义通用工具方法。
#├── DPN.py     # DPN网络结构.
#├── eval.py     # 模型评估脚本
#├── reader.py     # 数据读取.
#├── logs     # 日志文件夹
In[2]
#解压数据集
!cd data/data2815 && unzip -q flower_photos.zip
In[3]
#数据预处理
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[4]
#模型训练
!python train.py
2020-03-09 15:25:47,594-INFO: input_size: [3, 224, 224]
[2020-03-09 15:25:47,594.594] config.py [line:85] INFO: input_size: [3, 224, 224]
2020-03-09 15:25:47,594-INFO: class_dim: 5
[2020-03-09 15:25:47,594.594] config.py [line:86] INFO: class_dim: 5
2020-03-09 15:25:47,594-INFO: continue_train: True
[2020-03-09 15:25:47,594.594] config.py [line:87] INFO: continue_train: True
2020-03-09 15:25:47,594-INFO: train_image_count: 2982
[2020-03-09 15:25:47,594.594] config.py [line:88] INFO: train_image_count: 2982
2020-03-09 15:25:47,594-INFO: eval_image_count: 688
[2020-03-09 15:25:47,594.594] config.py [line:89] INFO: eval_image_count: 688
2020-03-09 15:25:47,594-INFO: num_epochs: 10
[2020-03-09 15:25:47,594.594] config.py [line:90] INFO: num_epochs: 10
2020-03-09 15:25:47,594-INFO: train_batch_size: 64
[2020-03-09 15:25:47,594.594] config.py [line:91] INFO: train_batch_size: 64
2020-03-09 15:25:47,594-INFO: mean_rgb: [127.5, 127.5, 127.5]
[2020-03-09 15:25:47,594.594] config.py [line:92] INFO: mean_rgb: [127.5, 127.5, 127.5]
2020-03-09 15:25:47,594-INFO: save_model_dir: ./save_model/net
[2020-03-09 15:25:47,594.594] config.py [line:93] INFO: save_model_dir: ./save_model/net
2020-03-09 15:25:47,597-INFO: start train
[2020-03-09 15:25:47,597.597] train.py [line:60] INFO: start train
W0309 15:25:48.339375    93 device_context.cc:237] Please NOTE: device: 0, CUDA Capability: 70, Driver API Version: 9.2, Runtime API Version: 9.0
W0309 15:25:48.342763    93 device_context.cc:245] device: 0, cuDNN Version: 7.3.
2020-03-09 15:25:49,789-INFO: use Adam optimizer
[2020-03-09 15:25:49,789.789] train.py [line:32] INFO: use Adam optimizer
2020-03-09 15:25:49,789-INFO: load params from ./save_model/net
[2020-03-09 15:25:49,789.789] train.py [line:44] INFO: load params from ./save_model/net
2020-03-09 15:25:54,897-INFO: loss at epoch 0 step 5: [1.6091776], acc: [0.296875]
[2020-03-09 15:25:54,897.897] train.py [line:99] INFO: loss at epoch 0 step 5: [1.6091776], acc: [0.296875]
2020-03-09 15:25:59,143-INFO: loss at epoch 0 step 10: [1.6122777], acc: [0.15625]
[2020-03-09 15:25:59,143.143] train.py [line:99] INFO: loss at epoch 0 step 10: [1.6122777], acc: [0.15625]
2020-03-09 15:26:03,105-INFO: loss at epoch 0 step 15: [1.5948787], acc: [0.3125]
[2020-03-09 15:26:03,105.105] train.py [line:99] INFO: loss at epoch 0 step 15: [1.5948787], acc: [0.3125]
2020-03-09 15:26:07,210-INFO: loss at epoch 0 step 20: [1.5997486], acc: [0.359375]
[2020-03-09 15:26:07,210.210] train.py [line:99] INFO: loss at epoch 0 step 20: [1.5997486], acc: [0.359375]
2020-03-09 15:26:11,481-INFO: loss at epoch 0 step 25: [1.6041915], acc: [0.328125]
[2020-03-09 15:26:11,481.481] train.py [line:99] INFO: loss at epoch 0 step 25: [1.6041915], acc: [0.328125]
2020-03-09 15:26:15,769-INFO: loss at epoch 0 step 30: [1.6060413], acc: [0.234375]
[2020-03-09 15:26:15,769.769] train.py [line:99] INFO: loss at epoch 0 step 30: [1.6060413], acc: [0.234375]
2020-03-09 15:26:20,145-INFO: loss at epoch 0 step 35: [1.6031518], acc: [0.265625]
[2020-03-09 15:26:20,145.145] train.py [line:99] INFO: loss at epoch 0 step 35: [1.6031518], acc: [0.265625]
2020-03-09 15:26:24,217-INFO: loss at epoch 0 step 40: [1.5935323], acc: [0.375]
[2020-03-09 15:26:24,217.217] train.py [line:99] INFO: loss at epoch 0 step 40: [1.5935323], acc: [0.375]
2020-03-09 15:26:28,345-INFO: loss at epoch 0 step 45: [1.5882888], acc: [0.453125]
[2020-03-09 15:26:28,345.345] train.py [line:99] INFO: loss at epoch 0 step 45: [1.5882888], acc: [0.453125]
2020-03-09 15:26:28,633-INFO: epoch 0 acc: [0.3006114]
[2020-03-09 15:26:28,633.633] train.py [line:102] INFO: epoch 0 acc: [0.3006114]
2020-03-09 15:26:28,634-INFO: current epoch 0 acc: [0.3006114] better than last acc: 0.0, save model
[2020-03-09 15:26:28,634.634] train.py [line:105] INFO: current epoch 0 acc: [0.3006114] better than last acc: 0.0, save model
2020-03-09 15:26:33,750-INFO: loss at epoch 1 step 5: [1.6067531], acc: [0.265625]
[2020-03-09 15:26:33,750.750] train.py [line:99] INFO: loss at epoch 1 step 5: [1.6067531], acc: [0.265625]
2020-03-09 15:26:37,980-INFO: loss at epoch 1 step 10: [1.598098], acc: [0.375]
[2020-03-09 15:26:37,980.980] train.py [line:99] INFO: loss at epoch 1 step 10: [1.598098], acc: [0.375]
2020-03-09 15:26:42,184-INFO: loss at epoch 1 step 15: [1.6024013], acc: [0.3125]
[2020-03-09 15:26:42,184.184] train.py [line:99] INFO: loss at epoch 1 step 15: [1.6024013], acc: [0.3125]
2020-03-09 15:26:46,313-INFO: loss at epoch 1 step 20: [1.5985036], acc: [0.359375]
[2020-03-09 15:26:46,313.313] train.py [line:99] INFO: loss at epoch 1 step 20: [1.5985036], acc: [0.359375]
2020-03-09 15:26:50,425-INFO: loss at epoch 1 step 25: [1.6213667], acc: [0.1875]
[2020-03-09 15:26:50,425.425] train.py [line:99] INFO: loss at epoch 1 step 25: [1.6213667], acc: [0.1875]
2020-03-09 15:26:54,754-INFO: loss at epoch 1 step 30: [1.5978827], acc: [0.265625]
[2020-03-09 15:26:54,754.754] train.py [line:99] INFO: loss at epoch 1 step 30: [1.5978827], acc: [0.265625]
2020-03-09 15:26:58,842-INFO: loss at epoch 1 step 35: [1.5901895], acc: [0.375]
[2020-03-09 15:26:58,842.842] train.py [line:99] INFO: loss at epoch 1 step 35: [1.5901895], acc: [0.375]
2020-03-09 15:27:02,884-INFO: loss at epoch 1 step 40: [1.5972428], acc: [0.296875]
[2020-03-09 15:27:02,884.884] train.py [line:99] INFO: loss at epoch 1 step 40: [1.5972428], acc: [0.296875]
2020-03-09 15:27:07,002-INFO: loss at epoch 1 step 45: [1.6010656], acc: [0.3125]
[2020-03-09 15:27:07,002.002] train.py [line:99] INFO: loss at epoch 1 step 45: [1.6010656], acc: [0.3125]
2020-03-09 15:27:07,353-INFO: epoch 1 acc: [0.30672553]
[2020-03-09 15:27:07,353.353] train.py [line:102] INFO: epoch 1 acc: [0.30672553]
2020-03-09 15:27:07,353-INFO: current epoch 1 acc: [0.30672553] better than last acc: [0.3006114], save model
[2020-03-09 15:27:07,353.353] train.py [line:105] INFO: current epoch 1 acc: [0.30672553] better than last acc: [0.3006114], save model
2020-03-09 15:27:12,391-INFO: loss at epoch 2 step 5: [1.5902538], acc: [0.359375]
[2020-03-09 15:27:12,391.391] train.py [line:99] INFO: loss at epoch 2 step 5: [1.5902538], acc: [0.359375]
2020-03-09 15:27:16,574-INFO: loss at epoch 2 step 10: [1.5914931], acc: [0.421875]
[2020-03-09 15:27:16,574.574] train.py [line:99] INFO: loss at epoch 2 step 10: [1.5914931], acc: [0.421875]
2020-03-09 15:27:20,709-INFO: loss at epoch 2 step 15: [1.6113138], acc: [0.21875]
[2020-03-09 15:27:20,709.709] train.py [line:99] INFO: loss at epoch 2 step 15: [1.6113138], acc: [0.21875]
2020-03-09 15:27:24,924-INFO: loss at epoch 2 step 20: [1.5867205], acc: [0.390625]
[2020-03-09 15:27:24,924.924] train.py [line:99] INFO: loss at epoch 2 step 20: [1.5867205], acc: [0.390625]
2020-03-09 15:27:29,147-INFO: loss at epoch 2 step 25: [1.5995429], acc: [0.34375]
[2020-03-09 15:27:29,147.147] train.py [line:99] INFO: loss at epoch 2 step 25: [1.5995429], acc: [0.34375]
2020-03-09 15:27:33,152-INFO: loss at epoch 2 step 30: [1.6005954], acc: [0.25]
[2020-03-09 15:27:33,152.152] train.py [line:99] INFO: loss at epoch 2 step 30: [1.6005954], acc: [0.25]
2020-03-09 15:27:37,169-INFO: loss at epoch 2 step 35: [1.5899], acc: [0.328125]
[2020-03-09 15:27:37,169.169] train.py [line:99] INFO: loss at epoch 2 step 35: [1.5899], acc: [0.328125]
2020-03-09 15:27:41,277-INFO: loss at epoch 2 step 40: [1.598083], acc: [0.3125]
[2020-03-09 15:27:41,277.277] train.py [line:99] INFO: loss at epoch 2 step 40: [1.598083], acc: [0.3125]
2020-03-09 15:27:45,520-INFO: loss at epoch 2 step 45: [1.5854399], acc: [0.390625]
[2020-03-09 15:27:45,520.520] train.py [line:99] INFO: loss at epoch 2 step 45: [1.5854399], acc: [0.390625]
2020-03-09 15:27:45,804-INFO: epoch 2 acc: [0.3074049]
[2020-03-09 15:27:45,804.804] train.py [line:102] INFO: epoch 2 acc: [0.3074049]
2020-03-09 15:27:45,805-INFO: current epoch 2 acc: [0.3074049] better than last acc: [0.30672553], save model
[2020-03-09 15:27:45,805.805] train.py [line:105] INFO: current epoch 2 acc: [0.3074049] better than last acc: [0.30672553], save model
2020-03-09 15:27:51,024-INFO: loss at epoch 3 step 5: [1.5952559], acc: [0.234375]
[2020-03-09 15:27:51,024.024] train.py [line:99] INFO: loss at epoch 3 step 5: [1.5952559], acc: [0.234375]
2020-03-09 15:27:55,155-INFO: loss at epoch 3 step 10: [1.5960991], acc: [0.3125]
[2020-03-09 15:27:55,155.155] train.py [line:99] INFO: loss at epoch 3 step 10: [1.5960991], acc: [0.3125]
2020-03-09 15:27:59,299-INFO: loss at epoch 3 step 15: [1.6081111], acc: [0.28125]
[2020-03-09 15:27:59,299.299] train.py [line:99] INFO: loss at epoch 3 step 15: [1.6081111], acc: [0.28125]
2020-03-09 15:28:03,633-INFO: loss at epoch 3 step 20: [1.5938478], acc: [0.421875]
[2020-03-09 15:28:03,633.633] train.py [line:99] INFO: loss at epoch 3 step 20: [1.5938478], acc: [0.421875]
2020-03-09 15:28:07,806-INFO: loss at epoch 3 step 25: [1.6197957], acc: [0.203125]
[2020-03-09 15:28:07,806.806] train.py [line:99] INFO: loss at epoch 3 step 25: [1.6197957], acc: [0.203125]
2020-03-09 15:28:11,844-INFO: loss at epoch 3 step 30: [1.5910263], acc: [0.40625]
[2020-03-09 15:28:11,844.844] train.py [line:99] INFO: loss at epoch 3 step 30: [1.5910263], acc: [0.40625]
2020-03-09 15:28:16,130-INFO: loss at epoch 3 step 35: [1.5988715], acc: [0.28125]
[2020-03-09 15:28:16,130.130] train.py [line:99] INFO: loss at epoch 3 step 35: [1.5988715], acc: [0.28125]
2020-03-09 15:28:20,358-INFO: loss at epoch 3 step 40: [1.5983167], acc: [0.265625]
[2020-03-09 15:28:20,358.358] train.py [line:99] INFO: loss at epoch 3 step 40: [1.5983167], acc: [0.265625]
2020-03-09 15:28:24,359-INFO: loss at epoch 3 step 45: [1.6008418], acc: [0.296875]
[2020-03-09 15:28:24,359.359] train.py [line:99] INFO: loss at epoch 3 step 45: [1.6008418], acc: [0.296875]
2020-03-09 15:28:24,673-INFO: epoch 3 acc: [0.31182066]
[2020-03-09 15:28:24,673.673] train.py [line:102] INFO: epoch 3 acc: [0.31182066]
2020-03-09 15:28:24,674-INFO: current epoch 3 acc: [0.31182066] better than last acc: [0.3074049], save model
[2020-03-09 15:28:24,674.674] train.py [line:105] INFO: current epoch 3 acc: [0.31182066] better than last acc: [0.3074049], save model
2020-03-09 15:28:30,529-INFO: loss at epoch 4 step 5: [1.5885402], acc: [0.359375]
[2020-03-09 15:28:30,529.529] train.py [line:99] INFO: loss at epoch 4 step 5: [1.5885402], acc: [0.359375]
2020-03-09 15:28:35,217-INFO: loss at epoch 4 step 10: [1.588066], acc: [0.390625]
[2020-03-09 15:28:35,217.217] train.py [line:99] INFO: loss at epoch 4 step 10: [1.588066], acc: [0.390625]
2020-03-09 15:28:39,385-INFO: loss at epoch 4 step 15: [1.5979295], acc: [0.25]
[2020-03-09 15:28:39,385.385] train.py [line:99] INFO: loss at epoch 4 step 15: [1.5979295], acc: [0.25]
2020-03-09 15:28:43,428-INFO: loss at epoch 4 step 20: [1.5973804], acc: [0.234375]
[2020-03-09 15:28:43,428.428] train.py [line:99] INFO: loss at epoch 4 step 20: [1.5973804], acc: [0.234375]
2020-03-09 15:28:47,477-INFO: loss at epoch 4 step 25: [1.5923043], acc: [0.328125]
[2020-03-09 15:28:47,477.477] train.py [line:99] INFO: loss at epoch 4 step 25: [1.5923043], acc: [0.328125]
2020-03-09 15:28:51,635-INFO: loss at epoch 4 step 30: [1.5938048], acc: [0.3125]
[2020-03-09 15:28:51,635.635] train.py [line:99] INFO: loss at epoch 4 step 30: [1.5938048], acc: [0.3125]
2020-03-09 15:28:55,876-INFO: loss at epoch 4 step 35: [1.5903678], acc: [0.328125]
[2020-03-09 15:28:55,876.876] train.py [line:99] INFO: loss at epoch 4 step 35: [1.5903678], acc: [0.328125]
2020-03-09 15:28:59,991-INFO: loss at epoch 4 step 40: [1.610435], acc: [0.21875]
[2020-03-09 15:28:59,991.991] train.py [line:99] INFO: loss at epoch 4 step 40: [1.610435], acc: [0.21875]
2020-03-09 15:29:04,067-INFO: loss at epoch 4 step 45: [1.5934954], acc: [0.265625]
[2020-03-09 15:29:04,067.067] train.py [line:99] INFO: loss at epoch 4 step 45: [1.5934954], acc: [0.265625]
2020-03-09 15:29:04,438-INFO: epoch 4 acc: [0.30706522]
[2020-03-09 15:29:04,438.438] train.py [line:102] INFO: epoch 4 acc: [0.30706522]
2020-03-09 15:29:09,385-INFO: loss at epoch 5 step 5: [1.5994024], acc: [0.328125]
[2020-03-09 15:29:09,385.385] train.py [line:99] INFO: loss at epoch 5 step 5: [1.5994024], acc: [0.328125]
2020-03-09 15:29:13,648-INFO: loss at epoch 5 step 10: [1.5963029], acc: [0.3125]
[2020-03-09 15:29:13,648.648] train.py [line:99] INFO: loss at epoch 5 step 10: [1.5963029], acc: [0.3125]
2020-03-09 15:29:17,718-INFO: loss at epoch 5 step 15: [1.6074193], acc: [0.28125]
[2020-03-09 15:29:17,718.718] train.py [line:99] INFO: loss at epoch 5 step 15: [1.6074193], acc: [0.28125]
2020-03-09 15:29:22,006-INFO: loss at epoch 5 step 20: [1.5982354], acc: [0.328125]
[2020-03-09 15:29:22,006.006] train.py [line:99] INFO: loss at epoch 5 step 20: [1.5982354], acc: [0.328125]
2020-03-09 15:29:26,055-INFO: loss at epoch 5 step 25: [1.6008279], acc: [0.234375]
[2020-03-09 15:29:26,055.055] train.py [line:99] INFO: loss at epoch 5 step 25: [1.6008279], acc: [0.234375]
2020-03-09 15:29:30,435-INFO: loss at epoch 5 step 30: [1.6077155], acc: [0.28125]
[2020-03-09 15:29:30,435.435] train.py [line:99] INFO: loss at epoch 5 step 30: [1.6077155], acc: [0.28125]
2020-03-09 15:29:34,599-INFO: loss at epoch 5 step 35: [1.6005772], acc: [0.25]
[2020-03-09 15:29:34,599.599] train.py [line:99] INFO: loss at epoch 5 step 35: [1.6005772], acc: [0.25]
2020-03-09 15:29:38,711-INFO: loss at epoch 5 step 40: [1.5853997], acc: [0.328125]
[2020-03-09 15:29:38,711.711] train.py [line:99] INFO: loss at epoch 5 step 40: [1.5853997], acc: [0.328125]
2020-03-09 15:29:42,709-INFO: loss at epoch 5 step 45: [1.6077719], acc: [0.25]
[2020-03-09 15:29:42,709.709] train.py [line:99] INFO: loss at epoch 5 step 45: [1.6077719], acc: [0.25]
2020-03-09 15:29:43,075-INFO: epoch 5 acc: [0.2982337]
[2020-03-09 15:29:43,075.075] train.py [line:102] INFO: epoch 5 acc: [0.2982337]
2020-03-09 15:29:48,183-INFO: loss at epoch 6 step 5: [1.598316], acc: [0.296875]
[2020-03-09 15:29:48,183.183] train.py [line:99] INFO: loss at epoch 6 step 5: [1.598316], acc: [0.296875]
2020-03-09 15:29:52,311-INFO: loss at epoch 6 step 10: [1.6091461], acc: [0.265625]
[2020-03-09 15:29:52,311.311] train.py [line:99] INFO: loss at epoch 6 step 10: [1.6091461], acc: [0.265625]
2020-03-09 15:29:56,522-INFO: loss at epoch 6 step 15: [1.593323], acc: [0.3125]
[2020-03-09 15:29:56,522.522] train.py [line:99] INFO: loss at epoch 6 step 15: [1.593323], acc: [0.3125]
2020-03-09 15:30:00,793-INFO: loss at epoch 6 step 20: [1.6009337], acc: [0.28125]
[2020-03-09 15:30:00,793.793] train.py [line:99] INFO: loss at epoch 6 step 20: [1.6009337], acc: [0.28125]
2020-03-09 15:30:05,067-INFO: loss at epoch 6 step 25: [1.6004825], acc: [0.28125]
[2020-03-09 15:30:05,067.067] train.py [line:99] INFO: loss at epoch 6 step 25: [1.6004825], acc: [0.28125]
2020-03-09 15:30:09,236-INFO: loss at epoch 6 step 30: [1.5903766], acc: [0.296875]
[2020-03-09 15:30:09,236.236] train.py [line:99] INFO: loss at epoch 6 step 30: [1.5903766], acc: [0.296875]
2020-03-09 15:30:13,332-INFO: loss at epoch 6 step 35: [1.6220949], acc: [0.203125]
[2020-03-09 15:30:13,332.332] train.py [line:99] INFO: loss at epoch 6 step 35: [1.6220949], acc: [0.203125]
2020-03-09 15:30:17,488-INFO: loss at epoch 6 step 40: [1.6104429], acc: [0.25]
[2020-03-09 15:30:17,488.488] train.py [line:99] INFO: loss at epoch 6 step 40: [1.6104429], acc: [0.25]
2020-03-09 15:30:21,510-INFO: loss at epoch 6 step 45: [1.5944788], acc: [0.375]
[2020-03-09 15:30:21,510.510] train.py [line:99] INFO: loss at epoch 6 step 45: [1.5944788], acc: [0.375]
2020-03-09 15:30:21,803-INFO: epoch 6 acc: [0.30774456]
[2020-03-09 15:30:21,803.803] train.py [line:102] INFO: epoch 6 acc: [0.30774456]
2020-03-09 15:30:26,657-INFO: loss at epoch 7 step 5: [1.6060929], acc: [0.328125]
[2020-03-09 15:30:26,657.657] train.py [line:99] INFO: loss at epoch 7 step 5: [1.6060929], acc: [0.328125]
2020-03-09 15:30:30,835-INFO: loss at epoch 7 step 10: [1.585001], acc: [0.359375]
[2020-03-09 15:30:30,835.835] train.py [line:99] INFO: loss at epoch 7 step 10: [1.585001], acc: [0.359375]
2020-03-09 15:30:34,882-INFO: loss at epoch 7 step 15: [1.6008654], acc: [0.3125]
[2020-03-09 15:30:34,882.882] train.py [line:99] INFO: loss at epoch 7 step 15: [1.6008654], acc: [0.3125]
2020-03-09 15:30:39,136-INFO: loss at epoch 7 step 20: [1.5943606], acc: [0.421875]
[2020-03-09 15:30:39,136.136] train.py [line:99] INFO: loss at epoch 7 step 20: [1.5943606], acc: [0.421875]
2020-03-09 15:30:43,243-INFO: loss at epoch 7 step 25: [1.606915], acc: [0.28125]
[2020-03-09 15:30:43,243.243] train.py [line:99] INFO: loss at epoch 7 step 25: [1.606915], acc: [0.28125]
2020-03-09 15:30:47,418-INFO: loss at epoch 7 step 30: [1.5917559], acc: [0.3125]
[2020-03-09 15:30:47,418.418] train.py [line:99] INFO: loss at epoch 7 step 30: [1.5917559], acc: [0.3125]
2020-03-09 15:30:51,570-INFO: loss at epoch 7 step 35: [1.6035596], acc: [0.296875]
[2020-03-09 15:30:51,570.570] train.py [line:99] INFO: loss at epoch 7 step 35: [1.6035596], acc: [0.296875]
2020-03-09 15:30:55,630-INFO: loss at epoch 7 step 40: [1.5946233], acc: [0.328125]
[2020-03-09 15:30:55,630.630] train.py [line:99] INFO: loss at epoch 7 step 40: [1.5946233], acc: [0.328125]
2020-03-09 15:30:59,884-INFO: loss at epoch 7 step 45: [1.6059242], acc: [0.28125]
[2020-03-09 15:30:59,884.884] train.py [line:99] INFO: loss at epoch 7 step 45: [1.6059242], acc: [0.28125]
2020-03-09 15:31:00,247-INFO: epoch 7 acc: [0.3121603]
[2020-03-09 15:31:00,247.247] train.py [line:102] INFO: epoch 7 acc: [0.3121603]
2020-03-09 15:31:00,247-INFO: current epoch 7 acc: [0.3121603] better than last acc: [0.31182066], save model
[2020-03-09 15:31:00,247.247] train.py [line:105] INFO: current epoch 7 acc: [0.3121603] better than last acc: [0.31182066], save model
2020-03-09 15:31:05,544-INFO: loss at epoch 8 step 5: [1.6041166], acc: [0.296875]
[2020-03-09 15:31:05,544.544] train.py [line:99] INFO: loss at epoch 8 step 5: [1.6041166], acc: [0.296875]
2020-03-09 15:31:09,829-INFO: loss at epoch 8 step 10: [1.6135991], acc: [0.265625]
[2020-03-09 15:31:09,829.829] train.py [line:99] INFO: loss at epoch 8 step 10: [1.6135991], acc: [0.265625]
2020-03-09 15:31:13,974-INFO: loss at epoch 8 step 15: [1.5787809], acc: [0.375]
[2020-03-09 15:31:13,974.974] train.py [line:99] INFO: loss at epoch 8 step 15: [1.5787809], acc: [0.375]
2020-03-09 15:31:18,196-INFO: loss at epoch 8 step 20: [1.5829132], acc: [0.421875]
[2020-03-09 15:31:18,196.196] train.py [line:99] INFO: loss at epoch 8 step 20: [1.5829132], acc: [0.421875]
2020-03-09 15:31:22,059-INFO: loss at epoch 8 step 25: [1.5935941], acc: [0.28125]
[2020-03-09 15:31:22,059.059] train.py [line:99] INFO: loss at epoch 8 step 25: [1.5935941], acc: [0.28125]
2020-03-09 15:31:26,190-INFO: loss at epoch 8 step 30: [1.5830628], acc: [0.328125]
[2020-03-09 15:31:26,190.190] train.py [line:99] INFO: loss at epoch 8 step 30: [1.5830628], acc: [0.328125]
2020-03-09 15:31:30,442-INFO: loss at epoch 8 step 35: [1.594005], acc: [0.28125]
[2020-03-09 15:31:30,442.442] train.py [line:99] INFO: loss at epoch 8 step 35: [1.594005], acc: [0.28125]
2020-03-09 15:31:34,627-INFO: loss at epoch 8 step 40: [1.5973294], acc: [0.296875]
[2020-03-09 15:31:34,627.627] train.py [line:99] INFO: loss at epoch 8 step 40: [1.5973294], acc: [0.296875]
2020-03-09 15:31:38,658-INFO: loss at epoch 8 step 45: [1.5801846], acc: [0.3125]
[2020-03-09 15:31:38,658.658] train.py [line:99] INFO: loss at epoch 8 step 45: [1.5801846], acc: [0.3125]
2020-03-09 15:31:39,009-INFO: epoch 8 acc: [0.30163044]
[2020-03-09 15:31:39,009.009] train.py [line:102] INFO: epoch 8 acc: [0.30163044]
2020-03-09 15:31:44,048-INFO: loss at epoch 9 step 5: [1.5883484], acc: [0.34375]
[2020-03-09 15:31:44,048.048] train.py [line:99] INFO: loss at epoch 9 step 5: [1.5883484], acc: [0.34375]
2020-03-09 15:31:48,230-INFO: loss at epoch 9 step 10: [1.5818994], acc: [0.34375]
[2020-03-09 15:31:48,230.230] train.py [line:99] INFO: loss at epoch 9 step 10: [1.5818994], acc: [0.34375]
2020-03-09 15:31:52,338-INFO: loss at epoch 9 step 15: [1.5914074], acc: [0.3125]
[2020-03-09 15:31:52,338.338] train.py [line:99] INFO: loss at epoch 9 step 15: [1.5914074], acc: [0.3125]
2020-03-09 15:31:56,499-INFO: loss at epoch 9 step 20: [1.5987613], acc: [0.328125]
[2020-03-09 15:31:56,499.499] train.py [line:99] INFO: loss at epoch 9 step 20: [1.5987613], acc: [0.328125]
2020-03-09 15:32:00,567-INFO: loss at epoch 9 step 25: [1.5974481], acc: [0.25]
[2020-03-09 15:32:00,567.567] train.py [line:99] INFO: loss at epoch 9 step 25: [1.5974481], acc: [0.25]
2020-03-09 15:32:04,833-INFO: loss at epoch 9 step 30: [1.596801], acc: [0.28125]
[2020-03-09 15:32:04,833.833] train.py [line:99] INFO: loss at epoch 9 step 30: [1.596801], acc: [0.28125]
2020-03-09 15:32:08,986-INFO: loss at epoch 9 step 35: [1.5867531], acc: [0.359375]
[2020-03-09 15:32:08,986.986] train.py [line:99] INFO: loss at epoch 9 step 35: [1.5867531], acc: [0.359375]
2020-03-09 15:32:12,968-INFO: loss at epoch 9 step 40: [1.6090192], acc: [0.21875]
[2020-03-09 15:32:12,968.968] train.py [line:99] INFO: loss at epoch 9 step 40: [1.6090192], acc: [0.21875]
2020-03-09 15:32:17,009-INFO: loss at epoch 9 step 45: [1.6065781], acc: [0.28125]
[2020-03-09 15:32:17,009.009] train.py [line:99] INFO: loss at epoch 9 step 45: [1.6065781], acc: [0.28125]
2020-03-09 15:32:17,345-INFO: epoch 9 acc: [0.3074049]
[2020-03-09 15:32:17,345.345] train.py [line:102] INFO: epoch 9 acc: [0.3074049]
2020-03-09 15:32:17,345-INFO: train till end
[2020-03-09 15:32:17,345.345] train.py [line:110] INFO: train till end
In[7]
#训练1轮,在验证集上评估
!python eval.py
[2020-03-09 15:32:56,698.698] config.py [line:85] INFO: input_size: [3, 224, 224]
[2020-03-09 15:32:56,698.698] config.py [line:86] INFO: class_dim: 5
[2020-03-09 15:32:56,698.698] config.py [line:87] INFO: continue_train: True
[2020-03-09 15:32:56,698.698] config.py [line:88] INFO: train_image_count: 2982
[2020-03-09 15:32:56,699.699] config.py [line:89] INFO: eval_image_count: 688
[2020-03-09 15:32:56,699.699] config.py [line:90] INFO: num_epochs: 10
[2020-03-09 15:32:56,699.699] config.py [line:91] INFO: train_batch_size: 64
[2020-03-09 15:32:56,699.699] config.py [line:92] INFO: mean_rgb: [127.5, 127.5, 127.5]
[2020-03-09 15:32:56,699.699] config.py [line:93] INFO: save_model_dir: ./save_model/net
[2020-03-09 15:32:56,699.699] eval.py [line:16] INFO: start eval
W0309 15:32:57.542837   273 device_context.cc:237] Please NOTE: device: 0, CUDA Capability: 70, Driver API Version: 9.2, Runtime API Version: 9.0
W0309 15:32:57.546497   273 device_context.cc:245] device: 0, cuDNN Version: 7.3.
[2020-03-09 15:33:21,139.139] eval.py [line:45] INFO: test count: 688 , acc: 0.2616279125213623 cost time: 22.116441011428833
In[6]
#对图片进行预测
!python infer.py
2020-03-09 15:32:45,032-INFO: input_size: [3, 224, 224]
[2020-03-09 15:32:45,032.032] config.py [line:85] INFO: input_size: [3, 224, 224]
2020-03-09 15:32:45,033-INFO: class_dim: 5
[2020-03-09 15:32:45,033.033] config.py [line:86] INFO: class_dim: 5
2020-03-09 15:32:45,033-INFO: continue_train: True
[2020-03-09 15:32:45,033.033] config.py [line:87] INFO: continue_train: True
2020-03-09 15:32:45,033-INFO: train_image_count: 2982
[2020-03-09 15:32:45,033.033] config.py [line:88] INFO: train_image_count: 2982
2020-03-09 15:32:45,033-INFO: eval_image_count: 688
[2020-03-09 15:32:45,033.033] config.py [line:89] INFO: eval_image_count: 688
2020-03-09 15:32:45,033-INFO: num_epochs: 10
[2020-03-09 15:32:45,033.033] config.py [line:90] INFO: num_epochs: 10
2020-03-09 15:32:45,033-INFO: train_batch_size: 64
[2020-03-09 15:32:45,033.033] config.py [line:91] INFO: train_batch_size: 64
2020-03-09 15:32:45,033-INFO: mean_rgb: [127.5, 127.5, 127.5]
[2020-03-09 15:32:45,033.033] config.py [line:92] INFO: mean_rgb: [127.5, 127.5, 127.5]
2020-03-09 15:32:45,033-INFO: save_model_dir: ./save_model/net
[2020-03-09 15:32:45,033.033] config.py [line:93] INFO: save_model_dir: ./save_model/net
2020-03-09 15:32:45,045-INFO: input_size: [3, 224, 224]
[2020-03-09 15:32:45,045.045] config.py [line:85] INFO: input_size: [3, 224, 224]
2020-03-09 15:32:45,046-INFO: class_dim: 5
[2020-03-09 15:32:45,046.046] config.py [line:86] INFO: class_dim: 5
2020-03-09 15:32:45,046-INFO: continue_train: True
[2020-03-09 15:32:45,046.046] config.py [line:87] INFO: continue_train: True
2020-03-09 15:32:45,046-INFO: train_image_count: 2982
[2020-03-09 15:32:45,046.046] config.py [line:88] INFO: train_image_count: 2982
2020-03-09 15:32:45,046-INFO: eval_image_count: 688
[2020-03-09 15:32:45,046.046] config.py [line:89] INFO: eval_image_count: 688
2020-03-09 15:32:45,046-INFO: num_epochs: 10
[2020-03-09 15:32:45,046.046] config.py [line:90] INFO: num_epochs: 10
2020-03-09 15:32:45,046-INFO: train_batch_size: 64
[2020-03-09 15:32:45,046.046] config.py [line:91] INFO: train_batch_size: 64
2020-03-09 15:32:45,046-INFO: mean_rgb: [127.5, 127.5, 127.5]
[2020-03-09 15:32:45,046.046] config.py [line:92] INFO: mean_rgb: [127.5, 127.5, 127.5]
2020-03-09 15:32:45,046-INFO: save_model_dir: ./save_model/net
[2020-03-09 15:32:45,046.046] config.py [line:93] INFO: save_model_dir: ./save_model/net
W0309 15:32:45.874236   213 device_context.cc:237] Please NOTE: device: 0, CUDA Capability: 70, Driver API Version: 9.2, Runtime API Version: 9.0
W0309 15:32:45.878165   213 device_context.cc:245] device: 0, cuDNN Version: 7.3.
checkpoint loaded
image data/data2815/sunflowers/14646283472_50a3ae1395.jpg Infer result is: dandelion

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

下载安装命令

## 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 官网,了解更多相关内容

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部