当前位置:   article > 正文

超越 ConvNeXt、Swin(涨点神器): 利用递归门控卷积的高阶空间交互网络

门控卷积

HorNet:新的空间交互模块

1. 摘要

     本文提出递归门控卷积(gnConv),它通过门控卷积核递归设计执行高效、可扩展和平移等变的高阶空间交互,即插即用来改进各种视觉Transformer和基于CNN的模型,并提出新的视觉骨干网络家族:HorNet

2.设计缘由

     1、利用点乘积的自我注意在视觉任务中的有效性尚未从高阶空间交互的方面进行分析;

     2、由于非线性的原因,深度模型存在复杂的计算和经常高阶两个空间位置之间的交互,自注意力和其他动态网络的成功表明,显式和高阶空间交互引入的设计有利于提高视觉模型的建模能力。

     3、视觉建模的基本操作(例如自注意力中的点乘)趋势表明,可以通过增加空间交互的次数来提高网络容量。下图展示了普通卷积、注意力卷积、Transformer block以及本文的递归模块。顺序依次为a、b、c、d。
在这里插入图片描述

3.核心架构:递归门控卷积

     门控卷积结构如下图所示,括号中表示输出通道数。从图中可以看出,门控卷积就是首先通过两个卷积层来调整特征通道数。接着,将深度可分离卷积的输出特征沿着特征分成多块,每一块与前一块交互的特征进一步进行逐元素相乘的方式进行交互,最终得到输出特征。这里递归就是不断地进行逐元素相乘操作,通过这种递归方式特征越在后面的特征高阶信息保存越多,这样在高阶中特征交互就会足够多。
在这里插入图片描述

4.代码复现

本项目基于Paddleclas对HorNet进行复现,对Paddleclas感兴趣的可以去GITHUB了解一下。

代码位置: Hornet.pyPaddleClas/ppcls/arch/backbone/modelzoo/hornet.py

核心代码展示(gnConv部分)

 class gnconv(nn.Layer):
    def __init__(self, dim, order=5, gflayer=None, h=14, w=8, s=1.0):
        super().__init__()
        self.order = order
        self.dims = [dim // 2 ** i for i in range(order)]
        self.dims.reverse()
        self.proj_in = nn.Conv2D(dim, 2*dim, 1)

        if gflayer is None: #这里就是定义上图中的深度可分离卷积
            self.dwconv = get_dwconv(sum(self.dims), 7, True) 
        else:
            self.dwconv = gflayer(sum(self.dims), h=h, w=w)
        
        self.proj_out = nn.Conv2D(dim, dim, 1) #这里就是第一个映射层

        self.pws = nn.LayerList(
            [nn.Conv2D(self.dims[i], self.dims[i+1], 1) for i in range(order-1)]
        )

        self.scale = s
        #print('[gnconv]', order, 'order with dims=', self.dims, 'scale=%.4f'%self.scale)

    def forward(self, x, mask=None, dummy=False):
        B, C, H, W = x.shape

        fused_x = self.proj_in(x)
        pwa, abc = paddle.split(fused_x, (self.dims[0], sum(self.dims)), axis=1) #第一个分离部分

        dw_abc = self.dwconv(abc) * self.scale

        dw_list = paddle.split(dw_abc, self.dims, axis=1) #将特征分成对应的几个部分,也就是第二个split
        x = pwa * dw_list[0]

        for i in range(self.order -1):
            x = self.pws[i](x) * dw_list[i+1]  #这里就是逐元素相乘操作

        x = self.proj_out(x)

        return x
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39

其余部分和ConNeXt类似,这里就不进行详细的展示

5. ImageNet实验结果

下面我们对模型在ImageNet验证集上效果进行展示。

#解压数据集
!mkdir data/ILSVRC2012
!tar -xf ~/data/data105740/ILSVRC2012_val.tar -C ~/data/ILSVRC2012
  • 1
  • 2
  • 3
#导入必要的库
import os
import cv2
import numpy as np
import warnings
import paddle
import paddle.vision.transforms as T
from PIL import Image
warnings.filterwarnings('ignore')

# 构建数据集
class ILSVRC2012(paddle.io.Dataset):
    def __init__(self, root, label_list, transform, backend='pil'):
        self.transform = transform
        self.root = root
        self.label_list = label_list
        self.backend = backend
        self.load_datas()

    def load_datas(self):
        self.imgs = []
        self.labels = []
        with open(self.label_list, 'r') as f:
            for line in f:
                img, label = line[:-1].split(' ')
                self.imgs.append(os.path.join(self.root, img))
                self.labels.append(int(label))

    def __getitem__(self, idx):
        label = self.labels[idx]
        image = self.imgs[idx]
        if self.backend=='cv2':
            image = cv2.imread(image)
        else:
            image = Image.open(image).convert('RGB')
        image = self.transform(image)
        return image.astype('float32'), np.array(label).astype('int64')

    def __len__(self):
        return len(self.imgs)


val_transforms = T.Compose([
    T.Resize(int(224 / 0.96), interpolation='bicubic'),
    T.CenterCrop(224),
    T.ToTensor(),
    T.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
])

val_transform_384 = T.Compose([
    T.Resize(int(384 / 0.96), interpolation='bicubic'),
    T.CenterCrop(384),
    T.ToTensor(),
    T.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
])
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
%cd /home/aistudio/
  • 1
/home/aistudio
  • 1
#创建模型,这里我们复现三个不同体量模型
from Hornet import hornet_tiny_7x7,hornet_small_7x7,hornet_base_gf
model = hornet_tiny_7x7(drop_path_rate = 0.,layer_scale_init_value = 1e-6)
model_small = hornet_small_7x7(drop_path_rate = 0.,layer_scale_init_value = 1e-6)
model_base_gf = hornet_base_gf(drop_path_rate = 0.,layer_scale_init_value = 1e-6)
  • 1
  • 2
  • 3
  • 4
  • 5
W0801 16:01:38.262773   286 gpu_resources.cc:61] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 11.2, Runtime API Version: 10.1
W0801 16:01:38.267696   286 gpu_resources.cc:91] device: 0, cuDNN Version: 7.6.
  • 1
  • 2
#导入权重
model.load_dict(paddle.load('/home/aistudio/hornet_tiny_7x7.pdparams'))
model = paddle.Model(model)

model_small.load_dict(paddle.load('/home/aistudio/hornet_small_7x7.pdparams'))
model_small = paddle.Model(model_small)

model_base_gf.load_dict(paddle.load("/home/aistudio/hornet_base_gf.pdparams"))
model_base_gf = paddle.Model(model_base_gf)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
#模型结构
model.summary((1, 3, 224, 224))
  • 1
  • 2
---------------------------------------------------------------------------
 Layer (type)       Input Shape          Output Shape         Param #    
===========================================================================
   Conv2D-1      [[1, 3, 224, 224]]    [1, 64, 56, 56]         3,136     
  LayerNorm-1    [[1, 64, 56, 56]]     [1, 64, 56, 56]          128      
  LayerNorm-5    [[1, 64, 56, 56]]     [1, 64, 56, 56]          128      
   Conv2D-5      [[1, 64, 56, 56]]     [1, 128, 56, 56]        8,320     
   Conv2D-6      [[1, 96, 56, 56]]     [1, 96, 56, 56]         4,800     
   Conv2D-8      [[1, 32, 56, 56]]     [1, 64, 56, 56]         2,112     
   Conv2D-7      [[1, 64, 56, 56]]     [1, 64, 56, 56]         4,160     
   gnconv-1      [[1, 64, 56, 56]]     [1, 64, 56, 56]           0       
  Identity-1     [[1, 64, 56, 56]]     [1, 64, 56, 56]           0       
  LayerNorm-6    [[1, 56, 56, 64]]     [1, 56, 56, 64]          128      
   Linear-1      [[1, 56, 56, 64]]     [1, 56, 56, 256]       16,640     
    GELU-1       [[1, 56, 56, 256]]    [1, 56, 56, 256]          0       
   Linear-2      [[1, 56, 56, 256]]    [1, 56, 56, 64]        16,448     
    Block-1      [[1, 64, 56, 56]]     [1, 64, 56, 56]          128      
  LayerNorm-7    [[1, 64, 56, 56]]     [1, 64, 56, 56]          128      
   Conv2D-9      [[1, 64, 56, 56]]     [1, 128, 56, 56]        8,320     
   Conv2D-10     [[1, 96, 56, 56]]     [1, 96, 56, 56]         4,800     
   Conv2D-12     [[1, 32, 56, 56]]     [1, 64, 56, 56]         2,112     
   Conv2D-11     [[1, 64, 56, 56]]     [1, 64, 56, 56]         4,160     
   gnconv-2      [[1, 64, 56, 56]]     [1, 64, 56, 56]           0       
  Identity-2     [[1, 64, 56, 56]]     [1, 64, 56, 56]           0       
  LayerNorm-8    [[1, 56, 56, 64]]     [1, 56, 56, 64]          128      
   Linear-3      [[1, 56, 56, 64]]     [1, 56, 56, 256]       16,640     
    GELU-2       [[1, 56, 56, 256]]    [1, 56, 56, 256]          0       
   Linear-4      [[1, 56, 56, 256]]    [1, 56, 56, 64]        16,448     
    Block-2      [[1, 64, 56, 56]]     [1, 64, 56, 56]          128      
  LayerNorm-2    [[1, 64, 56, 56]]     [1, 64, 56, 56]          128      
   Conv2D-2      [[1, 64, 56, 56]]     [1, 128, 28, 28]       32,896     
  LayerNorm-9    [[1, 128, 28, 28]]    [1, 128, 28, 28]         256      
   Conv2D-13     [[1, 128, 28, 28]]    [1, 256, 28, 28]       33,024     
   Conv2D-14     [[1, 224, 28, 28]]    [1, 224, 28, 28]       11,200     
   Conv2D-16     [[1, 32, 28, 28]]     [1, 64, 28, 28]         2,112     
   Conv2D-17     [[1, 64, 28, 28]]     [1, 128, 28, 28]        8,320     
   Conv2D-15     [[1, 128, 28, 28]]    [1, 128, 28, 28]       16,512     
   gnconv-3      [[1, 128, 28, 28]]    [1, 128, 28, 28]          0       
  Identity-3     [[1, 128, 28, 28]]    [1, 128, 28, 28]          0       
 LayerNorm-10    [[1, 28, 28, 128]]    [1, 28, 28, 128]         256      
   Linear-5      [[1, 28, 28, 128]]    [1, 28, 28, 512]       66,048     
    GELU-3       [[1, 28, 28, 512]]    [1, 28, 28, 512]          0       
   Linear-6      [[1, 28, 28, 512]]    [1, 28, 28, 128]       65,664     
    Block-3      [[1, 128, 28, 28]]    [1, 128, 28, 28]         256      
 LayerNorm-11    [[1, 128, 28, 28]]    [1, 128, 28, 28]         256      
   Conv2D-18     [[1, 128, 28, 28]]    [1, 256, 28, 28]       33,024     
   Conv2D-19     [[1, 224, 28, 28]]    [1, 224, 28, 28]       11,200     
   Conv2D-21     [[1, 32, 28, 28]]     [1, 64, 28, 28]         2,112     
   Conv2D-22     [[1, 64, 28, 28]]     [1, 128, 28, 28]        8,320     
   Conv2D-20     [[1, 128, 28, 28]]    [1, 128, 28, 28]       16,512     
   gnconv-4      [[1, 128, 28, 28]]    [1, 128, 28, 28]          0       
  Identity-4     [[1, 128, 28, 28]]    [1, 128, 28, 28]          0       
 LayerNorm-12    [[1, 28, 28, 128]]    [1, 28, 28, 128]         256      
   Linear-7      [[1, 28, 28, 128]]    [1, 28, 28, 512]       66,048     
    GELU-4       [[1, 28, 28, 512]]    [1, 28, 28, 512]          0       
   Linear-8      [[1, 28, 28, 512]]    [1, 28, 28, 128]       65,664     
    Block-4      [[1, 128, 28, 28]]    [1, 128, 28, 28]         256      
 LayerNorm-13    [[1, 128, 28, 28]]    [1, 128, 28, 28]         256      
   Conv2D-23     [[1, 128, 28, 28]]    [1, 256, 28, 28]       33,024     
   Conv2D-24     [[1, 224, 28, 28]]    [1, 224, 28, 28]       11,200     
   Conv2D-26     [[1, 32, 28, 28]]     [1, 64, 28, 28]         2,112     
   Conv2D-27     [[1, 64, 28, 28]]     [1, 128, 28, 28]        8,320     
   Conv2D-25     [[1, 128, 28, 28]]    [1, 128, 28, 28]       16,512     
   gnconv-5      [[1, 128, 28, 28]]    [1, 128, 28, 28]          0       
  Identity-5     [[1, 128, 28, 28]]    [1, 128, 28, 28]          0       
 LayerNorm-14    [[1, 28, 28, 128]]    [1, 28, 28, 128]         256      
   Linear-9      [[1, 28, 28, 128]]    [1, 28, 28, 512]       66,048     
    GELU-5       [[1, 28, 28, 512]]    [1, 28, 28, 512]          0       
   Linear-10     [[1, 28, 28, 512]]    [1, 28, 28, 128]       65,664     
    Block-5      [[1, 128, 28, 28]]    [1, 128, 28, 28]         256      
  LayerNorm-3    [[1, 128, 28, 28]]    [1, 128, 28, 28]         256      
   Conv2D-3      [[1, 128, 28, 28]]    [1, 256, 14, 14]       131,328    
 LayerNorm-15    [[1, 256, 14, 14]]    [1, 256, 14, 14]         512      
   Conv2D-28     [[1, 256, 14, 14]]    [1, 512, 14, 14]       131,584    
   Conv2D-29     [[1, 480, 14, 14]]    [1, 480, 14, 14]       24,000     
   Conv2D-31     [[1, 32, 14, 14]]     [1, 64, 14, 14]         2,112     
   Conv2D-32     [[1, 64, 14, 14]]     [1, 128, 14, 14]        8,320     
   Conv2D-33     [[1, 128, 14, 14]]    [1, 256, 14, 14]       33,024     
   Conv2D-30     [[1, 256, 14, 14]]    [1, 256, 14, 14]       65,792     
   gnconv-6      [[1, 256, 14, 14]]    [1, 256, 14, 14]          0       
  Identity-6     [[1, 256, 14, 14]]    [1, 256, 14, 14]          0       
 LayerNorm-16    [[1, 14, 14, 256]]    [1, 14, 14, 256]         512      
   Linear-11     [[1, 14, 14, 256]]   [1, 14, 14, 1024]       263,168    
    GELU-6      [[1, 14, 14, 1024]]   [1, 14, 14, 1024]          0       
   Linear-12    [[1, 14, 14, 1024]]    [1, 14, 14, 256]       262,400    
    Block-6      [[1, 256, 14, 14]]    [1, 256, 14, 14]         512      
 LayerNorm-17    [[1, 256, 14, 14]]    [1, 256, 14, 14]         512      
   Conv2D-34     [[1, 256, 14, 14]]    [1, 512, 14, 14]       131,584    
   Conv2D-35     [[1, 480, 14, 14]]    [1, 480, 14, 14]       24,000     
   Conv2D-37     [[1, 32, 14, 14]]     [1, 64, 14, 14]         2,112     
   Conv2D-38     [[1, 64, 14, 14]]     [1, 128, 14, 14]        8,320     
   Conv2D-39     [[1, 128, 14, 14]]    [1, 256, 14, 14]       33,024     
   Conv2D-36     [[1, 256, 14, 14]]    [1, 256, 14, 14]       65,792     
   gnconv-7      [[1, 256, 14, 14]]    [1, 256, 14, 14]          0       
  Identity-7     [[1, 256, 14, 14]]    [1, 256, 14, 14]          0       
 LayerNorm-18    [[1, 14, 14, 256]]    [1, 14, 14, 256]         512      
   Linear-13     [[1, 14, 14, 256]]   [1, 14, 14, 1024]       263,168    
    GELU-7      [[1, 14, 14, 1024]]   [1, 14, 14, 1024]          0       
   Linear-14    [[1, 14, 14, 1024]]    [1, 14, 14, 256]       262,400    
    Block-7      [[1, 256, 14, 14]]    [1, 256, 14, 14]         512      
 LayerNorm-19    [[1, 256, 14, 14]]    [1, 256, 14, 14]         512      
   Conv2D-40     [[1, 256, 14, 14]]    [1, 512, 14, 14]       131,584    
   Conv2D-41     [[1, 480, 14, 14]]    [1, 480, 14, 14]       24,000     
   Conv2D-43     [[1, 32, 14, 14]]     [1, 64, 14, 14]         2,112     
   Conv2D-44     [[1, 64, 14, 14]]     [1, 128, 14, 14]        8,320     
   Conv2D-45     [[1, 128, 14, 14]]    [1, 256, 14, 14]       33,024     
   Conv2D-42     [[1, 256, 14, 14]]    [1, 256, 14, 14]       65,792     
   gnconv-8      [[1, 256, 14, 14]]    [1, 256, 14, 14]          0       
  Identity-8     [[1, 256, 14, 14]]    [1, 256, 14, 14]          0       
 LayerNorm-20    [[1, 14, 14, 256]]    [1, 14, 14, 256]         512      
   Linear-15     [[1, 14, 14, 256]]   [1, 14, 14, 1024]       263,168    
    GELU-8      [[1, 14, 14, 1024]]   [1, 14, 14, 1024]          0       
   Linear-16    [[1, 14, 14, 1024]]    [1, 14, 14, 256]       262,400    
    Block-8      [[1, 256, 14, 14]]    [1, 256, 14, 14]         512      
 LayerNorm-21    [[1, 256, 14, 14]]    [1, 256, 14, 14]         512      
   Conv2D-46     [[1, 256, 14, 14]]    [1, 512, 14, 14]       131,584    
   Conv2D-47     [[1, 480, 14, 14]]    [1, 480, 14, 14]       24,000     
   Conv2D-49     [[1, 32, 14, 14]]     [1, 64, 14, 14]         2,112     
   Conv2D-50     [[1, 64, 14, 14]]     [1, 128, 14, 14]        8,320     
   Conv2D-51     [[1, 128, 14, 14]]    [1, 256, 14, 14]       33,024     
   Conv2D-48     [[1, 256, 14, 14]]    [1, 256, 14, 14]       65,792     
   gnconv-9      [[1, 256, 14, 14]]    [1, 256, 14, 14]          0       
  Identity-9     [[1, 256, 14, 14]]    [1, 256, 14, 14]          0       
 LayerNorm-22    [[1, 14, 14, 256]]    [1, 14, 14, 256]         512      
   Linear-17     [[1, 14, 14, 256]]   [1, 14, 14, 1024]       263,168    
    GELU-9      [[1, 14, 14, 1024]]   [1, 14, 14, 1024]          0       
   Linear-18    [[1, 14, 14, 1024]]    [1, 14, 14, 256]       262,400    
    Block-9      [[1, 256, 14, 14]]    [1, 256, 14, 14]         512      
 LayerNorm-23    [[1, 256, 14, 14]]    [1, 256, 14, 14]         512      
   Conv2D-52     [[1, 256, 14, 14]]    [1, 512, 14, 14]       131,584    
   Conv2D-53     [[1, 480, 14, 14]]    [1, 480, 14, 14]       24,000     
   Conv2D-55     [[1, 32, 14, 14]]     [1, 64, 14, 14]         2,112     
   Conv2D-56     [[1, 64, 14, 14]]     [1, 128, 14, 14]        8,320     
   Conv2D-57     [[1, 128, 14, 14]]    [1, 256, 14, 14]       33,024     
   Conv2D-54     [[1, 256, 14, 14]]    [1, 256, 14, 14]       65,792     
   gnconv-10     [[1, 256, 14, 14]]    [1, 256, 14, 14]          0       
  Identity-10    [[1, 256, 14, 14]]    [1, 256, 14, 14]          0       
 LayerNorm-24    [[1, 14, 14, 256]]    [1, 14, 14, 256]         512      
   Linear-19     [[1, 14, 14, 256]]   [1, 14, 14, 1024]       263,168    
    GELU-10     [[1, 14, 14, 1024]]   [1, 14, 14, 1024]          0       
   Linear-20    [[1, 14, 14, 1024]]    [1, 14, 14, 256]       262,400    
   Block-10      [[1, 256, 14, 14]]    [1, 256, 14, 14]         512      
 LayerNorm-25    [[1, 256, 14, 14]]    [1, 256, 14, 14]         512      
   Conv2D-58     [[1, 256, 14, 14]]    [1, 512, 14, 14]       131,584    
   Conv2D-59     [[1, 480, 14, 14]]    [1, 480, 14, 14]       24,000     
   Conv2D-61     [[1, 32, 14, 14]]     [1, 64, 14, 14]         2,112     
   Conv2D-62     [[1, 64, 14, 14]]     [1, 128, 14, 14]        8,320     
   Conv2D-63     [[1, 128, 14, 14]]    [1, 256, 14, 14]       33,024     
   Conv2D-60     [[1, 256, 14, 14]]    [1, 256, 14, 14]       65,792     
   gnconv-11     [[1, 256, 14, 14]]    [1, 256, 14, 14]          0       
  Identity-11    [[1, 256, 14, 14]]    [1, 256, 14, 14]          0       
 LayerNorm-26    [[1, 14, 14, 256]]    [1, 14, 14, 256]         512      
   Linear-21     [[1, 14, 14, 256]]   [1, 14, 14, 1024]       263,168    
    GELU-11     [[1, 14, 14, 1024]]   [1, 14, 14, 1024]          0       
   Linear-22    [[1, 14, 14, 1024]]    [1, 14, 14, 256]       262,400    
   Block-11      [[1, 256, 14, 14]]    [1, 256, 14, 14]         512      
 LayerNorm-27    [[1, 256, 14, 14]]    [1, 256, 14, 14]         512      
   Conv2D-64     [[1, 256, 14, 14]]    [1, 512, 14, 14]       131,584    
   Conv2D-65     [[1, 480, 14, 14]]    [1, 480, 14, 14]       24,000     
   Conv2D-67     [[1, 32, 14, 14]]     [1, 64, 14, 14]         2,112     
   Conv2D-68     [[1, 64, 14, 14]]     [1, 128, 14, 14]        8,320     
   Conv2D-69     [[1, 128, 14, 14]]    [1, 256, 14, 14]       33,024     
   Conv2D-66     [[1, 256, 14, 14]]    [1, 256, 14, 14]       65,792     
   gnconv-12     [[1, 256, 14, 14]]    [1, 256, 14, 14]          0       
  Identity-12    [[1, 256, 14, 14]]    [1, 256, 14, 14]          0       
 LayerNorm-28    [[1, 14, 14, 256]]    [1, 14, 14, 256]         512      
   Linear-23     [[1, 14, 14, 256]]   [1, 14, 14, 1024]       263,168    
    GELU-12     [[1, 14, 14, 1024]]   [1, 14, 14, 1024]          0       
   Linear-24    [[1, 14, 14, 1024]]    [1, 14, 14, 256]       262,400    
   Block-12      [[1, 256, 14, 14]]    [1, 256, 14, 14]         512      
 LayerNorm-29    [[1, 256, 14, 14]]    [1, 256, 14, 14]         512      
   Conv2D-70     [[1, 256, 14, 14]]    [1, 512, 14, 14]       131,584    
   Conv2D-71     [[1, 480, 14, 14]]    [1, 480, 14, 14]       24,000     
   Conv2D-73     [[1, 32, 14, 14]]     [1, 64, 14, 14]         2,112     
   Conv2D-74     [[1, 64, 14, 14]]     [1, 128, 14, 14]        8,320     
   Conv2D-75     [[1, 128, 14, 14]]    [1, 256, 14, 14]       33,024     
   Conv2D-72     [[1, 256, 14, 14]]    [1, 256, 14, 14]       65,792     
   gnconv-13     [[1, 256, 14, 14]]    [1, 256, 14, 14]          0       
  Identity-13    [[1, 256, 14, 14]]    [1, 256, 14, 14]          0       
 LayerNorm-30    [[1, 14, 14, 256]]    [1, 14, 14, 256]         512      
   Linear-25     [[1, 14, 14, 256]]   [1, 14, 14, 1024]       263,168    
    GELU-13     [[1, 14, 14, 1024]]   [1, 14, 14, 1024]          0       
   Linear-26    [[1, 14, 14, 1024]]    [1, 14, 14, 256]       262,400    
   Block-13      [[1, 256, 14, 14]]    [1, 256, 14, 14]         512      
 LayerNorm-31    [[1, 256, 14, 14]]    [1, 256, 14, 14]         512      
   Conv2D-76     [[1, 256, 14, 14]]    [1, 512, 14, 14]       131,584    
   Conv2D-77     [[1, 480, 14, 14]]    [1, 480, 14, 14]       24,000     
   Conv2D-79     [[1, 32, 14, 14]]     [1, 64, 14, 14]         2,112     
   Conv2D-80     [[1, 64, 14, 14]]     [1, 128, 14, 14]        8,320     
   Conv2D-81     [[1, 128, 14, 14]]    [1, 256, 14, 14]       33,024     
   Conv2D-78     [[1, 256, 14, 14]]    [1, 256, 14, 14]       65,792     
   gnconv-14     [[1, 256, 14, 14]]    [1, 256, 14, 14]          0       
  Identity-14    [[1, 256, 14, 14]]    [1, 256, 14, 14]          0       
 LayerNorm-32    [[1, 14, 14, 256]]    [1, 14, 14, 256]         512      
   Linear-27     [[1, 14, 14, 256]]   [1, 14, 14, 1024]       263,168    
    GELU-14     [[1, 14, 14, 1024]]   [1, 14, 14, 1024]          0       
   Linear-28    [[1, 14, 14, 1024]]    [1, 14, 14, 256]       262,400    
   Block-14      [[1, 256, 14, 14]]    [1, 256, 14, 14]         512      
 LayerNorm-33    [[1, 256, 14, 14]]    [1, 256, 14, 14]         512      
   Conv2D-82     [[1, 256, 14, 14]]    [1, 512, 14, 14]       131,584    
   Conv2D-83     [[1, 480, 14, 14]]    [1, 480, 14, 14]       24,000     
   Conv2D-85     [[1, 32, 14, 14]]     [1, 64, 14, 14]         2,112     
   Conv2D-86     [[1, 64, 14, 14]]     [1, 128, 14, 14]        8,320     
   Conv2D-87     [[1, 128, 14, 14]]    [1, 256, 14, 14]       33,024     
   Conv2D-84     [[1, 256, 14, 14]]    [1, 256, 14, 14]       65,792     
   gnconv-15     [[1, 256, 14, 14]]    [1, 256, 14, 14]          0       
  Identity-15    [[1, 256, 14, 14]]    [1, 256, 14, 14]          0       
 LayerNorm-34    [[1, 14, 14, 256]]    [1, 14, 14, 256]         512      
   Linear-29     [[1, 14, 14, 256]]   [1, 14, 14, 1024]       263,168    
    GELU-15     [[1, 14, 14, 1024]]   [1, 14, 14, 1024]          0       
   Linear-30    [[1, 14, 14, 1024]]    [1, 14, 14, 256]       262,400    
   Block-15      [[1, 256, 14, 14]]    [1, 256, 14, 14]         512      
 LayerNorm-35    [[1, 256, 14, 14]]    [1, 256, 14, 14]         512      
   Conv2D-88     [[1, 256, 14, 14]]    [1, 512, 14, 14]       131,584    
   Conv2D-89     [[1, 480, 14, 14]]    [1, 480, 14, 14]       24,000     
   Conv2D-91     [[1, 32, 14, 14]]     [1, 64, 14, 14]         2,112     
   Conv2D-92     [[1, 64, 14, 14]]     [1, 128, 14, 14]        8,320     
   Conv2D-93     [[1, 128, 14, 14]]    [1, 256, 14, 14]       33,024     
   Conv2D-90     [[1, 256, 14, 14]]    [1, 256, 14, 14]       65,792     
   gnconv-16     [[1, 256, 14, 14]]    [1, 256, 14, 14]          0       
  Identity-16    [[1, 256, 14, 14]]    [1, 256, 14, 14]          0       
 LayerNorm-36    [[1, 14, 14, 256]]    [1, 14, 14, 256]         512      
   Linear-31     [[1, 14, 14, 256]]   [1, 14, 14, 1024]       263,168    
    GELU-16     [[1, 14, 14, 1024]]   [1, 14, 14, 1024]          0       
   Linear-32    [[1, 14, 14, 1024]]    [1, 14, 14, 256]       262,400    
   Block-16      [[1, 256, 14, 14]]    [1, 256, 14, 14]         512      
 LayerNorm-37    [[1, 256, 14, 14]]    [1, 256, 14, 14]         512      
   Conv2D-94     [[1, 256, 14, 14]]    [1, 512, 14, 14]       131,584    
   Conv2D-95     [[1, 480, 14, 14]]    [1, 480, 14, 14]       24,000     
   Conv2D-97     [[1, 32, 14, 14]]     [1, 64, 14, 14]         2,112     
   Conv2D-98     [[1, 64, 14, 14]]     [1, 128, 14, 14]        8,320     
   Conv2D-99     [[1, 128, 14, 14]]    [1, 256, 14, 14]       33,024     
   Conv2D-96     [[1, 256, 14, 14]]    [1, 256, 14, 14]       65,792     
   gnconv-17     [[1, 256, 14, 14]]    [1, 256, 14, 14]          0       
  Identity-17    [[1, 256, 14, 14]]    [1, 256, 14, 14]          0       
 LayerNorm-38    [[1, 14, 14, 256]]    [1, 14, 14, 256]         512      
   Linear-33     [[1, 14, 14, 256]]   [1, 14, 14, 1024]       263,168    
    GELU-17     [[1, 14, 14, 1024]]   [1, 14, 14, 1024]          0       
   Linear-34    [[1, 14, 14, 1024]]    [1, 14, 14, 256]       262,400    
   Block-17      [[1, 256, 14, 14]]    [1, 256, 14, 14]         512      
 LayerNorm-39    [[1, 256, 14, 14]]    [1, 256, 14, 14]         512      
  Conv2D-100     [[1, 256, 14, 14]]    [1, 512, 14, 14]       131,584    
  Conv2D-101     [[1, 480, 14, 14]]    [1, 480, 14, 14]       24,000     
  Conv2D-103     [[1, 32, 14, 14]]     [1, 64, 14, 14]         2,112     
  Conv2D-104     [[1, 64, 14, 14]]     [1, 128, 14, 14]        8,320     
  Conv2D-105     [[1, 128, 14, 14]]    [1, 256, 14, 14]       33,024     
  Conv2D-102     [[1, 256, 14, 14]]    [1, 256, 14, 14]       65,792     
   gnconv-18     [[1, 256, 14, 14]]    [1, 256, 14, 14]          0       
  Identity-18    [[1, 256, 14, 14]]    [1, 256, 14, 14]          0       
 LayerNorm-40    [[1, 14, 14, 256]]    [1, 14, 14, 256]         512      
   Linear-35     [[1, 14, 14, 256]]   [1, 14, 14, 1024]       263,168    
    GELU-18     [[1, 14, 14, 1024]]   [1, 14, 14, 1024]          0       
   Linear-36    [[1, 14, 14, 1024]]    [1, 14, 14, 256]       262,400    
   Block-18      [[1, 256, 14, 14]]    [1, 256, 14, 14]         512      
 LayerNorm-41    [[1, 256, 14, 14]]    [1, 256, 14, 14]         512      
  Conv2D-106     [[1, 256, 14, 14]]    [1, 512, 14, 14]       131,584    
  Conv2D-107     [[1, 480, 14, 14]]    [1, 480, 14, 14]       24,000     
  Conv2D-109     [[1, 32, 14, 14]]     [1, 64, 14, 14]         2,112     
  Conv2D-110     [[1, 64, 14, 14]]     [1, 128, 14, 14]        8,320     
  Conv2D-111     [[1, 128, 14, 14]]    [1, 256, 14, 14]       33,024     
  Conv2D-108     [[1, 256, 14, 14]]    [1, 256, 14, 14]       65,792     
   gnconv-19     [[1, 256, 14, 14]]    [1, 256, 14, 14]          0       
  Identity-19    [[1, 256, 14, 14]]    [1, 256, 14, 14]          0       
 LayerNorm-42    [[1, 14, 14, 256]]    [1, 14, 14, 256]         512      
   Linear-37     [[1, 14, 14, 256]]   [1, 14, 14, 1024]       263,168    
    GELU-19     [[1, 14, 14, 1024]]   [1, 14, 14, 1024]          0       
   Linear-38    [[1, 14, 14, 1024]]    [1, 14, 14, 256]       262,400    
   Block-19      [[1, 256, 14, 14]]    [1, 256, 14, 14]         512      
 LayerNorm-43    [[1, 256, 14, 14]]    [1, 256, 14, 14]         512      
  Conv2D-112     [[1, 256, 14, 14]]    [1, 512, 14, 14]       131,584    
  Conv2D-113     [[1, 480, 14, 14]]    [1, 480, 14, 14]       24,000     
  Conv2D-115     [[1, 32, 14, 14]]     [1, 64, 14, 14]         2,112     
  Conv2D-116     [[1, 64, 14, 14]]     [1, 128, 14, 14]        8,320     
  Conv2D-117     [[1, 128, 14, 14]]    [1, 256, 14, 14]       33,024     
  Conv2D-114     [[1, 256, 14, 14]]    [1, 256, 14, 14]       65,792     
   gnconv-20     [[1, 256, 14, 14]]    [1, 256, 14, 14]          0       
  Identity-20    [[1, 256, 14, 14]]    [1, 256, 14, 14]          0       
 LayerNorm-44    [[1, 14, 14, 256]]    [1, 14, 14, 256]         512      
   Linear-39     [[1, 14, 14, 256]]   [1, 14, 14, 1024]       263,168    
    GELU-20     [[1, 14, 14, 1024]]   [1, 14, 14, 1024]          0       
   Linear-40    [[1, 14, 14, 1024]]    [1, 14, 14, 256]       262,400    
   Block-20      [[1, 256, 14, 14]]    [1, 256, 14, 14]         512      
 LayerNorm-45    [[1, 256, 14, 14]]    [1, 256, 14, 14]         512      
  Conv2D-118     [[1, 256, 14, 14]]    [1, 512, 14, 14]       131,584    
  Conv2D-119     [[1, 480, 14, 14]]    [1, 480, 14, 14]       24,000     
  Conv2D-121     [[1, 32, 14, 14]]     [1, 64, 14, 14]         2,112     
  Conv2D-122     [[1, 64, 14, 14]]     [1, 128, 14, 14]        8,320     
  Conv2D-123     [[1, 128, 14, 14]]    [1, 256, 14, 14]       33,024     
  Conv2D-120     [[1, 256, 14, 14]]    [1, 256, 14, 14]       65,792     
   gnconv-21     [[1, 256, 14, 14]]    [1, 256, 14, 14]          0       
  Identity-21    [[1, 256, 14, 14]]    [1, 256, 14, 14]          0       
 LayerNorm-46    [[1, 14, 14, 256]]    [1, 14, 14, 256]         512      
   Linear-41     [[1, 14, 14, 256]]   [1, 14, 14, 1024]       263,168    
    GELU-21     [[1, 14, 14, 1024]]   [1, 14, 14, 1024]          0       
   Linear-42    [[1, 14, 14, 1024]]    [1, 14, 14, 256]       262,400    
   Block-21      [[1, 256, 14, 14]]    [1, 256, 14, 14]         512      
 LayerNorm-47    [[1, 256, 14, 14]]    [1, 256, 14, 14]         512      
  Conv2D-124     [[1, 256, 14, 14]]    [1, 512, 14, 14]       131,584    
  Conv2D-125     [[1, 480, 14, 14]]    [1, 480, 14, 14]       24,000     
  Conv2D-127     [[1, 32, 14, 14]]     [1, 64, 14, 14]         2,112     
  Conv2D-128     [[1, 64, 14, 14]]     [1, 128, 14, 14]        8,320     
  Conv2D-129     [[1, 128, 14, 14]]    [1, 256, 14, 14]       33,024     
  Conv2D-126     [[1, 256, 14, 14]]    [1, 256, 14, 14]       65,792     
   gnconv-22     [[1, 256, 14, 14]]    [1, 256, 14, 14]          0       
  Identity-22    [[1, 256, 14, 14]]    [1, 256, 14, 14]          0       
 LayerNorm-48    [[1, 14, 14, 256]]    [1, 14, 14, 256]         512      
   Linear-43     [[1, 14, 14, 256]]   [1, 14, 14, 1024]       263,168    
    GELU-22     [[1, 14, 14, 1024]]   [1, 14, 14, 1024]          0       
   Linear-44    [[1, 14, 14, 1024]]    [1, 14, 14, 256]       262,400    
   Block-22      [[1, 256, 14, 14]]    [1, 256, 14, 14]         512      
 LayerNorm-49    [[1, 256, 14, 14]]    [1, 256, 14, 14]         512      
  Conv2D-130     [[1, 256, 14, 14]]    [1, 512, 14, 14]       131,584    
  Conv2D-131     [[1, 480, 14, 14]]    [1, 480, 14, 14]       24,000     
  Conv2D-133     [[1, 32, 14, 14]]     [1, 64, 14, 14]         2,112     
  Conv2D-134     [[1, 64, 14, 14]]     [1, 128, 14, 14]        8,320     
  Conv2D-135     [[1, 128, 14, 14]]    [1, 256, 14, 14]       33,024     
  Conv2D-132     [[1, 256, 14, 14]]    [1, 256, 14, 14]       65,792     
   gnconv-23     [[1, 256, 14, 14]]    [1, 256, 14, 14]          0       
  Identity-23    [[1, 256, 14, 14]]    [1, 256, 14, 14]          0       
 LayerNorm-50    [[1, 14, 14, 256]]    [1, 14, 14, 256]         512      
   Linear-45     [[1, 14, 14, 256]]   [1, 14, 14, 1024]       263,168    
    GELU-23     [[1, 14, 14, 1024]]   [1, 14, 14, 1024]          0       
   Linear-46    [[1, 14, 14, 1024]]    [1, 14, 14, 256]       262,400    
   Block-23      [[1, 256, 14, 14]]    [1, 256, 14, 14]         512      
  LayerNorm-4    [[1, 256, 14, 14]]    [1, 256, 14, 14]         512      
   Conv2D-4      [[1, 256, 14, 14]]     [1, 512, 7, 7]        524,800    
 LayerNorm-51     [[1, 512, 7, 7]]      [1, 512, 7, 7]         1,024     
  Conv2D-136      [[1, 512, 7, 7]]     [1, 1024, 7, 7]        525,312    
  Conv2D-137      [[1, 992, 7, 7]]      [1, 992, 7, 7]        49,600     
  Conv2D-139      [[1, 32, 7, 7]]       [1, 64, 7, 7]          2,112     
  Conv2D-140      [[1, 64, 7, 7]]       [1, 128, 7, 7]         8,320     
  Conv2D-141      [[1, 128, 7, 7]]      [1, 256, 7, 7]        33,024     
  Conv2D-142      [[1, 256, 7, 7]]      [1, 512, 7, 7]        131,584    
  Conv2D-138      [[1, 512, 7, 7]]      [1, 512, 7, 7]        262,656    
   gnconv-24      [[1, 512, 7, 7]]      [1, 512, 7, 7]           0       
  Identity-24     [[1, 512, 7, 7]]      [1, 512, 7, 7]           0       
 LayerNorm-52     [[1, 7, 7, 512]]      [1, 7, 7, 512]         1,024     
   Linear-47      [[1, 7, 7, 512]]     [1, 7, 7, 2048]       1,050,624   
    GELU-24      [[1, 7, 7, 2048]]     [1, 7, 7, 2048]           0       
   Linear-48     [[1, 7, 7, 2048]]      [1, 7, 7, 512]       1,049,088   
   Block-24       [[1, 512, 7, 7]]      [1, 512, 7, 7]         1,024     
 LayerNorm-53     [[1, 512, 7, 7]]      [1, 512, 7, 7]         1,024     
  Conv2D-143      [[1, 512, 7, 7]]     [1, 1024, 7, 7]        525,312    
  Conv2D-144      [[1, 992, 7, 7]]      [1, 992, 7, 7]        49,600     
  Conv2D-146      [[1, 32, 7, 7]]       [1, 64, 7, 7]          2,112     
  Conv2D-147      [[1, 64, 7, 7]]       [1, 128, 7, 7]         8,320     
  Conv2D-148      [[1, 128, 7, 7]]      [1, 256, 7, 7]        33,024     
  Conv2D-149      [[1, 256, 7, 7]]      [1, 512, 7, 7]        131,584    
  Conv2D-145      [[1, 512, 7, 7]]      [1, 512, 7, 7]        262,656    
   gnconv-25      [[1, 512, 7, 7]]      [1, 512, 7, 7]           0       
  Identity-25     [[1, 512, 7, 7]]      [1, 512, 7, 7]           0       
 LayerNorm-54     [[1, 7, 7, 512]]      [1, 7, 7, 512]         1,024     
   Linear-49      [[1, 7, 7, 512]]     [1, 7, 7, 2048]       1,050,624   
    GELU-25      [[1, 7, 7, 2048]]     [1, 7, 7, 2048]           0       
   Linear-50     [[1, 7, 7, 2048]]      [1, 7, 7, 512]       1,049,088   
   Block-25       [[1, 512, 7, 7]]      [1, 512, 7, 7]         1,024     
 LayerNorm-55        [[1, 512]]            [1, 512]            1,024     
   Linear-51         [[1, 512]]           [1, 1000]           513,000    
===========================================================================
Total params: 22,409,512
Trainable params: 22,409,512
Non-trainable params: 0
---------------------------------------------------------------------------
Input size (MB): 0.57
Forward/backward pass size (MB): 263.41
Params size (MB): 85.49
Estimated Total Size (MB): 349.47
---------------------------------------------------------------------------






{'total_params': 22409512, 'trainable_params': 22409512}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209
  • 210
  • 211
  • 212
  • 213
  • 214
  • 215
  • 216
  • 217
  • 218
  • 219
  • 220
  • 221
  • 222
  • 223
  • 224
  • 225
  • 226
  • 227
  • 228
  • 229
  • 230
  • 231
  • 232
  • 233
  • 234
  • 235
  • 236
  • 237
  • 238
  • 239
  • 240
  • 241
  • 242
  • 243
  • 244
  • 245
  • 246
  • 247
  • 248
  • 249
  • 250
  • 251
  • 252
  • 253
  • 254
  • 255
  • 256
  • 257
  • 258
  • 259
  • 260
  • 261
  • 262
  • 263
  • 264
  • 265
  • 266
  • 267
  • 268
  • 269
  • 270
  • 271
  • 272
  • 273
  • 274
  • 275
  • 276
  • 277
  • 278
  • 279
  • 280
  • 281
  • 282
  • 283
  • 284
  • 285
  • 286
  • 287
  • 288
  • 289
  • 290
  • 291
  • 292
  • 293
  • 294
  • 295
  • 296
  • 297
  • 298
  • 299
  • 300
  • 301
  • 302
  • 303
  • 304
  • 305
  • 306
  • 307
  • 308
  • 309
  • 310
  • 311
  • 312
  • 313
  • 314
  • 315
  • 316
  • 317
  • 318
  • 319
  • 320
  • 321
  • 322
  • 323
  • 324
  • 325
  • 326
  • 327
  • 328
  • 329
  • 330
  • 331
  • 332
  • 333
  • 334
  • 335
  • 336
  • 337
  • 338
  • 339
  • 340
  • 341
  • 342
  • 343
  • 344
  • 345
  • 346
  • 347
  • 348
  • 349
  • 350
  • 351
  • 352
  • 353
  • 354
  • 355
  • 356
  • 357
  • 358
  • 359
  • 360
  • 361
  • 362
  • 363
  • 364
  • 365
  • 366
  • 367
  • 368
  • 369
  • 370
  • 371
  • 372
  • 373
  • 374
  • 375
#tiny模型结果
model.prepare(metrics=paddle.metric.Accuracy(topk=(1, 5)))
val_dataset = ILSVRC2012('/home/aistudio/data/ILSVRC2012/ILSVRC2012_val', transform=val_transforms, label_list='/home/aistudio/data/ILSVRC2012/ILSVRC2012_val/val_list.txt', backend='pil')
acc = model.evaluate(val_dataset, batch_size=32, num_workers=4, verbose=1)
print(acc)
  • 1
  • 2
  • 3
  • 4
  • 5
Eval begin...
step 1563/1563 [==============================] - acc_top1: 0.8270 - acc_top5: 0.9637 - 98ms/step         
Eval samples: 50000
{'acc_top1': 0.82698, 'acc_top5': 0.96374}
  • 1
  • 2
  • 3
  • 4
#small模型结果
model_small.prepare(metrics=paddle.metric.Accuracy(topk=(1, 5)))
val_dataset = ILSVRC2012('/home/aistudio/data/ILSVRC2012/ILSVRC2012_val', transform=val_transforms, label_list='/home/aistudio/data/ILSVRC2012/ILSVRC2012_val/val_list.txt', backend='pil')
acc = model_small.evaluate(val_dataset, batch_size=32, num_workers=4, verbose=1)
print(acc)
  • 1
  • 2
  • 3
  • 4
  • 5
Eval begin...
step 1563/1563 [==============================] - acc_top1: 0.8390 - acc_top5: 0.9681 - 111ms/step         
Eval samples: 50000
{'acc_top1': 0.83898, 'acc_top5': 0.96814}
  • 1
  • 2
  • 3
  • 4
#base模型结果
model_base_gf.prepare(metrics=paddle.metric.Accuracy(topk=(1, 5)))
val_dataset = ILSVRC2012('/home/aistudio/data/ILSVRC2012/ILSVRC2012_val', transform=val_transforms, label_list='/home/aistudio/data/ILSVRC2012/ILSVRC2012_val/val_list.txt', backend='pil')
acc = model_base_gf.evaluate(val_dataset, batch_size=32, num_workers=4, verbose=1)
print(acc)
  • 1
  • 2
  • 3
  • 4
  • 5
Eval begin...
step 1563/1563 [==============================] - acc_top1: 0.8448 - acc_top5: 0.9701 - 183ms/step         
Eval samples: 50000
{'acc_top1': 0.84476, 'acc_top5': 0.97008}
  • 1
  • 2
  • 3
  • 4

6、Flowers102数据集训练对比

为了公平比较CNN、Transformer与HorNet,本文借助Paddleclas在Flowers102数据集上对ResNet50vd、Swin、HorNet进行对比

#解压数据集
!mkdir data/flowers
!tar -xf ~/data/data19852/flowers102.tar -C ~/data/flowers
  • 1
  • 2
  • 3
[]
  • 1
%cd PaddleClas/
  • 1
/home/aistudio/PaddleClas
  • 1
#安装必要库
!pip install -r requirements.txt
  • 1
  • 2

首先进行HorNet的训练和验证

!python -m paddle.distributed.launch --gpus 0 tools/train.py -c ppcls/configs/hornet_tiny_7x7.yaml \
                                                             -o Global.pretrained_model=/home/aistudio/hornet_tiny_7x7
  • 1
  • 2
!python tools/eval.py -c ppcls/configs/hornet_tiny_7x7.yaml -o Global.pretrained_model=output/hornet_tiny_7x7/best_model
  • 1
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/matplotlib/__init__.py:107: 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 MutableMapping
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/matplotlib/rcsetup.py:20: 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 Iterable, Mapping
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/matplotlib/colors.py:53: 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 Sized
[2022/08/01 17:19:29] ppcls INFO: 
===========================================================
==        PaddleClas is powered by PaddlePaddle !        ==
===========================================================
==                                                       ==
==   For more info please go to the following website.   ==
==                                                       ==
==       https://github.com/PaddlePaddle/PaddleClas      ==
===========================================================

[2022/08/01 17:19:29] ppcls INFO: Arch : 
[2022/08/01 17:19:29] ppcls INFO:     class_num : 102
[2022/08/01 17:19:29] ppcls INFO:     drop_path_rate : 0.2
[2022/08/01 17:19:29] ppcls INFO:     head_init_scale : 1.0
[2022/08/01 17:19:29] ppcls INFO:     layer_scale_init_value : 1e-06
[2022/08/01 17:19:29] ppcls INFO:     name : hornet_tiny_7x7
[2022/08/01 17:19:29] ppcls INFO: DataLoader : 
[2022/08/01 17:19:29] ppcls INFO:     Eval : 
[2022/08/01 17:19:29] ppcls INFO:         dataset : 
[2022/08/01 17:19:29] ppcls INFO:             cls_label_path : /home/aistudio/data/flowers/oxford-102-flowers/oxford-102-flowers/valid.txt
[2022/08/01 17:19:29] ppcls INFO:             image_root : /home/aistudio/data/flowers/oxford-102-flowers/oxford-102-flowers
[2022/08/01 17:19:29] ppcls INFO:             name : ImageNetDataset
[2022/08/01 17:19:29] ppcls INFO:             transform_ops : 
[2022/08/01 17:19:29] ppcls INFO:                 DecodeImage : 
[2022/08/01 17:19:29] ppcls INFO:                     channel_first : False
[2022/08/01 17:19:29] ppcls INFO:                     to_rgb : True
[2022/08/01 17:19:29] ppcls INFO:                 ResizeImage : 
[2022/08/01 17:19:29] ppcls INFO:                     backend : pil
[2022/08/01 17:19:29] ppcls INFO:                     interpolation : bicubic
[2022/08/01 17:19:29] ppcls INFO:                     resize_short : 256
[2022/08/01 17:19:29] ppcls INFO:                 CropImage : 
[2022/08/01 17:19:29] ppcls INFO:                     size : 224
[2022/08/01 17:19:29] ppcls INFO:                 NormalizeImage : 
[2022/08/01 17:19:29] ppcls INFO:                     mean : [0.485, 0.456, 0.406]
[2022/08/01 17:19:29] ppcls INFO:                     order : 
[2022/08/01 17:19:29] ppcls INFO:                     scale : 1.0/255.0
[2022/08/01 17:19:29] ppcls INFO:                     std : [0.229, 0.224, 0.225]
[2022/08/01 17:19:29] ppcls INFO:         loader : 
[2022/08/01 17:19:29] ppcls INFO:             num_workers : 4
[2022/08/01 17:19:29] ppcls INFO:             use_shared_memory : True
[2022/08/01 17:19:29] ppcls INFO:         sampler : 
[2022/08/01 17:19:29] ppcls INFO:             batch_size : 128
[2022/08/01 17:19:29] ppcls INFO:             drop_last : False
[2022/08/01 17:19:29] ppcls INFO:             name : DistributedBatchSampler
[2022/08/01 17:19:29] ppcls INFO:             shuffle : False
[2022/08/01 17:19:29] ppcls INFO:     Train : 
[2022/08/01 17:19:29] ppcls INFO:         dataset : 
[2022/08/01 17:19:29] ppcls INFO:             batch_transform_ops : 
[2022/08/01 17:19:29] ppcls INFO:                 OpSampler : 
[2022/08/01 17:19:29] ppcls INFO:                     CutmixOperator : 
[2022/08/01 17:19:29] ppcls INFO:                         alpha : 1.0
[2022/08/01 17:19:29] ppcls INFO:                         prob : 0.5
[2022/08/01 17:19:29] ppcls INFO:                     MixupOperator : 
[2022/08/01 17:19:29] ppcls INFO:                         alpha : 0.8
[2022/08/01 17:19:29] ppcls INFO:                         prob : 0.5
[2022/08/01 17:19:29] ppcls INFO:             cls_label_path : /home/aistudio/data/flowers/oxford-102-flowers/oxford-102-flowers/train.txt
[2022/08/01 17:19:29] ppcls INFO:             image_root : /home/aistudio/data/flowers/oxford-102-flowers/oxford-102-flowers
[2022/08/01 17:19:29] ppcls INFO:             name : ImageNetDataset
[2022/08/01 17:19:29] ppcls INFO:             transform_ops : 
[2022/08/01 17:19:29] ppcls INFO:                 DecodeImage : 
[2022/08/01 17:19:29] ppcls INFO:                     channel_first : False
[2022/08/01 17:19:29] ppcls INFO:                     to_rgb : True
[2022/08/01 17:19:29] ppcls INFO:                 RandCropImage : 
[2022/08/01 17:19:29] ppcls INFO:                     backend : pil
[2022/08/01 17:19:29] ppcls INFO:                     interpolation : bicubic
[2022/08/01 17:19:29] ppcls INFO:                     size : 224
[2022/08/01 17:19:29] ppcls INFO:                 RandFlipImage : 
[2022/08/01 17:19:29] ppcls INFO:                     flip_code : 1
[2022/08/01 17:19:29] ppcls INFO:                 TimmAutoAugment : 
[2022/08/01 17:19:29] ppcls INFO:                     config_str : rand-m9-mstd0.5-inc1
[2022/08/01 17:19:29] ppcls INFO:                     img_size : 224
[2022/08/01 17:19:29] ppcls INFO:                     interpolation : bicubic
[2022/08/01 17:19:29] ppcls INFO:                 NormalizeImage : 
[2022/08/01 17:19:29] ppcls INFO:                     mean : [0.485, 0.456, 0.406]
[2022/08/01 17:19:29] ppcls INFO:                     order : 
[2022/08/01 17:19:29] ppcls INFO:                     scale : 1.0/255.0
[2022/08/01 17:19:29] ppcls INFO:                     std : [0.229, 0.224, 0.225]
[2022/08/01 17:19:29] ppcls INFO:                 RandomErasing : 
[2022/08/01 17:19:29] ppcls INFO:                     EPSILON : 0.25
[2022/08/01 17:19:29] ppcls INFO: ------------------------------------------------------------
[2022/08/01 17:19:29] ppcls INFO:                     attempt : 10
[2022/08/01 17:19:29] ppcls INFO:                     mode : pixel
[2022/08/01 17:19:29] ppcls INFO:                     r1 : 0.3
[2022/08/01 17:19:29] ppcls INFO:                     sh : 1.0/3.0
[2022/08/01 17:19:29] ppcls INFO:                     sl : 0.02
[2022/08/01 17:19:29] ppcls INFO:                     use_log_aspect : True
[2022/08/01 17:19:29] ppcls INFO:         loader : 
[2022/08/01 17:19:29] ppcls INFO:             num_workers : 4
[2022/08/01 17:19:29] ppcls INFO:             use_shared_memory : True
[2022/08/01 17:19:29] ppcls INFO:         sampler : 
[2022/08/01 17:19:29] ppcls INFO:             batch_size : 32
[2022/08/01 17:19:29] ppcls INFO:             drop_last : False
[2022/08/01 17:19:29] ppcls INFO:             name : DistributedBatchSampler
[2022/08/01 17:19:29] ppcls INFO:             shuffle : True
[2022/08/01 17:19:29] ppcls INFO: EMA : 
[2022/08/01 17:19:29] ppcls INFO:     decay : 0.9999
[2022/08/01 17:19:29] ppcls INFO: ------------------------------------------------------------
[2022/08/01 17:19:29] ppcls INFO: Global : 
[2022/08/01 17:19:29] ppcls INFO:     checkpoints : None
[2022/08/01 17:19:29] ppcls INFO:     device : gpu
[2022/08/01 17:19:29] ppcls INFO:     epochs : 50
[2022/08/01 17:19:29] ppcls INFO:     eval_during_train : True
[2022/08/01 17:19:29] ppcls INFO:     eval_interval : 1
[2022/08/01 17:19:29] ppcls INFO:     image_shape : [3, 224, 224]
[2022/08/01 17:19:29] ppcls INFO:     output_dir : ./output/
[2022/08/01 17:19:29] ppcls INFO:     pretrained_model : output/hornet_tiny_7x7/best_model
[2022/08/01 17:19:29] ppcls INFO:     print_batch_step : 10
[2022/08/01 17:19:29] ppcls INFO:     save_inference_dir : ./inference
[2022/08/01 17:19:29] ppcls INFO:     save_interval : 1
[2022/08/01 17:19:29] ppcls INFO:     update_freq : 4
[2022/08/01 17:19:29] ppcls INFO:     use_visualdl : False
[2022/08/01 17:19:29] ppcls INFO: Infer : 
[2022/08/01 17:19:29] ppcls INFO:     PostProcess : 
[2022/08/01 17:19:29] ppcls INFO:         class_id_map_file : ./dataset/flowers102/flowers102_label_list.txt
[2022/08/01 17:19:29] ppcls INFO:         name : Topk
[2022/08/01 17:19:29] ppcls INFO:         topk : 5
[2022/08/01 17:19:29] ppcls INFO:     batch_size : 10
[2022/08/01 17:19:29] ppcls INFO:     infer_imgs : docs/images/inference_deployment/whl_demo.jpg
[2022/08/01 17:19:29] ppcls INFO:     transforms : 
[2022/08/01 17:19:29] ppcls INFO:         DecodeImage : 
[2022/08/01 17:19:29] ppcls INFO:             channel_first : False
[2022/08/01 17:19:29] ppcls INFO:             to_rgb : True
[2022/08/01 17:19:29] ppcls INFO:         ResizeImage : 
[2022/08/01 17:19:29] ppcls INFO:             resize_short : 256
[2022/08/01 17:19:29] ppcls INFO:         CropImage : 
[2022/08/01 17:19:29] ppcls INFO:             size : 224
[2022/08/01 17:19:29] ppcls INFO:         NormalizeImage : 
[2022/08/01 17:19:29] ppcls INFO:             mean : [0.485, 0.456, 0.406]
[2022/08/01 17:19:29] ppcls INFO:             order : 
[2022/08/01 17:19:29] ppcls INFO:             scale : 1.0/255.0
[2022/08/01 17:19:29] ppcls INFO:             std : [0.229, 0.224, 0.225]
[2022/08/01 17:19:29] ppcls INFO:         ToCHWImage : None
[2022/08/01 17:19:29] ppcls INFO: Loss : 
[2022/08/01 17:19:29] ppcls INFO:     Eval : 
[2022/08/01 17:19:29] ppcls INFO:         CELoss : 
[2022/08/01 17:19:29] ppcls INFO:             weight : 1.0
[2022/08/01 17:19:29] ppcls INFO:     Train : 
[2022/08/01 17:19:29] ppcls INFO:         CELoss : 
[2022/08/01 17:19:29] ppcls INFO:             weight : 1.0
[2022/08/01 17:19:29] ppcls INFO: Metric : 
[2022/08/01 17:19:29] ppcls INFO:     Eval : 
[2022/08/01 17:19:29] ppcls INFO:         TopkAcc : 
[2022/08/01 17:19:29] ppcls INFO:             topk : [1, 5]
[2022/08/01 17:19:29] ppcls INFO:     Train : 
[2022/08/01 17:19:29] ppcls INFO:         TopkAcc : 
[2022/08/01 17:19:29] ppcls INFO:             topk : [1, 5]
[2022/08/01 17:19:29] ppcls INFO: Optimizer : 
[2022/08/01 17:19:29] ppcls INFO:     beta1 : 0.9
[2022/08/01 17:19:29] ppcls INFO:     beta2 : 0.999
[2022/08/01 17:19:29] ppcls INFO:     epsilon : 1e-08
[2022/08/01 17:19:29] ppcls INFO:     lr : 
[2022/08/01 17:19:29] ppcls INFO:         eta_min : 1e-06
[2022/08/01 17:19:29] ppcls INFO:         learning_rate : 0.0005
[2022/08/01 17:19:29] ppcls INFO:         name : Cosine
[2022/08/01 17:19:29] ppcls INFO:         warmup_epoch : 5
[2022/08/01 17:19:29] ppcls INFO:         warmup_start_lr : 0
[2022/08/01 17:19:29] ppcls INFO:     name : AdamW
[2022/08/01 17:19:29] ppcls INFO:     one_dim_param_no_weight_decay : True
[2022/08/01 17:19:29] ppcls INFO:     weight_decay : 0.05
[2022/08/01 17:19:29] ppcls INFO: train with paddle 2.3.1 and device Place(gpu:0)
W0801 17:19:29.716073 14503 gpu_resources.cc:61] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 11.2, Runtime API Version: 10.1
W0801 17:19:29.721376 14503 gpu_resources.cc:91] device: 0, cuDNN Version: 7.6.
+++++++
[2022/08/01 17:19:36] ppcls INFO: [Eval][Epoch 0][Iter: 0/8]CELoss: 3.77862, loss: 3.77862, top1: 0.95312, top5: 0.99219, batch_cost: 5.59765s, reader_cost: 3.28722, ips: 22.86673 images/sec
[2022/08/01 17:19:38] ppcls INFO: [Eval][Epoch 0][Avg]CELoss: 3.75967, loss: 3.75967, top1: 0.96961, top5: 0.99314
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171

接着是ResNet50vd的训练和验证

!python -m paddle.distributed.launch --gpus 0 tools/train.py -c ppcls/configs/resnet50.yaml \
                                                             -o Global.pretrained_model=https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/legendary_models/ResNet50_vd_pretrained.pdparams
  • 1
  • 2
!python tools/eval.py -c ppcls/configs/resnet50.yaml -o Global.pretrained_model=output/ResNet50_vd/best_model
  • 1
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/matplotlib/__init__.py:107: 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 MutableMapping
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/matplotlib/rcsetup.py:20: 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 Iterable, Mapping
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/matplotlib/colors.py:53: 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 Sized
[2022/08/01 17:29:21] ppcls INFO: 
===========================================================
==        PaddleClas is powered by PaddlePaddle !        ==
===========================================================
==                                                       ==
==   For more info please go to the following website.   ==
==                                                       ==
==       https://github.com/PaddlePaddle/PaddleClas      ==
===========================================================

[2022/08/01 17:29:21] ppcls INFO: Arch : 
[2022/08/01 17:29:21] ppcls INFO:     class_num : 102
[2022/08/01 17:29:21] ppcls INFO:     name : ResNet50_vd
[2022/08/01 17:29:21] ppcls INFO: DataLoader : 
[2022/08/01 17:29:21] ppcls INFO:     Eval : 
[2022/08/01 17:29:21] ppcls INFO:         dataset : 
[2022/08/01 17:29:21] ppcls INFO:             cls_label_path : /home/aistudio/data/flowers/oxford-102-flowers/oxford-102-flowers/valid.txt
[2022/08/01 17:29:21] ppcls INFO:             image_root : /home/aistudio/data/flowers/oxford-102-flowers/oxford-102-flowers
[2022/08/01 17:29:21] ppcls INFO:             name : ImageNetDataset
[2022/08/01 17:29:21] ppcls INFO:             transform_ops : 
[2022/08/01 17:29:21] ppcls INFO:                 DecodeImage : 
[2022/08/01 17:29:21] ppcls INFO:                     channel_first : False
[2022/08/01 17:29:21] ppcls INFO:                     to_rgb : True
[2022/08/01 17:29:21] ppcls INFO:                 ResizeImage : 
[2022/08/01 17:29:21] ppcls INFO:                     resize_short : 256
[2022/08/01 17:29:21] ppcls INFO:                 CropImage : 
[2022/08/01 17:29:21] ppcls INFO:                     size : 224
[2022/08/01 17:29:21] ppcls INFO:                 NormalizeImage : 
[2022/08/01 17:29:21] ppcls INFO:                     mean : [0.485, 0.456, 0.406]
[2022/08/01 17:29:21] ppcls INFO:                     order : 
[2022/08/01 17:29:21] ppcls INFO:                     scale : 1.0/255.0
[2022/08/01 17:29:21] ppcls INFO:                     std : [0.229, 0.224, 0.225]
[2022/08/01 17:29:21] ppcls INFO:         loader : 
[2022/08/01 17:29:21] ppcls INFO:             num_workers : 4
[2022/08/01 17:29:21] ppcls INFO:             use_shared_memory : True
[2022/08/01 17:29:21] ppcls INFO:         sampler : 
[2022/08/01 17:29:21] ppcls INFO:             batch_size : 128
[2022/08/01 17:29:21] ppcls INFO:             drop_last : False
[2022/08/01 17:29:21] ppcls INFO:             name : DistributedBatchSampler
[2022/08/01 17:29:21] ppcls INFO:             shuffle : False
[2022/08/01 17:29:21] ppcls INFO:     Train : 
[2022/08/01 17:29:21] ppcls INFO:         dataset : 
[2022/08/01 17:29:21] ppcls INFO:             cls_label_path : /home/aistudio/data/flowers/oxford-102-flowers/oxford-102-flowers/train.txt
[2022/08/01 17:29:21] ppcls INFO:             image_root : /home/aistudio/data/flowers/oxford-102-flowers/oxford-102-flowers
[2022/08/01 17:29:21] ppcls INFO:             name : ImageNetDataset
[2022/08/01 17:29:21] ppcls INFO:             transform_ops : 
[2022/08/01 17:29:21] ppcls INFO:                 DecodeImage : 
[2022/08/01 17:29:21] ppcls INFO:                     channel_first : False
[2022/08/01 17:29:21] ppcls INFO:                     to_rgb : True
[2022/08/01 17:29:21] ppcls INFO:                 RandCropImage : 
[2022/08/01 17:29:21] ppcls INFO:                     size : 224
[2022/08/01 17:29:21] ppcls INFO:                 RandFlipImage : 
[2022/08/01 17:29:21] ppcls INFO:                     flip_code : 1
[2022/08/01 17:29:21] ppcls INFO:                 NormalizeImage : 
[2022/08/01 17:29:21] ppcls INFO:                     mean : [0.485, 0.456, 0.406]
[2022/08/01 17:29:21] ppcls INFO:                     order : 
[2022/08/01 17:29:21] ppcls INFO:                     scale : 1.0/255.0
[2022/08/01 17:29:21] ppcls INFO:                     std : [0.229, 0.224, 0.225]
[2022/08/01 17:29:21] ppcls INFO:         loader : 
[2022/08/01 17:29:21] ppcls INFO:             num_workers : 4
[2022/08/01 17:29:21] ppcls INFO:             use_shared_memory : True
[2022/08/01 17:29:21] ppcls INFO:         sampler : 
[2022/08/01 17:29:21] ppcls INFO:             batch_size : 32
[2022/08/01 17:29:21] ppcls INFO:             drop_last : False
[2022/08/01 17:29:21] ppcls INFO:             name : DistributedBatchSampler
[2022/08/01 17:29:21] ppcls INFO:             shuffle : True
[2022/08/01 17:29:21] ppcls INFO: Global : 
[2022/08/01 17:29:21] ppcls INFO:     checkpoints : None
[2022/08/01 17:29:21] ppcls INFO:     device : gpu
[2022/08/01 17:29:21] ppcls INFO:     epochs : 50
[2022/08/01 17:29:21] ppcls INFO:     eval_during_train : True
[2022/08/01 17:29:21] ppcls INFO:     eval_interval : 1
[2022/08/01 17:29:21] ppcls INFO:     image_shape : [3, 224, 224]
[2022/08/01 17:29:21] ppcls INFO:     output_dir : ./output/
[2022/08/01 17:29:21] ppcls INFO:     pretrained_model : output/ResNet50_vd/best_model
[2022/08/01 17:29:21] ppcls INFO:     print_batch_step : 10
[2022/08/01 17:29:21] ppcls INFO:     save_inference_dir : ./inference
[2022/08/01 17:29:21] ppcls INFO:     save_interval : 1
[2022/08/01 17:29:21] ppcls INFO:     use_visualdl : False
[2022/08/01 17:29:21] ppcls INFO: Infer : 
[2022/08/01 17:29:21] ppcls INFO:     PostProcess : 
[2022/08/01 17:29:21] ppcls INFO:         class_id_map_file : ./dataset/flowers102/flowers102_label_list.txt
[2022/08/01 17:29:21] ppcls INFO:         name : Topk
[2022/08/01 17:29:21] ppcls INFO:         topk : 5
[2022/08/01 17:29:21] ppcls INFO:     batch_size : 10
[2022/08/01 17:29:21] ppcls INFO:     infer_imgs : docs/images/inference_deployment/whl_demo.jpg
[2022/08/01 17:29:21] ppcls INFO:     transforms : 
[2022/08/01 17:29:21] ppcls INFO:         DecodeImage : 
[2022/08/01 17:29:21] ppcls INFO:             channel_first : False
[2022/08/01 17:29:21] ppcls INFO:             to_rgb : True
[2022/08/01 17:29:21] ppcls INFO:         ResizeImage : 
[2022/08/01 17:29:21] ppcls INFO:             resize_short : 256
[2022/08/01 17:29:21] ppcls INFO:         CropImage : 
[2022/08/01 17:29:21] ppcls INFO:             size : 224
[2022/08/01 17:29:21] ppcls INFO:         NormalizeImage : 
[2022/08/01 17:29:21] ppcls INFO:             mean : [0.485, 0.456, 0.406]
[2022/08/01 17:29:21] ppcls INFO:             order : 
[2022/08/01 17:29:21] ppcls INFO:             scale : 1.0/255.0
[2022/08/01 17:29:21] ppcls INFO:             std : [0.229, 0.224, 0.225]
[2022/08/01 17:29:21] ppcls INFO:         ToCHWImage : None
[2022/08/01 17:29:21] ppcls INFO: Loss : 
[2022/08/01 17:29:21] ppcls INFO:     Eval : 
[2022/08/01 17:29:21] ppcls INFO:         CELoss : 
[2022/08/01 17:29:21] ppcls INFO:             weight : 1.0
[2022/08/01 17:29:21] ppcls INFO:     Train : 
[2022/08/01 17:29:21] ppcls INFO:         CELoss : 
[2022/08/01 17:29:21] ppcls INFO:             weight : 1.0
[2022/08/01 17:29:21] ppcls INFO: Metric : 
[2022/08/01 17:29:21] ppcls INFO:     Eval : 
[2022/08/01 17:29:21] ppcls INFO:         TopkAcc : 
[2022/08/01 17:29:21] ppcls INFO:             topk : [1, 5]
[2022/08/01 17:29:21] ppcls INFO:     Train : 
[2022/08/01 17:29:21] ppcls INFO:         TopkAcc : 
[2022/08/01 17:29:21] ppcls INFO:             topk : [1, 5]
[2022/08/01 17:29:21] ppcls INFO: Optimizer : 
[2022/08/01 17:29:21] ppcls INFO:     lr : 
[2022/08/01 17:29:21] ppcls INFO:         learning_rate : 0.0125
[2022/08/01 17:29:21] ppcls INFO:         name : Cosine
[2022/08/01 17:29:21] ppcls INFO:         warmup_epoch : 5
[2022/08/01 17:29:21] ppcls INFO:     momentum : 0.9
[2022/08/01 17:29:21] ppcls INFO:     name : Momentum
[2022/08/01 17:29:21] ppcls INFO:     regularizer : 
[2022/08/01 17:29:21] ppcls INFO:         coeff : 1e-05
[2022/08/01 17:29:21] ppcls INFO:         name : L2
[2022/08/01 17:29:21] ppcls INFO: train with paddle 2.3.1 and device Place(gpu:0)
W0801 17:29:21.801292 22024 gpu_resources.cc:61] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 11.2, Runtime API Version: 10.1
W0801 17:29:21.806051 22024 gpu_resources.cc:91] device: 0, cuDNN Version: 7.6.
+++++++
[2022/08/01 17:29:26] ppcls INFO: [Eval][Epoch 0][Iter: 0/8]CELoss: 0.32419, loss: 0.32419, top1: 0.92188, top5: 0.96875, batch_cost: 3.66914s, reader_cost: 1.63267, ips: 34.88556 images/sec
[2022/08/01 17:29:27] ppcls INFO: [Eval][Epoch 0][Avg]CELoss: 0.21094, loss: 0.21094, top1: 0.95588, top5: 0.98529
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136

最后是Swin的验证

!python -m paddle.distributed.launch --gpus 0 tools/train.py -c ppcls/configs/swin.yaml \
thon -m paddle.distributed.launch --gpus 0 tools/train.py -c ppcls/configs/swin.yaml \
                                                             -o Global.pretrained_model=https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/SwinTransformer_tiny_patch4_window7_224_pretrained.pdparams
  • 1
  • 2
  • 3
!python tools/eval.py -c ppcls/configs/swin.yaml -o Global.pretrained_model=output/SwinTransformer_tiny_patch4_window7_224/best_model
  • 1
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/matplotlib/__init__.py:107: 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 MutableMapping
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/matplotlib/rcsetup.py:20: 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 Iterable, Mapping
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/matplotlib/colors.py:53: 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 Sized
[2022/08/01 17:51:34] ppcls INFO: 
===========================================================
==        PaddleClas is powered by PaddlePaddle !        ==
===========================================================
==                                                       ==
==   For more info please go to the following website.   ==
==                                                       ==
==       https://github.com/PaddlePaddle/PaddleClas      ==
===========================================================

[2022/08/01 17:51:34] ppcls INFO: Arch : 
[2022/08/01 17:51:34] ppcls INFO:     class_num : 102
[2022/08/01 17:51:34] ppcls INFO:     name : SwinTransformer_tiny_patch4_window7_224
[2022/08/01 17:51:34] ppcls INFO: DataLoader : 
[2022/08/01 17:51:34] ppcls INFO:     Eval : 
[2022/08/01 17:51:34] ppcls INFO:         dataset : 
[2022/08/01 17:51:34] ppcls INFO:             cls_label_path : /home/aistudio/data/flowers/oxford-102-flowers/oxford-102-flowers/valid.txt
[2022/08/01 17:51:34] ppcls INFO:             image_root : /home/aistudio/data/flowers/oxford-102-flowers/oxford-102-flowers
[2022/08/01 17:51:34] ppcls INFO:             name : ImageNetDataset
[2022/08/01 17:51:34] ppcls INFO:             transform_ops : 
[2022/08/01 17:51:34] ppcls INFO:                 DecodeImage : 
[2022/08/01 17:51:34] ppcls INFO:                     channel_first : False
[2022/08/01 17:51:34] ppcls INFO:                     to_rgb : True
[2022/08/01 17:51:34] ppcls INFO:                 ResizeImage : 
[2022/08/01 17:51:34] ppcls INFO:                     backend : pil
[2022/08/01 17:51:34] ppcls INFO:                     interpolation : bicubic
[2022/08/01 17:51:34] ppcls INFO:                     resize_short : 256
[2022/08/01 17:51:34] ppcls INFO:                 CropImage : 
[2022/08/01 17:51:34] ppcls INFO:                     size : 224
[2022/08/01 17:51:34] ppcls INFO:                 NormalizeImage : 
[2022/08/01 17:51:34] ppcls INFO:                     mean : [0.485, 0.456, 0.406]
[2022/08/01 17:51:34] ppcls INFO:                     order : 
[2022/08/01 17:51:34] ppcls INFO:                     scale : 1.0/255.0
[2022/08/01 17:51:34] ppcls INFO:                     std : [0.229, 0.224, 0.225]
[2022/08/01 17:51:34] ppcls INFO:         loader : 
[2022/08/01 17:51:34] ppcls INFO:             num_workers : 4
[2022/08/01 17:51:34] ppcls INFO:             use_shared_memory : True
[2022/08/01 17:51:34] ppcls INFO:         sampler : 
[2022/08/01 17:51:34] ppcls INFO:             batch_size : 128
[2022/08/01 17:51:34] ppcls INFO:             drop_last : False
[2022/08/01 17:51:34] ppcls INFO:             name : DistributedBatchSampler
[2022/08/01 17:51:34] ppcls INFO:             shuffle : False
[2022/08/01 17:51:34] ppcls INFO:     Train : 
[2022/08/01 17:51:34] ppcls INFO:         dataset : 
[2022/08/01 17:51:34] ppcls INFO:             batch_transform_ops : 
[2022/08/01 17:51:34] ppcls INFO:                 OpSampler : 
[2022/08/01 17:51:34] ppcls INFO:                     CutmixOperator : 
[2022/08/01 17:51:34] ppcls INFO:                         alpha : 1.0
[2022/08/01 17:51:34] ppcls INFO:                         prob : 0.5
[2022/08/01 17:51:34] ppcls INFO:                     MixupOperator : 
[2022/08/01 17:51:34] ppcls INFO:                         alpha : 0.8
[2022/08/01 17:51:34] ppcls INFO:                         prob : 0.5
[2022/08/01 17:51:34] ppcls INFO:             cls_label_path : /home/aistudio/data/flowers/oxford-102-flowers/oxford-102-flowers/train.txt
[2022/08/01 17:51:34] ppcls INFO:             image_root : /home/aistudio/data/flowers/oxford-102-flowers/oxford-102-flowers
[2022/08/01 17:51:34] ppcls INFO:             name : ImageNetDataset
[2022/08/01 17:51:34] ppcls INFO:             transform_ops : 
[2022/08/01 17:51:34] ppcls INFO:                 DecodeImage : 
[2022/08/01 17:51:34] ppcls INFO:                     channel_first : False
[2022/08/01 17:51:34] ppcls INFO:                     to_rgb : True
[2022/08/01 17:51:34] ppcls INFO:                 RandCropImage : 
[2022/08/01 17:51:34] ppcls INFO:                     backend : pil
[2022/08/01 17:51:34] ppcls INFO:                     interpolation : bicubic
[2022/08/01 17:51:34] ppcls INFO:                     size : 224
[2022/08/01 17:51:34] ppcls INFO:                 RandFlipImage : 
[2022/08/01 17:51:34] ppcls INFO:                     flip_code : 1
[2022/08/01 17:51:34] ppcls INFO:                 TimmAutoAugment : 
[2022/08/01 17:51:34] ppcls INFO:                     config_str : rand-m9-mstd0.5-inc1
[2022/08/01 17:51:34] ppcls INFO:                     img_size : 224
[2022/08/01 17:51:34] ppcls INFO:                     interpolation : bicubic
[2022/08/01 17:51:34] ppcls INFO:                 NormalizeImage : 
[2022/08/01 17:51:34] ppcls INFO:                     mean : [0.485, 0.456, 0.406]
[2022/08/01 17:51:34] ppcls INFO:                     order : 
[2022/08/01 17:51:34] ppcls INFO:                     scale : 1.0/255.0
[2022/08/01 17:51:34] ppcls INFO:                     std : [0.229, 0.224, 0.225]
[2022/08/01 17:51:34] ppcls INFO:                 RandomErasing : 
[2022/08/01 17:51:34] ppcls INFO:                     EPSILON : 0.25
[2022/08/01 17:51:34] ppcls INFO: ------------------------------------------------------------
[2022/08/01 17:51:34] ppcls INFO:                     attempt : 10
[2022/08/01 17:51:34] ppcls INFO:                     mode : pixel
[2022/08/01 17:51:34] ppcls INFO:                     r1 : 0.3
[2022/08/01 17:51:34] ppcls INFO:                     sh : 1.0/3.0
[2022/08/01 17:51:34] ppcls INFO:                     sl : 0.02
[2022/08/01 17:51:34] ppcls INFO:                     use_log_aspect : True
[2022/08/01 17:51:34] ppcls INFO:         loader : 
[2022/08/01 17:51:34] ppcls INFO:             num_workers : 4
[2022/08/01 17:51:34] ppcls INFO:             use_shared_memory : True
[2022/08/01 17:51:34] ppcls INFO:         sampler : 
[2022/08/01 17:51:34] ppcls INFO:             batch_size : 32
[2022/08/01 17:51:34] ppcls INFO:             drop_last : False
[2022/08/01 17:51:34] ppcls INFO:             name : DistributedBatchSampler
[2022/08/01 17:51:34] ppcls INFO:             shuffle : True
[2022/08/01 17:51:34] ppcls INFO: Global : 
[2022/08/01 17:51:34] ppcls INFO:     checkpoints : None
[2022/08/01 17:51:34] ppcls INFO:     device : gpu
[2022/08/01 17:51:34] ppcls INFO:     epochs : 50
[2022/08/01 17:51:34] ppcls INFO:     eval_during_train : True
[2022/08/01 17:51:34] ppcls INFO:     eval_interval : 1
[2022/08/01 17:51:34] ppcls INFO:     image_shape : [3, 224, 224]
[2022/08/01 17:51:34] ppcls INFO:     output_dir : ./output/
[2022/08/01 17:51:34] ppcls INFO:     pretrained_model : output/SwinTransformer_tiny_patch4_window7_224/best_model
[2022/08/01 17:51:34] ppcls INFO:     print_batch_step : 10
[2022/08/01 17:51:34] ppcls INFO:     save_inference_dir : ./inference
[2022/08/01 17:51:34] ppcls INFO:     save_interval : 1
[2022/08/01 17:51:34] ppcls INFO:     to_static : False
[2022/08/01 17:51:34] ppcls INFO:     use_visualdl : False
[2022/08/01 17:51:34] ppcls INFO: Infer : 
[2022/08/01 17:51:34] ppcls INFO:     PostProcess : 
[2022/08/01 17:51:34] ppcls INFO:         class_id_map_file : ppcls/utils/imagenet1k_label_list.txt
[2022/08/01 17:51:34] ppcls INFO:         name : Topk
[2022/08/01 17:51:34] ppcls INFO:         topk : 5
[2022/08/01 17:51:34] ppcls INFO:     batch_size : 10
[2022/08/01 17:51:34] ppcls INFO:     infer_imgs : docs/images/inference_deployment/whl_demo.jpg
[2022/08/01 17:51:34] ppcls INFO:     transforms : 
[2022/08/01 17:51:34] ppcls INFO:         DecodeImage : 
[2022/08/01 17:51:34] ppcls INFO:             channel_first : False
[2022/08/01 17:51:34] ppcls INFO:             to_rgb : True
[2022/08/01 17:51:34] ppcls INFO:         ResizeImage : 
[2022/08/01 17:51:34] ppcls INFO:             backend : pil
[2022/08/01 17:51:34] ppcls INFO:             interpolation : bicubic
[2022/08/01 17:51:34] ppcls INFO:             resize_short : 256
[2022/08/01 17:51:34] ppcls INFO:         CropImage : 
[2022/08/01 17:51:34] ppcls INFO:             size : 224
[2022/08/01 17:51:34] ppcls INFO:         NormalizeImage : 
[2022/08/01 17:51:34] ppcls INFO:             mean : [0.485, 0.456, 0.406]
[2022/08/01 17:51:34] ppcls INFO:             order : 
[2022/08/01 17:51:34] ppcls INFO:             scale : 1.0/255.0
[2022/08/01 17:51:34] ppcls INFO:             std : [0.229, 0.224, 0.225]
[2022/08/01 17:51:34] ppcls INFO:         ToCHWImage : None
[2022/08/01 17:51:34] ppcls INFO: Loss : 
[2022/08/01 17:51:34] ppcls INFO:     Eval : 
[2022/08/01 17:51:34] ppcls INFO:         CELoss : 
[2022/08/01 17:51:34] ppcls INFO:             weight : 1.0
[2022/08/01 17:51:34] ppcls INFO:     Train : 
[2022/08/01 17:51:34] ppcls INFO:         CELoss : 
[2022/08/01 17:51:34] ppcls INFO:             epsilon : 0.1
[2022/08/01 17:51:34] ppcls INFO:             weight : 1.0
[2022/08/01 17:51:34] ppcls INFO: Metric : 
[2022/08/01 17:51:34] ppcls INFO:     Eval : 
[2022/08/01 17:51:34] ppcls INFO:         TopkAcc : 
[2022/08/01 17:51:34] ppcls INFO:             topk : [1, 5]
[2022/08/01 17:51:34] ppcls INFO: Optimizer : 
[2022/08/01 17:51:34] ppcls INFO:     beta1 : 0.9
[2022/08/01 17:51:34] ppcls INFO:     beta2 : 0.999
[2022/08/01 17:51:34] ppcls INFO:     epsilon : 1e-08
[2022/08/01 17:51:34] ppcls INFO:     lr : 
[2022/08/01 17:51:34] ppcls INFO:         eta_min : 2e-05
[2022/08/01 17:51:34] ppcls INFO:         learning_rate : 1.25e-05
[2022/08/01 17:51:34] ppcls INFO:         name : Cosine
[2022/08/01 17:51:34] ppcls INFO:         warmup_epoch : 5
[2022/08/01 17:51:34] ppcls INFO:         warmup_start_lr : 2e-06
[2022/08/01 17:51:34] ppcls INFO:     name : AdamW
[2022/08/01 17:51:34] ppcls INFO:     no_weight_decay_name : absolute_pos_embed relative_position_bias_table .bias norm
[2022/08/01 17:51:34] ppcls INFO:     one_dim_param_no_weight_decay : True
[2022/08/01 17:51:34] ppcls INFO:     weight_decay : 0.05
[2022/08/01 17:51:34] ppcls INFO: train with paddle 2.3.1 and device Place(gpu:0)
W0801 17:51:34.209131 26352 gpu_resources.cc:61] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 11.2, Runtime API Version: 10.1
W0801 17:51:34.214239 26352 gpu_resources.cc:91] device: 0, cuDNN Version: 7.6.
+++++++
[2022/08/01 17:51:41] ppcls INFO: [Eval][Epoch 0][Iter: 0/8]CELoss: 0.49065, loss: 0.49065, top1: 0.89844, top5: 0.97656, batch_cost: 5.42404s, reader_cost: 2.71487, ips: 23.59865 images/sec
[2022/08/01 17:51:42] ppcls INFO: [Eval][Epoch 0][Avg]CELoss: 0.39882, loss: 0.39882, top1: 0.94510, top5: 0.98529
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166

对比实验结果

modelVal Acc
ResNet50vd0.95588
Swin-Transformer0.94510
HorNet0.96961

从实验结果可以看出,HorNet优势还是很明显的,这也表明HorNet中模块的有效性

7、个人总结

1、提出一种新的空间交互模块,即插即用,可以助力网络涨点;

2、表明高阶空间中信息交互对信息处理更有效;

3、是一个新的思路,可以在未来进行进一步探索。


转载自:https://aistudio.baidu.com/aistudio/projectdetail/4396458

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/93977
推荐阅读
  

闽ICP备14008679号