paddle基础网络解析

项目地址

基础网络搭建解析

在这里插入图片描述

人类对图像的理解和计算机是完全不用的,计算机读取的数据是一串数字,所以理解起来会比较困难。
在这里插入图片描述
语义鸿沟,对于计算机来说,像素和区域 极为相似或者迷惑性极强的有些人类不仔细看也容易看错更何况是机器呢?
在这里插入图片描述
对于解决这些问题还需要更加努力提高机器的理解和更好的ai技术

图像识别的流程

使用机器学习(深度学习)的目的:寻找一个合适的函数
在这里插入图片描述

我们可以通过数据处理建立模型训练模型测试模型等一系类的过程得到一个比较好的结果
在这里插入图片描述

神经元

神经元来源于人的神经网络
人神经细胞结构大致可分为:树突、突触、细胞体及轴突。
单个神经细胞可被视为一种只有两种状态的机器——激动时为‘是’,而未激动时为‘否’。
刚刚好可以对应我们计算机的0和1 大量的神经元 进行堆叠 刚好可以对应神经网络
在这里插入图片描述

网络结构

网络结构分为线性,卷积等
在一个网络中上一层的输出和本层的输入必须对应
一般我们必须要考虑的是输入层和输出层至于中间的可以统一称为隐藏层

接下去我们进行举例:以输入(1,28,28)输出10为例子构建几个常见的网络

import paddle
import paddle.nn as nn
from paddle.nn import Linear
import paddle.nn.functional as F
from paddle.vision.transforms import ToTensor
# 单层线性网络
model=nn.Linear(in_features=1*28*28, out_features=10)  # 定义线性网络
paddle.summary(model, (1*28*28))
---------------------------------------------------------------------------
 Layer (type)       Input Shape          Output Shape         Param #    
===========================================================================
   Linear-3           [[784]]                [10]              7,850     
===========================================================================
Total params: 7,850
Trainable params: 7,850
Non-trainable params: 0
---------------------------------------------------------------------------
Input size (MB): 0.00
Forward/backward pass size (MB): 0.00
Params size (MB): 0.03
Estimated Total Size (MB): 0.03
---------------------------------------------------------------------------

{'total_params': 7850, 'trainable_params': 7850}
# DNN
class MyDNN(paddle.nn.Layer):
    def __init__(self):
        super(MyDNN,self).__init__()
        self.hidden1 = Linear(28,100)
        self.hidden2 = Linear(100,100)
        self.hidden3 = Linear(100,28)
        self.hidden4 = Linear(1*28*28,10)
    
    def forward(self,input):
        # print(input.shape)
        x = self.hidden1(input)
        x =F.relu(x)
        # print(x.shape)
        x = self.hidden2(x)
        x = F.relu(x)
        # print(x.shape)
        x = self.hidden3(x)
        x = F.relu(x)
        # print(x.shape)
        x = paddle.reshape(x, shape=[-1,1*28*28])  
        x = self.hidden4(x)
        y = F.softmax(x)
        # print(y.shape)
        return y

network = MyDNN()
paddle.summary(network, (1, 28, 28))  
---------------------------------------------------------------------------
 Layer (type)       Input Shape          Output Shape         Param #    
===========================================================================
   Linear-8        [[1, 28, 28]]         [1, 28, 100]          2,900     
   Linear-9        [[1, 28, 100]]        [1, 28, 100]         10,100     
   Linear-10       [[1, 28, 100]]        [1, 28, 28]           2,828     
   Linear-11         [[1, 784]]            [1, 10]             7,850     
===========================================================================
Total params: 23,678
Trainable params: 23,678
Non-trainable params: 0
---------------------------------------------------------------------------
Input size (MB): 0.00
Forward/backward pass size (MB): 0.05
Params size (MB): 0.09
Estimated Total Size (MB): 0.14
---------------------------------------------------------------------------

{'total_params': 23678, 'trainable_params': 23678}

CNN说明

参考资料
在这里插入图片描述

在这里插入图片描述在这里插入图片描述

network = nn.Sequential(
    nn.Conv2D(in_channels=1, out_channels=6, kernel_size=3, stride=1, padding=1),  # 卷积
    nn.ReLU(),  # 激活函数
    nn.MaxPool2D(kernel_size=2, stride=2),  # 最大池化
    nn.Conv2D(in_channels=6, out_channels=16, kernel_size=5, stride=1, padding=0),
    nn.ReLU(),
    nn.MaxPool2D(kernel_size=2, stride=2),
    nn.Flatten(),
    nn.Linear(in_features=400, out_features=120),  # 400 = 5x5x16,输入形状为32x32, 输入形状为28x28时调整为256
    nn.Linear(in_features=120, out_features=84),
    nn.Linear(in_features=84, out_features=10)
)
paddle.summary(network, (1, 1, 28, 28))
---------------------------------------------------------------------------
 Layer (type)       Input Shape          Output Shape         Param #    
===========================================================================
   Conv2D-12      [[1, 1, 28, 28]]      [1, 6, 28, 28]          60       
    ReLU-3        [[1, 6, 28, 28]]      [1, 6, 28, 28]           0       
  MaxPool2D-3     [[1, 6, 28, 28]]      [1, 6, 14, 14]           0       
   Conv2D-13      [[1, 6, 14, 14]]     [1, 16, 10, 10]         2,416     
    ReLU-4       [[1, 16, 10, 10]]     [1, 16, 10, 10]           0       
  MaxPool2D-4    [[1, 16, 10, 10]]      [1, 16, 5, 5]            0       
   Flatten-5      [[1, 16, 5, 5]]          [1, 400]              0       
   Linear-21         [[1, 400]]            [1, 120]           48,120     
   Linear-22         [[1, 120]]            [1, 84]            10,164     
   Linear-23         [[1, 84]]             [1, 10]              850      
===========================================================================
Total params: 61,610
Trainable params: 61,610
Non-trainable params: 0
---------------------------------------------------------------------------
Input size (MB): 0.00
Forward/backward pass size (MB): 0.11
Params size (MB): 0.24
Estimated Total Size (MB): 0.35
---------------------------------------------------------------------------

{'total_params': 61610, 'trainable_params': 61610}
# api已有网络
network = paddle.vision.models.resnet101(num_classes=10)
paddle.summary(network, (1, 3, 224, 224))
-------------------------------------------------------------------------------
   Layer (type)         Input Shape          Output Shape         Param #    
===============================================================================
    Conv2D-123       [[1, 3, 224, 224]]   [1, 64, 112, 112]        9,408     
  BatchNorm2D-105   [[1, 64, 112, 112]]   [1, 64, 112, 112]         256      
      ReLU-43       [[1, 64, 112, 112]]   [1, 64, 112, 112]          0       
    MaxPool2D-8     [[1, 64, 112, 112]]    [1, 64, 56, 56]           0       
    Conv2D-125       [[1, 64, 56, 56]]     [1, 64, 56, 56]         4,096     
  BatchNorm2D-107    [[1, 64, 56, 56]]     [1, 64, 56, 56]          256      
      ReLU-44        [[1, 256, 56, 56]]    [1, 256, 56, 56]          0       
    Conv2D-126       [[1, 64, 56, 56]]     [1, 64, 56, 56]        36,864     
  BatchNorm2D-108    [[1, 64, 56, 56]]     [1, 64, 56, 56]          256      
    Conv2D-127       [[1, 64, 56, 56]]     [1, 256, 56, 56]       16,384     
  BatchNorm2D-109    [[1, 256, 56, 56]]    [1, 256, 56, 56]        1,024     
    Conv2D-124       [[1, 64, 56, 56]]     [1, 256, 56, 56]       16,384     
  BatchNorm2D-106    [[1, 256, 56, 56]]    [1, 256, 56, 56]        1,024     
BottleneckBlock-34   [[1, 64, 56, 56]]     [1, 256, 56, 56]          0       
    Conv2D-128       [[1, 256, 56, 56]]    [1, 64, 56, 56]        16,384     
  BatchNorm2D-110    [[1, 64, 56, 56]]     [1, 64, 56, 56]          256      
      ReLU-45        [[1, 256, 56, 56]]    [1, 256, 56, 56]          0       
    Conv2D-129       [[1, 64, 56, 56]]     [1, 64, 56, 56]        36,864     
  BatchNorm2D-111    [[1, 64, 56, 56]]     [1, 64, 56, 56]          256      
    Conv2D-130       [[1, 64, 56, 56]]     [1, 256, 56, 56]       16,384     
  BatchNorm2D-112    [[1, 256, 56, 56]]    [1, 256, 56, 56]        1,024     
BottleneckBlock-35   [[1, 256, 56, 56]]    [1, 256, 56, 56]          0       
    Conv2D-131       [[1, 256, 56, 56]]    [1, 64, 56, 56]        16,384     
  BatchNorm2D-113    [[1, 64, 56, 56]]     [1, 64, 56, 56]          256      
      ReLU-46        [[1, 256, 56, 56]]    [1, 256, 56, 56]          0       
    Conv2D-132       [[1, 64, 56, 56]]     [1, 64, 56, 56]        36,864     
  BatchNorm2D-114    [[1, 64, 56, 56]]     [1, 64, 56, 56]          256      
    Conv2D-133       [[1, 64, 56, 56]]     [1, 256, 56, 56]       16,384     
  BatchNorm2D-115    [[1, 256, 56, 56]]    [1, 256, 56, 56]        1,024     
BottleneckBlock-36   [[1, 256, 56, 56]]    [1, 256, 56, 56]          0       
    Conv2D-135       [[1, 256, 56, 56]]    [1, 128, 56, 56]       32,768     
  BatchNorm2D-117    [[1, 128, 56, 56]]    [1, 128, 56, 56]         512      
      ReLU-47        [[1, 512, 28, 28]]    [1, 512, 28, 28]          0       
    Conv2D-136       [[1, 128, 56, 56]]    [1, 128, 28, 28]       147,456    
  BatchNorm2D-118    [[1, 128, 28, 28]]    [1, 128, 28, 28]         512      
    Conv2D-137       [[1, 128, 28, 28]]    [1, 512, 28, 28]       65,536     
  BatchNorm2D-119    [[1, 512, 28, 28]]    [1, 512, 28, 28]        2,048     
    Conv2D-134       [[1, 256, 56, 56]]    [1, 512, 28, 28]       131,072    
  BatchNorm2D-116    [[1, 512, 28, 28]]    [1, 512, 28, 28]        2,048     
BottleneckBlock-37   [[1, 256, 56, 56]]    [1, 512, 28, 28]          0       
    Conv2D-138       [[1, 512, 28, 28]]    [1, 128, 28, 28]       65,536     
  BatchNorm2D-120    [[1, 128, 28, 28]]    [1, 128, 28, 28]         512      
      ReLU-48        [[1, 512, 28, 28]]    [1, 512, 28, 28]          0       
    Conv2D-139       [[1, 128, 28, 28]]    [1, 128, 28, 28]       147,456    
  BatchNorm2D-121    [[1, 128, 28, 28]]    [1, 128, 28, 28]         512      
    Conv2D-140       [[1, 128, 28, 28]]    [1, 512, 28, 28]       65,536     
  BatchNorm2D-122    [[1, 512, 28, 28]]    [1, 512, 28, 28]        2,048     
BottleneckBlock-38   [[1, 512, 28, 28]]    [1, 512, 28, 28]          0       
    Conv2D-141       [[1, 512, 28, 28]]    [1, 128, 28, 28]       65,536     
  BatchNorm2D-123    [[1, 128, 28, 28]]    [1, 128, 28, 28]         512      
      ReLU-49        [[1, 512, 28, 28]]    [1, 512, 28, 28]          0       
    Conv2D-142       [[1, 128, 28, 28]]    [1, 128, 28, 28]       147,456    
  BatchNorm2D-124    [[1, 128, 28, 28]]    [1, 128, 28, 28]         512      
    Conv2D-143       [[1, 128, 28, 28]]    [1, 512, 28, 28]       65,536     
  BatchNorm2D-125    [[1, 512, 28, 28]]    [1, 512, 28, 28]        2,048     
BottleneckBlock-39   [[1, 512, 28, 28]]    [1, 512, 28, 28]          0       
    Conv2D-144       [[1, 512, 28, 28]]    [1, 128, 28, 28]       65,536     
  BatchNorm2D-126    [[1, 128, 28, 28]]    [1, 128, 28, 28]         512      
      ReLU-50        [[1, 512, 28, 28]]    [1, 512, 28, 28]          0       
    Conv2D-145       [[1, 128, 28, 28]]    [1, 128, 28, 28]       147,456    
  BatchNorm2D-127    [[1, 128, 28, 28]]    [1, 128, 28, 28]         512      
    Conv2D-146       [[1, 128, 28, 28]]    [1, 512, 28, 28]       65,536     
  BatchNorm2D-128    [[1, 512, 28, 28]]    [1, 512, 28, 28]        2,048     
BottleneckBlock-40   [[1, 512, 28, 28]]    [1, 512, 28, 28]          0       
    Conv2D-148       [[1, 512, 28, 28]]    [1, 256, 28, 28]       131,072    
  BatchNorm2D-130    [[1, 256, 28, 28]]    [1, 256, 28, 28]        1,024     
      ReLU-51       [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       
    Conv2D-149       [[1, 256, 28, 28]]    [1, 256, 14, 14]       589,824    
  BatchNorm2D-131    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     
    Conv2D-150       [[1, 256, 14, 14]]   [1, 1024, 14, 14]       262,144    
  BatchNorm2D-132   [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     
    Conv2D-147       [[1, 512, 28, 28]]   [1, 1024, 14, 14]       524,288    
  BatchNorm2D-129   [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     
BottleneckBlock-41   [[1, 512, 28, 28]]   [1, 1024, 14, 14]          0       
    Conv2D-151      [[1, 1024, 14, 14]]    [1, 256, 14, 14]       262,144    
  BatchNorm2D-133    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     
      ReLU-52       [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       
    Conv2D-152       [[1, 256, 14, 14]]    [1, 256, 14, 14]       589,824    
  BatchNorm2D-134    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     
    Conv2D-153       [[1, 256, 14, 14]]   [1, 1024, 14, 14]       262,144    
  BatchNorm2D-135   [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     
BottleneckBlock-42  [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       
    Conv2D-154      [[1, 1024, 14, 14]]    [1, 256, 14, 14]       262,144    
  BatchNorm2D-136    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     
      ReLU-53       [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       
    Conv2D-155       [[1, 256, 14, 14]]    [1, 256, 14, 14]       589,824    
  BatchNorm2D-137    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     
    Conv2D-156       [[1, 256, 14, 14]]   [1, 1024, 14, 14]       262,144    
  BatchNorm2D-138   [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     
BottleneckBlock-43  [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       
    Conv2D-157      [[1, 1024, 14, 14]]    [1, 256, 14, 14]       262,144    
  BatchNorm2D-139    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     
      ReLU-54       [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       
    Conv2D-158       [[1, 256, 14, 14]]    [1, 256, 14, 14]       589,824    
  BatchNorm2D-140    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     
    Conv2D-159       [[1, 256, 14, 14]]   [1, 1024, 14, 14]       262,144    
  BatchNorm2D-141   [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     
BottleneckBlock-44  [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       
    Conv2D-160      [[1, 1024, 14, 14]]    [1, 256, 14, 14]       262,144    
  BatchNorm2D-142    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     
      ReLU-55       [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       
    Conv2D-161       [[1, 256, 14, 14]]    [1, 256, 14, 14]       589,824    
  BatchNorm2D-143    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     
    Conv2D-162       [[1, 256, 14, 14]]   [1, 1024, 14, 14]       262,144    
  BatchNorm2D-144   [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     
BottleneckBlock-45  [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       
    Conv2D-163      [[1, 1024, 14, 14]]    [1, 256, 14, 14]       262,144    
  BatchNorm2D-145    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     
      ReLU-56       [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       
    Conv2D-164       [[1, 256, 14, 14]]    [1, 256, 14, 14]       589,824    
  BatchNorm2D-146    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     
    Conv2D-165       [[1, 256, 14, 14]]   [1, 1024, 14, 14]       262,144    
  BatchNorm2D-147   [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     
BottleneckBlock-46  [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       
    Conv2D-166      [[1, 1024, 14, 14]]    [1, 256, 14, 14]       262,144    
  BatchNorm2D-148    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     
      ReLU-57       [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       
    Conv2D-167       [[1, 256, 14, 14]]    [1, 256, 14, 14]       589,824    
  BatchNorm2D-149    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     
    Conv2D-168       [[1, 256, 14, 14]]   [1, 1024, 14, 14]       262,144    
  BatchNorm2D-150   [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     
BottleneckBlock-47  [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       
    Conv2D-169      [[1, 1024, 14, 14]]    [1, 256, 14, 14]       262,144    
  BatchNorm2D-151    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     
      ReLU-58       [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       
    Conv2D-170       [[1, 256, 14, 14]]    [1, 256, 14, 14]       589,824    
  BatchNorm2D-152    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     
    Conv2D-171       [[1, 256, 14, 14]]   [1, 1024, 14, 14]       262,144    
  BatchNorm2D-153   [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     
BottleneckBlock-48  [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       
    Conv2D-172      [[1, 1024, 14, 14]]    [1, 256, 14, 14]       262,144    
  BatchNorm2D-154    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     
      ReLU-59       [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       
    Conv2D-173       [[1, 256, 14, 14]]    [1, 256, 14, 14]       589,824    
  BatchNorm2D-155    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     
    Conv2D-174       [[1, 256, 14, 14]]   [1, 1024, 14, 14]       262,144    
  BatchNorm2D-156   [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     
BottleneckBlock-49  [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       
    Conv2D-175      [[1, 1024, 14, 14]]    [1, 256, 14, 14]       262,144    
  BatchNorm2D-157    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     
      ReLU-60       [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       
    Conv2D-176       [[1, 256, 14, 14]]    [1, 256, 14, 14]       589,824    
  BatchNorm2D-158    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     
    Conv2D-177       [[1, 256, 14, 14]]   [1, 1024, 14, 14]       262,144    
  BatchNorm2D-159   [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     
BottleneckBlock-50  [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       
    Conv2D-178      [[1, 1024, 14, 14]]    [1, 256, 14, 14]       262,144    
  BatchNorm2D-160    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     
      ReLU-61       [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       
    Conv2D-179       [[1, 256, 14, 14]]    [1, 256, 14, 14]       589,824    
  BatchNorm2D-161    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     
    Conv2D-180       [[1, 256, 14, 14]]   [1, 1024, 14, 14]       262,144    
  BatchNorm2D-162   [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     
BottleneckBlock-51  [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       
    Conv2D-181      [[1, 1024, 14, 14]]    [1, 256, 14, 14]       262,144    
  BatchNorm2D-163    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     
      ReLU-62       [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       
    Conv2D-182       [[1, 256, 14, 14]]    [1, 256, 14, 14]       589,824    
  BatchNorm2D-164    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     
    Conv2D-183       [[1, 256, 14, 14]]   [1, 1024, 14, 14]       262,144    
  BatchNorm2D-165   [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     
BottleneckBlock-52  [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       
    Conv2D-184      [[1, 1024, 14, 14]]    [1, 256, 14, 14]       262,144    
  BatchNorm2D-166    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     
      ReLU-63       [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       
    Conv2D-185       [[1, 256, 14, 14]]    [1, 256, 14, 14]       589,824    
  BatchNorm2D-167    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     
    Conv2D-186       [[1, 256, 14, 14]]   [1, 1024, 14, 14]       262,144    
  BatchNorm2D-168   [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     
BottleneckBlock-53  [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       
    Conv2D-187      [[1, 1024, 14, 14]]    [1, 256, 14, 14]       262,144    
  BatchNorm2D-169    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     
      ReLU-64       [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       
    Conv2D-188       [[1, 256, 14, 14]]    [1, 256, 14, 14]       589,824    
  BatchNorm2D-170    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     
    Conv2D-189       [[1, 256, 14, 14]]   [1, 1024, 14, 14]       262,144    
  BatchNorm2D-171   [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     
BottleneckBlock-54  [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       
    Conv2D-190      [[1, 1024, 14, 14]]    [1, 256, 14, 14]       262,144    
  BatchNorm2D-172    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     
      ReLU-65       [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       
    Conv2D-191       [[1, 256, 14, 14]]    [1, 256, 14, 14]       589,824    
  BatchNorm2D-173    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     
    Conv2D-192       [[1, 256, 14, 14]]   [1, 1024, 14, 14]       262,144    
  BatchNorm2D-174   [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     
BottleneckBlock-55  [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       
    Conv2D-193      [[1, 1024, 14, 14]]    [1, 256, 14, 14]       262,144    
  BatchNorm2D-175    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     
      ReLU-66       [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       
    Conv2D-194       [[1, 256, 14, 14]]    [1, 256, 14, 14]       589,824    
  BatchNorm2D-176    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     
    Conv2D-195       [[1, 256, 14, 14]]   [1, 1024, 14, 14]       262,144    
  BatchNorm2D-177   [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     
BottleneckBlock-56  [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       
    Conv2D-196      [[1, 1024, 14, 14]]    [1, 256, 14, 14]       262,144    
  BatchNorm2D-178    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     
      ReLU-67       [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       
    Conv2D-197       [[1, 256, 14, 14]]    [1, 256, 14, 14]       589,824    
  BatchNorm2D-179    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     
    Conv2D-198       [[1, 256, 14, 14]]   [1, 1024, 14, 14]       262,144    
  BatchNorm2D-180   [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     
BottleneckBlock-57  [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       
    Conv2D-199      [[1, 1024, 14, 14]]    [1, 256, 14, 14]       262,144    
  BatchNorm2D-181    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     
      ReLU-68       [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       
    Conv2D-200       [[1, 256, 14, 14]]    [1, 256, 14, 14]       589,824    
  BatchNorm2D-182    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     
    Conv2D-201       [[1, 256, 14, 14]]   [1, 1024, 14, 14]       262,144    
  BatchNorm2D-183   [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     
BottleneckBlock-58  [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       
    Conv2D-202      [[1, 1024, 14, 14]]    [1, 256, 14, 14]       262,144    
  BatchNorm2D-184    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     
      ReLU-69       [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       
    Conv2D-203       [[1, 256, 14, 14]]    [1, 256, 14, 14]       589,824    
  BatchNorm2D-185    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     
    Conv2D-204       [[1, 256, 14, 14]]   [1, 1024, 14, 14]       262,144    
  BatchNorm2D-186   [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     
BottleneckBlock-59  [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       
    Conv2D-205      [[1, 1024, 14, 14]]    [1, 256, 14, 14]       262,144    
  BatchNorm2D-187    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     
      ReLU-70       [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       
    Conv2D-206       [[1, 256, 14, 14]]    [1, 256, 14, 14]       589,824    
  BatchNorm2D-188    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     
    Conv2D-207       [[1, 256, 14, 14]]   [1, 1024, 14, 14]       262,144    
  BatchNorm2D-189   [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     
BottleneckBlock-60  [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       
    Conv2D-208      [[1, 1024, 14, 14]]    [1, 256, 14, 14]       262,144    
  BatchNorm2D-190    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     
      ReLU-71       [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       
    Conv2D-209       [[1, 256, 14, 14]]    [1, 256, 14, 14]       589,824    
  BatchNorm2D-191    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     
    Conv2D-210       [[1, 256, 14, 14]]   [1, 1024, 14, 14]       262,144    
  BatchNorm2D-192   [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     
BottleneckBlock-61  [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       
    Conv2D-211      [[1, 1024, 14, 14]]    [1, 256, 14, 14]       262,144    
  BatchNorm2D-193    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     
      ReLU-72       [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       
    Conv2D-212       [[1, 256, 14, 14]]    [1, 256, 14, 14]       589,824    
  BatchNorm2D-194    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     
    Conv2D-213       [[1, 256, 14, 14]]   [1, 1024, 14, 14]       262,144    
  BatchNorm2D-195   [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     
BottleneckBlock-62  [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       
    Conv2D-214      [[1, 1024, 14, 14]]    [1, 256, 14, 14]       262,144    
  BatchNorm2D-196    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     
      ReLU-73       [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       
    Conv2D-215       [[1, 256, 14, 14]]    [1, 256, 14, 14]       589,824    
  BatchNorm2D-197    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     
    Conv2D-216       [[1, 256, 14, 14]]   [1, 1024, 14, 14]       262,144    
  BatchNorm2D-198   [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     
BottleneckBlock-63  [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       
    Conv2D-218      [[1, 1024, 14, 14]]    [1, 512, 14, 14]       524,288    
  BatchNorm2D-200    [[1, 512, 14, 14]]    [1, 512, 14, 14]        2,048     
      ReLU-74        [[1, 2048, 7, 7]]     [1, 2048, 7, 7]           0       
    Conv2D-219       [[1, 512, 14, 14]]     [1, 512, 7, 7]       2,359,296   
  BatchNorm2D-201     [[1, 512, 7, 7]]      [1, 512, 7, 7]         2,048     
    Conv2D-220        [[1, 512, 7, 7]]     [1, 2048, 7, 7]       1,048,576   
  BatchNorm2D-202    [[1, 2048, 7, 7]]     [1, 2048, 7, 7]         8,192     
    Conv2D-217      [[1, 1024, 14, 14]]    [1, 2048, 7, 7]       2,097,152   
  BatchNorm2D-199    [[1, 2048, 7, 7]]     [1, 2048, 7, 7]         8,192     
BottleneckBlock-64  [[1, 1024, 14, 14]]    [1, 2048, 7, 7]           0       
    Conv2D-221       [[1, 2048, 7, 7]]      [1, 512, 7, 7]       1,048,576   
  BatchNorm2D-203     [[1, 512, 7, 7]]      [1, 512, 7, 7]         2,048     
      ReLU-75        [[1, 2048, 7, 7]]     [1, 2048, 7, 7]           0       
    Conv2D-222        [[1, 512, 7, 7]]      [1, 512, 7, 7]       2,359,296   
  BatchNorm2D-204     [[1, 512, 7, 7]]      [1, 512, 7, 7]         2,048     
    Conv2D-223        [[1, 512, 7, 7]]     [1, 2048, 7, 7]       1,048,576   
  BatchNorm2D-205    [[1, 2048, 7, 7]]     [1, 2048, 7, 7]         8,192     
BottleneckBlock-65   [[1, 2048, 7, 7]]     [1, 2048, 7, 7]           0       
    Conv2D-224       [[1, 2048, 7, 7]]      [1, 512, 7, 7]       1,048,576   
  BatchNorm2D-206     [[1, 512, 7, 7]]      [1, 512, 7, 7]         2,048     
      ReLU-76        [[1, 2048, 7, 7]]     [1, 2048, 7, 7]           0       
    Conv2D-225        [[1, 512, 7, 7]]      [1, 512, 7, 7]       2,359,296   
  BatchNorm2D-207     [[1, 512, 7, 7]]      [1, 512, 7, 7]         2,048     
    Conv2D-226        [[1, 512, 7, 7]]     [1, 2048, 7, 7]       1,048,576   
  BatchNorm2D-208    [[1, 2048, 7, 7]]     [1, 2048, 7, 7]         8,192     
BottleneckBlock-66   [[1, 2048, 7, 7]]     [1, 2048, 7, 7]           0       
AdaptiveAvgPool2D-3  [[1, 2048, 7, 7]]     [1, 2048, 1, 1]           0       
     Linear-33          [[1, 2048]]            [1, 10]            20,490     
===============================================================================
Total params: 42,625,994
Trainable params: 42,415,306
Non-trainable params: 210,688
-------------------------------------------------------------------------------
Input size (MB): 0.57
Forward/backward pass size (MB): 391.63
Params size (MB): 162.61
Estimated Total Size (MB): 554.81
-------------------------------------------------------------------------------

{'total_params': 42625994, 'trainable_params': 42415306}

梯度下降

为了判断学习的好坏,已经效率等,引入了梯度 的概念
在这里插入图片描述

# 随机梯度下降算法的优化器
sgd_optimizer=paddle.optimizer.SGD(learning_rate=0.001, parameters=model.parameters())
# loss计算
mse_loss=paddle.nn.MSELoss()

训练模块

model.prepare(paddle.optimizer.Adam(learning_rate=0.001, parameters=model.parameters()),
              paddle.nn.CrossEntropyLoss(),   # 交叉熵损失函数。线性模型+该损失函数,即softmax分类器。
              paddle.metric.Accuracy(topk=(1,2)))
model.fit(train_dataset, # 训练数据集
          val_dataset,  # 测试数据集
          epochs=2, # 训练的总轮次
          batch_size=64, # 训练使用的批大小
          verbose=1)  # 日志展示形式

model.evaluate(test_dataset,batch_size=64,verbose=1)  # 评估

作者简介

作者:三岁
经历:自学python,现在混迹于paddle社区,希望和大家一起从基础走起,一起学习Paddle
csdn地址:https://blog.csdn.net/weixin_45623093/article/list/3
我在AI Studio上获得黄金等级,点亮7个徽章,来互关呀~ https://aistudio.baidu.com/aistudio/personalcenter/thirdview/284366

传说中的飞桨社区最差代码人,让我们一起努力!
记住:三岁出品必是精品 (不要脸系列

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 博客之星2020 设计师:CY__ 返回首页