深度学习案例:ResNet50模型+SE-Net

news2024/12/4 2:02:08

本文为为🔗365天深度学习训练营内部文章

原作者:K同学啊

 一 回顾ResNet模型

ResNet,即残差网络,是由微软研究院的Kaiming He及其合作者于2015年提出的一种深度卷积神经网络架构。该网络架构的核心创新在于引入了“残差连接”(residual connections)或“跳跃连接”(skip connections),这一结构的引入使得网络能够有效地训练深度极深的模型。该技术成功克服了传统深度网络在增加层数时所面临的梯度消失(vanishing gradients)或梯度爆炸(exploding gradients)的难题。

1. ResNet的核心思想

残差网络(ResNet)的核心理念在于采用残差学习策略以替代直接学习目标函数的方法。在该框架下,我们旨在学习一个映射函数H(x)。通过引入残差连接,ResNet并非直接对H(x)进行学习,而是转而学习残差函数F(x),即H(x)与输入x之间的差值,从而将学习目标转化为对F(x)的掌握。

该方法显著提升了网络的优化效率,即便是在恒等映射(即 H(x)=x)的情形下,亦可通过学习残差 F(x)=0来实现。残差连接的引入促进了信息与梯度的直接传递,从较浅层至较深层,有效缓解了深层网络训练过程中的困难。

 

2.ResNet的构成

残差网络(ResNet)的核心组件为残差块。该结构单元由一个或多个卷积层组成,其中输入数据通过快捷连接(short-cut connection)绕过卷积层,直接与输出相加。ResNet的典型架构可概述如下:

卷积层:残差块通常由两个或三个卷积层构成,其中3x3卷积核的应用尤为普遍。卷积操作后,通常会应用一个激活函数(如ReLU函数),以实现数据的非线性映射。

快捷连接:输入数据通过快捷连接直接与输出相加,绕过了中间的卷积层。这种设计有助于简化信息在深层网络中的传递路径。

ReLU激活函数:在卷积层之后,通常会施加ReLU激活函数,以增强网络的非线性表达能力。

二 通道注意力机制 SE-Net 

E-Net(Squeeze-and-Excitation Networks),由Hu等人于2018年提出,是一种针对卷积神经网络(CNN)的通道注意力机制。该机制通过引入自适应通道权重调整机制,显著提升了CNN在图像分类等任务中的性能。SE-Net模块的核心理念在于通过“压缩(Squeeze)”与“激励(Excitation)”操作,自动学习并赋予各通道以重要性权重,进而对特征图进行加权处理,使模型能够集中注意力于关键特征,同时抑制不相关特征。

SE-Net模块可嵌入至各类传统卷积神经网络架构中(如ResNet、Inception等),通过引入通道级注意力机制以增强网络性能。SE模块的基本原理是通过“全局信息池化”步骤捕捉全局特征信息,并据此动态调整各通道的特征图权重。SE模块的处理流程主要包括两个阶段:

1)压缩

在压缩过程中,空间特征提取(Spatial Excitation, SE)模块利用全局平均池化(Global Average Pooling, GAP)技术对各个通道的特征图进行聚合,以实现对全局特征的表征。设输入特征图为 X,其高度和宽度分别为 H 和 W,通道数为 C。通过执行全局平均池化,对每个通道的 H×W 特征图进行平均值计算,从而为每个通道提取出一个单一的标量值。

\mathbf{z_{c}}=\frac{1}{\mathrm{H\times W}}\sum_{\mathrm{i=1}}^{\mathrm{H}}\sum_{\mathrm{j=1}}^{\mathrm{W}}\mathrm{x_{ijc}} ,\quad\mathrm{c=1,2,...,C} 

2)激励

激励机制旨在通过全连接层学习各通道的重要性权重。本研究采用全局特征表示 z=[z1,z2,…,zC] 作为输入,通过两个全连接层(FC层)的处理,生成各通道的权重系数 s=[s1,s2,…,sC]。具体操作步骤如下:

首先,第一个全连接层接收输入 z,并通过激活函数(例如ReLU)获得隐层特征。

其次,第二个全连接层利用Sigmoid激活函数输出各通道的权重系数,以确保每个系数Sc介于0到1之间。

最终,通过Sigmoid激活函数处理后得到的通道注意力权重向量 s,可计算出各通道的重要性得分。

s_{\mathrm{c}}= \sigma\left(\mathrm{W}_{2}\cdot\mathrm{ReLU}(\mathrm{W}_{1}\cdot\mathrm{z})\right),\quad\mathrm{c}=1,2,...,\mathrm{C} 

3)重标定

最终,空间注意力(Spatial Enhancement,SE)模块通过应用学习得到的通道权重s对原始特征图的各个通道进行加权,实现特征重标定。设输入特征图为X,经由SE模块处理后,每个通道c的输出Y可表示为:

\mathrm{y_{c}=s_{c}\cdot x_{c},\quad c=1,2,...,C}

 其中,xc是输入特征图中通道 c的特征图,sc 是通道 c 的权重。通过这个重标定步骤,SE模块为每个通道分配一个权重,从而增强了对重要通道的关注,抑制了无关通道的影响。

三 ResNet+SE-Net 性能提升 

from keras import layers
from keras.layers import Input, Activation, BatchNormalization, Flatten, Dropout,Reshape
from keras.layers import Dense, Conv2D, MaxPooling2D, ZeroPadding2D, AveragePooling2D, GlobalAveragePooling2D
from keras.models import Model
import tensorflow as tf
from keras.layers import Add, UpSampling2D, Conv2D
from keras.layers import Multiply, Concatenate

def squeeze_excite_block(input_tensor, ratio=16):
    '''
    Squeeze-and-Excitation Block
    :param input_tensor: 输入张量
    :param ratio: 压缩比,控制激励层中间层的维度。通常选择较小的值,如16。
    :return: 加权后的张量
    '''
    channel_axis = -1  # 通道轴通常在最后一维
    channels = input_tensor.shape[channel_axis]  # 获取通道数

    # Squeeze:全局平均池化
    x = GlobalAveragePooling2D()(input_tensor)
    x = Reshape((1, 1, channels))(x)

    # Excite:两个全连接层生成通道权重
    x = Dense(channels // ratio, activation='relu', kernel_initializer='he_normal', use_bias=False)(x)
    x = Dense(channels, activation='sigmoid', kernel_initializer='he_normal', use_bias=False)(x)

    # 将生成的权重与输入张量相乘
    x = Multiply()([input_tensor, x])
    
    return x
def identity_block(input_tensor, kernel_size, filters, stage, block):
    filters1, filters2, filters3 = filters
    name_base = str(stage) + block + '_identity_block_'

    # 第一卷积层
    x = Conv2D(filters1, (1, 1), name=name_base + 'conv1')(input_tensor)
    x = BatchNormalization(name=name_base + 'bn1')(x)
    x = Activation('relu', name=name_base + 'relu1')(x)

    # 第二卷积层
    x = Conv2D(filters2, kernel_size, padding='same', name=name_base + 'conv2')(x)
    x = BatchNormalization(name=name_base + 'bn2')(x)
    x = Activation('relu', name=name_base + 'relu2')(x)

    # 第三卷积层
    x = Conv2D(filters3, (1, 1), name=name_base + 'conv3')(x)
    x = BatchNormalization(name=name_base + 'bn3')(x)

    # SE-Net通道注意力机制
    x = squeeze_excite_block(x)

    # 残差连接
    x = layers.add([x, input_tensor], name=name_base + 'add')
    x = Activation('relu', name=name_base + 'relu4')(x)

    return x


def conv_block(input_tensor, kernel_size, filters, stage, block, strides=(2, 2)):
    filters1, filters2, filters3 = filters
    res_name_base = str(stage) + block + '_conv_block_res_'
    name_base = str(stage) + block + '_conv_block_'

    # 主卷积层
    x = Conv2D(filters1, (1, 1), strides=strides, name=name_base + 'conv1')(input_tensor)
    x = BatchNormalization(name=name_base + 'bn1')(x)
    x = Activation('relu', name=name_base + 'relu1')(x)

    x = Conv2D(filters2, kernel_size, padding='same', name=name_base + 'conv2')(x)
    x = BatchNormalization(name=name_base + 'bn2')(x)
    x = Activation('relu', name=name_base + 'relu2')(x)

    x = Conv2D(filters3, (1, 1), name=name_base + 'conv3')(x)
    x = BatchNormalization(name=name_base + 'bn3')(x)

    # 残差连接的卷积
    shortcut = Conv2D(filters3, (1, 1), strides=strides, name=res_name_base + 'conv')(input_tensor)
    shortcut = BatchNormalization(name=res_name_base + 'bn')(shortcut)

    # SE-Net通道注意力机制
    x = squeeze_excite_block(x)

    # 残差连接加和
    x = layers.add([x, shortcut], name=name_base + 'add')
    x = Activation('relu', name=name_base + 'relu4')(x)

    return x
def ResNet50(input_shape=[224,224,3], classes=4):
    img_input = Input(shape=input_shape)
    x = ZeroPadding2D((3, 3))(img_input)

    x = Conv2D(64, (7, 7), strides=(2, 2), name='conv1')(x)
    x = BatchNormalization(name='bn_conv1')(x)
    x = Activation('relu')(x)
    x = MaxPooling2D((3, 3), strides=(2, 2))(x)

    x = conv_block(x, 3, [64, 64, 256], stage=2, block='a', strides=(1, 1))
    x = identity_block(x, 3, [64, 64, 256], stage=2, block='b')
    x = identity_block(x, 3, [64, 64, 256], stage=2, block='c')

    x = conv_block(x, 3, [128, 128, 512], stage=3, block='a')
    x = identity_block(x, 3, [128, 128, 512], stage=3, block='b')
    x = identity_block(x, 3, [128, 128, 512], stage=3, block='c')
    x = identity_block(x, 3, [128, 128, 512], stage=3, block='d')

    x = conv_block(x, 3, [256, 256, 1024], stage=4, block='a')
    x = identity_block(x, 3, [256, 256, 1024], stage=4, block='b')
    x = identity_block(x, 3, [256, 256, 1024], stage=4, block='c')
    x = identity_block(x, 3, [256, 256, 1024], stage=4, block='d')
    x = identity_block(x, 3, [256, 256, 1024], stage=4, block='e')
    x = identity_block(x, 3, [256, 256, 1024], stage=4, block='f')

    x = conv_block(x, 3, [512, 512, 2048], stage=5, block='a')
    x = identity_block(x, 3, [512, 512, 2048], stage=5, block='b')
    x = identity_block(x, 3, [512, 512, 2048], stage=5, block='c')

    x = AveragePooling2D((7, 7), name='avg_pool')(x)

    x = Flatten()(x)
    x = Dropout(0.5)(x)
    x = Dense(classes, activation='softmax', name='fc2')(x)

    model = Model(img_input, x, name='resnet50')

    return model

model = ResNet50()
model.summary()
Model: "resnet50"
__________________________________________________________________________________________________
 Layer (type)                   Output Shape         Param #     Connected to                     
==================================================================================================
 input_1 (InputLayer)           [(None, 224, 224, 3  0           []                               
                                )]                                                                
                                                                                                  
 zero_padding2d (ZeroPadding2D)  (None, 230, 230, 3)  0          ['input_1[0][0]']                
                                                                                                  
 conv1 (Conv2D)                 (None, 112, 112, 64  9472        ['zero_padding2d[0][0]']         
                                )                                                                 
                                                                                                  
 bn_conv1 (BatchNormalization)  (None, 112, 112, 64  256         ['conv1[0][0]']                  
                                )                                                                 
                                                                                                  
 activation (Activation)        (None, 112, 112, 64  0           ['bn_conv1[0][0]']               
                                )                                                                 
                                                                                                  
 max_pooling2d (MaxPooling2D)   (None, 55, 55, 64)   0           ['activation[0][0]']             
                                                                                                  
 2a_conv_block_conv1 (Conv2D)   (None, 55, 55, 64)   4160        ['max_pooling2d[0][0]']          
                                                                                                  
 2a_conv_block_bn1 (BatchNormal  (None, 55, 55, 64)  256         ['2a_conv_block_conv1[0][0]']    
 ization)                                                                                         
                                                                                                  
 2a_conv_block_relu1 (Activatio  (None, 55, 55, 64)  0           ['2a_conv_block_bn1[0][0]']      
 n)                                                                                               
                                                                                                  
 2a_conv_block_conv2 (Conv2D)   (None, 55, 55, 64)   36928       ['2a_conv_block_relu1[0][0]']    
                                                                                                  
 2a_conv_block_bn2 (BatchNormal  (None, 55, 55, 64)  256         ['2a_conv_block_conv2[0][0]']    
 ization)                                                                                         
                                                                                                  
 2a_conv_block_relu2 (Activatio  (None, 55, 55, 64)  0           ['2a_conv_block_bn2[0][0]']      
 n)                                                                                               
                                                                                                  
 2a_conv_block_conv3 (Conv2D)   (None, 55, 55, 256)  16640       ['2a_conv_block_relu2[0][0]']    
                                                                                                  
 2a_conv_block_bn3 (BatchNormal  (None, 55, 55, 256)  1024       ['2a_conv_block_conv3[0][0]']    
 ization)                                                                                         
                                                                                                  
 global_average_pooling2d (Glob  (None, 256)         0           ['2a_conv_block_bn3[0][0]']      
 alAveragePooling2D)                                                                              
                                                                                                  
 reshape (Reshape)              (None, 1, 1, 256)    0           ['global_average_pooling2d[0][0]'
                                                                 ]                                
                                                                                                  
 dense (Dense)                  (None, 1, 1, 16)     4096        ['reshape[0][0]']                
                                                                                                  
 dense_1 (Dense)                (None, 1, 1, 256)    4096        ['dense[0][0]']                  
                                                                                                  
 2a_conv_block_res_conv (Conv2D  (None, 55, 55, 256)  16640      ['max_pooling2d[0][0]']          
 )                                                                                                
                                                                                                  
 multiply (Multiply)            (None, 55, 55, 256)  0           ['2a_conv_block_bn3[0][0]',      
                                                                  'dense_1[0][0]']                
                                                                                                  
 2a_conv_block_res_bn (BatchNor  (None, 55, 55, 256)  1024       ['2a_conv_block_res_conv[0][0]'] 
 malization)                                                                                      
                                                                                                  
 2a_conv_block_add (Add)        (None, 55, 55, 256)  0           ['multiply[0][0]',               
                                                                  '2a_conv_block_res_bn[0][0]']   
                                                                                                  
 2a_conv_block_relu4 (Activatio  (None, 55, 55, 256)  0          ['2a_conv_block_add[0][0]']      
 n)                                                                                               
                                                                                                  
 2b_identity_block_conv1 (Conv2  (None, 55, 55, 64)  16448       ['2a_conv_block_relu4[0][0]']    
 D)                                                                                               
                                                                                                  
 2b_identity_block_bn1 (BatchNo  (None, 55, 55, 64)  256         ['2b_identity_block_conv1[0][0]']
 rmalization)                                                                                     
                                                                                                  
 2b_identity_block_relu1 (Activ  (None, 55, 55, 64)  0           ['2b_identity_block_bn1[0][0]']  
 ation)                                                                                           
                                                                                                  
 2b_identity_block_conv2 (Conv2  (None, 55, 55, 64)  36928       ['2b_identity_block_relu1[0][0]']
 D)                                                                                               
                                                                                                  
 2b_identity_block_bn2 (BatchNo  (None, 55, 55, 64)  256         ['2b_identity_block_conv2[0][0]']
 rmalization)                                                                                     
                                                                                                  
 2b_identity_block_relu2 (Activ  (None, 55, 55, 64)  0           ['2b_identity_block_bn2[0][0]']  
 ation)                                                                                           
                                                                                                  
 2b_identity_block_conv3 (Conv2  (None, 55, 55, 256)  16640      ['2b_identity_block_relu2[0][0]']
 D)                                                                                               
                                                                                                  
 2b_identity_block_bn3 (BatchNo  (None, 55, 55, 256)  1024       ['2b_identity_block_conv3[0][0]']
 rmalization)                                                                                     
                                                                                                  
 global_average_pooling2d_1 (Gl  (None, 256)         0           ['2b_identity_block_bn3[0][0]']  
 obalAveragePooling2D)                                                                            
                                                                                                  
 reshape_1 (Reshape)            (None, 1, 1, 256)    0           ['global_average_pooling2d_1[0][0
                                                                 ]']                              
                                                                                                  
 dense_2 (Dense)                (None, 1, 1, 16)     4096        ['reshape_1[0][0]']              
                                                                                                  
 dense_3 (Dense)                (None, 1, 1, 256)    4096        ['dense_2[0][0]']                
                                                                                                  
 multiply_1 (Multiply)          (None, 55, 55, 256)  0           ['2b_identity_block_bn3[0][0]',  
                                                                  'dense_3[0][0]']                
                                                                                                  
 2b_identity_block_add (Add)    (None, 55, 55, 256)  0           ['multiply_1[0][0]',             
                                                                  '2a_conv_block_relu4[0][0]']    
                                                                                                  
 2b_identity_block_relu4 (Activ  (None, 55, 55, 256)  0          ['2b_identity_block_add[0][0]']  
 ation)                                                                                           
                                                                                                  
 2c_identity_block_conv1 (Conv2  (None, 55, 55, 64)  16448       ['2b_identity_block_relu4[0][0]']
 D)                                                                                               
                                                                                                  
 2c_identity_block_bn1 (BatchNo  (None, 55, 55, 64)  256         ['2c_identity_block_conv1[0][0]']
 rmalization)                                                                                     
                                                                                                  
 2c_identity_block_relu1 (Activ  (None, 55, 55, 64)  0           ['2c_identity_block_bn1[0][0]']  
 ation)                                                                                           
                                                                                                  
 2c_identity_block_conv2 (Conv2  (None, 55, 55, 64)  36928       ['2c_identity_block_relu1[0][0]']
 D)                                                                                               
                                                                                                  
 2c_identity_block_bn2 (BatchNo  (None, 55, 55, 64)  256         ['2c_identity_block_conv2[0][0]']
 rmalization)                                                                                     
                                                                                                  
 2c_identity_block_relu2 (Activ  (None, 55, 55, 64)  0           ['2c_identity_block_bn2[0][0]']  
 ation)                                                                                           
                                                                                                  
 2c_identity_block_conv3 (Conv2  (None, 55, 55, 256)  16640      ['2c_identity_block_relu2[0][0]']
 D)                                                                                               
                                                                                                  
 2c_identity_block_bn3 (BatchNo  (None, 55, 55, 256)  1024       ['2c_identity_block_conv3[0][0]']
 rmalization)                                                                                     
                                                                                                  
 global_average_pooling2d_2 (Gl  (None, 256)         0           ['2c_identity_block_bn3[0][0]']  
 obalAveragePooling2D)                                                                            
                                                                                                  
 reshape_2 (Reshape)            (None, 1, 1, 256)    0           ['global_average_pooling2d_2[0][0
                                                                 ]']                              
                                                                                                  
 dense_4 (Dense)                (None, 1, 1, 16)     4096        ['reshape_2[0][0]']              
                                                                                                  
 dense_5 (Dense)                (None, 1, 1, 256)    4096        ['dense_4[0][0]']                
                                                                                                  
 multiply_2 (Multiply)          (None, 55, 55, 256)  0           ['2c_identity_block_bn3[0][0]',  
                                                                  'dense_5[0][0]']                
                                                                                                  
 2c_identity_block_add (Add)    (None, 55, 55, 256)  0           ['multiply_2[0][0]',             
                                                                  '2b_identity_block_relu4[0][0]']
                                                                                                  
 2c_identity_block_relu4 (Activ  (None, 55, 55, 256)  0          ['2c_identity_block_add[0][0]']  
 ation)                                                                                           
                                                                                                  
 3a_conv_block_conv1 (Conv2D)   (None, 28, 28, 128)  32896       ['2c_identity_block_relu4[0][0]']
                                                                                                  
 3a_conv_block_bn1 (BatchNormal  (None, 28, 28, 128)  512        ['3a_conv_block_conv1[0][0]']    
 ization)                                                                                         
                                                                                                  
 3a_conv_block_relu1 (Activatio  (None, 28, 28, 128)  0          ['3a_conv_block_bn1[0][0]']      
 n)                                                                                               
                                                                                                  
 3a_conv_block_conv2 (Conv2D)   (None, 28, 28, 128)  147584      ['3a_conv_block_relu1[0][0]']    
                                                                                                  
 3a_conv_block_bn2 (BatchNormal  (None, 28, 28, 128)  512        ['3a_conv_block_conv2[0][0]']    
 ization)                                                                                         
                                                                                                  
 3a_conv_block_relu2 (Activatio  (None, 28, 28, 128)  0          ['3a_conv_block_bn2[0][0]']      
 n)                                                                                               
                                                                                                  
 3a_conv_block_conv3 (Conv2D)   (None, 28, 28, 512)  66048       ['3a_conv_block_relu2[0][0]']    
                                                                                                  
 3a_conv_block_bn3 (BatchNormal  (None, 28, 28, 512)  2048       ['3a_conv_block_conv3[0][0]']    
 ization)                                                                                         
                                                                                                  
 global_average_pooling2d_3 (Gl  (None, 512)         0           ['3a_conv_block_bn3[0][0]']      
 obalAveragePooling2D)                                                                            
                                                                                                  
 reshape_3 (Reshape)            (None, 1, 1, 512)    0           ['global_average_pooling2d_3[0][0
                                                                 ]']                              
                                                                                                  
 dense_6 (Dense)                (None, 1, 1, 32)     16384       ['reshape_3[0][0]']              
                                                                                                  
 dense_7 (Dense)                (None, 1, 1, 512)    16384       ['dense_6[0][0]']                
                                                                                                  
 3a_conv_block_res_conv (Conv2D  (None, 28, 28, 512)  131584     ['2c_identity_block_relu4[0][0]']
 )                                                                                                
                                                                                                  
 multiply_3 (Multiply)          (None, 28, 28, 512)  0           ['3a_conv_block_bn3[0][0]',      
                                                                  'dense_7[0][0]']                
                                                                                                  
 3a_conv_block_res_bn (BatchNor  (None, 28, 28, 512)  2048       ['3a_conv_block_res_conv[0][0]'] 
 malization)                                                                                      
                                                                                                  
 3a_conv_block_add (Add)        (None, 28, 28, 512)  0           ['multiply_3[0][0]',             
                                                                  '3a_conv_block_res_bn[0][0]']   
                                                                                                  
 3a_conv_block_relu4 (Activatio  (None, 28, 28, 512)  0          ['3a_conv_block_add[0][0]']      
 n)                                                                                               
                                                                                                  
 3b_identity_block_conv1 (Conv2  (None, 28, 28, 128)  65664      ['3a_conv_block_relu4[0][0]']    
 D)                                                                                               
                                                                                                  
 3b_identity_block_bn1 (BatchNo  (None, 28, 28, 128)  512        ['3b_identity_block_conv1[0][0]']
 rmalization)                                                                                     
                                                                                                  
 3b_identity_block_relu1 (Activ  (None, 28, 28, 128)  0          ['3b_identity_block_bn1[0][0]']  
 ation)                                                                                           
                                                                                                  
 3b_identity_block_conv2 (Conv2  (None, 28, 28, 128)  147584     ['3b_identity_block_relu1[0][0]']
 D)                                                                                               
                                                                                                  
 3b_identity_block_bn2 (BatchNo  (None, 28, 28, 128)  512        ['3b_identity_block_conv2[0][0]']
 rmalization)                                                                                     
                                                                                                  
 3b_identity_block_relu2 (Activ  (None, 28, 28, 128)  0          ['3b_identity_block_bn2[0][0]']  
 ation)                                                                                           
                                                                                                  
 3b_identity_block_conv3 (Conv2  (None, 28, 28, 512)  66048      ['3b_identity_block_relu2[0][0]']
 D)                                                                                               
                                                                                                  
 3b_identity_block_bn3 (BatchNo  (None, 28, 28, 512)  2048       ['3b_identity_block_conv3[0][0]']
 rmalization)                                                                                     
                                                                                                  
 global_average_pooling2d_4 (Gl  (None, 512)         0           ['3b_identity_block_bn3[0][0]']  
 obalAveragePooling2D)                                                                            
                                                                                                  
 reshape_4 (Reshape)            (None, 1, 1, 512)    0           ['global_average_pooling2d_4[0][0
                                                                 ]']                              
                                                                                                  
 dense_8 (Dense)                (None, 1, 1, 32)     16384       ['reshape_4[0][0]']              
                                                                                                  
 dense_9 (Dense)                (None, 1, 1, 512)    16384       ['dense_8[0][0]']                
                                                                                                  
 multiply_4 (Multiply)          (None, 28, 28, 512)  0           ['3b_identity_block_bn3[0][0]',  
                                                                  'dense_9[0][0]']                
                                                                                                  
 3b_identity_block_add (Add)    (None, 28, 28, 512)  0           ['multiply_4[0][0]',             
                                                                  '3a_conv_block_relu4[0][0]']    
                                                                                                  
 3b_identity_block_relu4 (Activ  (None, 28, 28, 512)  0          ['3b_identity_block_add[0][0]']  
 ation)                                                                                           
                                                                                                  
 3c_identity_block_conv1 (Conv2  (None, 28, 28, 128)  65664      ['3b_identity_block_relu4[0][0]']
 D)                                                                                               
                                                                                                  
 3c_identity_block_bn1 (BatchNo  (None, 28, 28, 128)  512        ['3c_identity_block_conv1[0][0]']
 rmalization)                                                                                     
                                                                                                  
 3c_identity_block_relu1 (Activ  (None, 28, 28, 128)  0          ['3c_identity_block_bn1[0][0]']  
 ation)                                                                                           
                                                                                                  
 3c_identity_block_conv2 (Conv2  (None, 28, 28, 128)  147584     ['3c_identity_block_relu1[0][0]']
 D)                                                                                               
                                                                                                  
 3c_identity_block_bn2 (BatchNo  (None, 28, 28, 128)  512        ['3c_identity_block_conv2[0][0]']
 rmalization)                                                                                     
                                                                                                  
 3c_identity_block_relu2 (Activ  (None, 28, 28, 128)  0          ['3c_identity_block_bn2[0][0]']  
 ation)                                                                                           
                                                                                                  
 3c_identity_block_conv3 (Conv2  (None, 28, 28, 512)  66048      ['3c_identity_block_relu2[0][0]']
 D)                                                                                               
                                                                                                  
 3c_identity_block_bn3 (BatchNo  (None, 28, 28, 512)  2048       ['3c_identity_block_conv3[0][0]']
 rmalization)                                                                                     
                                                                                                  
 global_average_pooling2d_5 (Gl  (None, 512)         0           ['3c_identity_block_bn3[0][0]']  
 obalAveragePooling2D)                                                                            
                                                                                                  
 reshape_5 (Reshape)            (None, 1, 1, 512)    0           ['global_average_pooling2d_5[0][0
                                                                 ]']                              
                                                                                                  
 dense_10 (Dense)               (None, 1, 1, 32)     16384       ['reshape_5[0][0]']              
                                                                                                  
 dense_11 (Dense)               (None, 1, 1, 512)    16384       ['dense_10[0][0]']               
                                                                                                  
 multiply_5 (Multiply)          (None, 28, 28, 512)  0           ['3c_identity_block_bn3[0][0]',  
                                                                  'dense_11[0][0]']               
                                                                                                  
 3c_identity_block_add (Add)    (None, 28, 28, 512)  0           ['multiply_5[0][0]',             
                                                                  '3b_identity_block_relu4[0][0]']
                                                                                                  
 3c_identity_block_relu4 (Activ  (None, 28, 28, 512)  0          ['3c_identity_block_add[0][0]']  
 ation)                                                                                           
                                                                                                  
 3d_identity_block_conv1 (Conv2  (None, 28, 28, 128)  65664      ['3c_identity_block_relu4[0][0]']
 D)                                                                                               
                                                                                                  
 3d_identity_block_bn1 (BatchNo  (None, 28, 28, 128)  512        ['3d_identity_block_conv1[0][0]']
 rmalization)                                                                                     
                                                                                                  
 3d_identity_block_relu1 (Activ  (None, 28, 28, 128)  0          ['3d_identity_block_bn1[0][0]']  
 ation)                                                                                           
                                                                                                  
 3d_identity_block_conv2 (Conv2  (None, 28, 28, 128)  147584     ['3d_identity_block_relu1[0][0]']
 D)                                                                                               
                                                                                                  
 3d_identity_block_bn2 (BatchNo  (None, 28, 28, 128)  512        ['3d_identity_block_conv2[0][0]']
 rmalization)                                                                                     
                                                                                                  
 3d_identity_block_relu2 (Activ  (None, 28, 28, 128)  0          ['3d_identity_block_bn2[0][0]']  
 ation)                                                                                           
                                                                                                  
 3d_identity_block_conv3 (Conv2  (None, 28, 28, 512)  66048      ['3d_identity_block_relu2[0][0]']
 D)                                                                                               
                                                                                                  
 3d_identity_block_bn3 (BatchNo  (None, 28, 28, 512)  2048       ['3d_identity_block_conv3[0][0]']
 rmalization)                                                                                     
                                                                                                  
 global_average_pooling2d_6 (Gl  (None, 512)         0           ['3d_identity_block_bn3[0][0]']  
 obalAveragePooling2D)                                                                            
                                                                                                  
 reshape_6 (Reshape)            (None, 1, 1, 512)    0           ['global_average_pooling2d_6[0][0
                                                                 ]']                              
                                                                                                  
 dense_12 (Dense)               (None, 1, 1, 32)     16384       ['reshape_6[0][0]']              
                                                                                                  
 dense_13 (Dense)               (None, 1, 1, 512)    16384       ['dense_12[0][0]']               
                                                                                                  
 multiply_6 (Multiply)          (None, 28, 28, 512)  0           ['3d_identity_block_bn3[0][0]',  
                                                                  'dense_13[0][0]']               
                                                                                                  
 3d_identity_block_add (Add)    (None, 28, 28, 512)  0           ['multiply_6[0][0]',             
                                                                  '3c_identity_block_relu4[0][0]']
                                                                                                  
 3d_identity_block_relu4 (Activ  (None, 28, 28, 512)  0          ['3d_identity_block_add[0][0]']  
 ation)                                                                                           
                                                                                                  
 4a_conv_block_conv1 (Conv2D)   (None, 14, 14, 256)  131328      ['3d_identity_block_relu4[0][0]']
                                                                                                  
 4a_conv_block_bn1 (BatchNormal  (None, 14, 14, 256)  1024       ['4a_conv_block_conv1[0][0]']    
 ization)                                                                                         
                                                                                                  
 4a_conv_block_relu1 (Activatio  (None, 14, 14, 256)  0          ['4a_conv_block_bn1[0][0]']      
 n)                                                                                               
                                                                                                  
 4a_conv_block_conv2 (Conv2D)   (None, 14, 14, 256)  590080      ['4a_conv_block_relu1[0][0]']    
                                                                                                  
 4a_conv_block_bn2 (BatchNormal  (None, 14, 14, 256)  1024       ['4a_conv_block_conv2[0][0]']    
 ization)                                                                                         
                                                                                                  
 4a_conv_block_relu2 (Activatio  (None, 14, 14, 256)  0          ['4a_conv_block_bn2[0][0]']      
 n)                                                                                               
                                                                                                  
 4a_conv_block_conv3 (Conv2D)   (None, 14, 14, 1024  263168      ['4a_conv_block_relu2[0][0]']    
                                )                                                                 
                                                                                                  
 4a_conv_block_bn3 (BatchNormal  (None, 14, 14, 1024  4096       ['4a_conv_block_conv3[0][0]']    
 ization)                       )                                                                 
                                                                                                  
 global_average_pooling2d_7 (Gl  (None, 1024)        0           ['4a_conv_block_bn3[0][0]']      
 obalAveragePooling2D)                                                                            
                                                                                                  
 reshape_7 (Reshape)            (None, 1, 1, 1024)   0           ['global_average_pooling2d_7[0][0
                                                                 ]']                              
                                                                                                  
 dense_14 (Dense)               (None, 1, 1, 64)     65536       ['reshape_7[0][0]']              
                                                                                                  
 dense_15 (Dense)               (None, 1, 1, 1024)   65536       ['dense_14[0][0]']               
                                                                                                  
 4a_conv_block_res_conv (Conv2D  (None, 14, 14, 1024  525312     ['3d_identity_block_relu4[0][0]']
 )                              )                                                                 
                                                                                                  
 multiply_7 (Multiply)          (None, 14, 14, 1024  0           ['4a_conv_block_bn3[0][0]',      
                                )                                 'dense_15[0][0]']               
                                                                                                  
 4a_conv_block_res_bn (BatchNor  (None, 14, 14, 1024  4096       ['4a_conv_block_res_conv[0][0]'] 
 malization)                    )                                                                 
                                                                                                  
 4a_conv_block_add (Add)        (None, 14, 14, 1024  0           ['multiply_7[0][0]',             
                                )                                 '4a_conv_block_res_bn[0][0]']   
                                                                                                  
 4a_conv_block_relu4 (Activatio  (None, 14, 14, 1024  0          ['4a_conv_block_add[0][0]']      
 n)                             )                                                                 
                                                                                                  
 4b_identity_block_conv1 (Conv2  (None, 14, 14, 256)  262400     ['4a_conv_block_relu4[0][0]']    
 D)                                                                                               
                                                                                                  
 4b_identity_block_bn1 (BatchNo  (None, 14, 14, 256)  1024       ['4b_identity_block_conv1[0][0]']
 rmalization)                                                                                     
                                                                                                  
 4b_identity_block_relu1 (Activ  (None, 14, 14, 256)  0          ['4b_identity_block_bn1[0][0]']  
 ation)                                                                                           
                                                                                                  
 4b_identity_block_conv2 (Conv2  (None, 14, 14, 256)  590080     ['4b_identity_block_relu1[0][0]']
 D)                                                                                               
                                                                                                  
 4b_identity_block_bn2 (BatchNo  (None, 14, 14, 256)  1024       ['4b_identity_block_conv2[0][0]']
 rmalization)                                                                                     
                                                                                                  
 4b_identity_block_relu2 (Activ  (None, 14, 14, 256)  0          ['4b_identity_block_bn2[0][0]']  
 ation)                                                                                           
                                                                                                  
 4b_identity_block_conv3 (Conv2  (None, 14, 14, 1024  263168     ['4b_identity_block_relu2[0][0]']
 D)                             )                                                                 
                                                                                                  
 4b_identity_block_bn3 (BatchNo  (None, 14, 14, 1024  4096       ['4b_identity_block_conv3[0][0]']
 rmalization)                   )                                                                 
                                                                                                  
 global_average_pooling2d_8 (Gl  (None, 1024)        0           ['4b_identity_block_bn3[0][0]']  
 obalAveragePooling2D)                                                                            
                                                                                                  
 reshape_8 (Reshape)            (None, 1, 1, 1024)   0           ['global_average_pooling2d_8[0][0
                                                                 ]']                              
                                                                                                  
 dense_16 (Dense)               (None, 1, 1, 64)     65536       ['reshape_8[0][0]']              
                                                                                                  
 dense_17 (Dense)               (None, 1, 1, 1024)   65536       ['dense_16[0][0]']               
                                                                                                  
 multiply_8 (Multiply)          (None, 14, 14, 1024  0           ['4b_identity_block_bn3[0][0]',  
                                )                                 'dense_17[0][0]']               
                                                                                                  
 4b_identity_block_add (Add)    (None, 14, 14, 1024  0           ['multiply_8[0][0]',             
                                )                                 '4a_conv_block_relu4[0][0]']    
                                                                                                  
 4b_identity_block_relu4 (Activ  (None, 14, 14, 1024  0          ['4b_identity_block_add[0][0]']  
 ation)                         )                                                                 
                                                                                                  
 4c_identity_block_conv1 (Conv2  (None, 14, 14, 256)  262400     ['4b_identity_block_relu4[0][0]']
 D)                                                                                               
                                                                                                  
 4c_identity_block_bn1 (BatchNo  (None, 14, 14, 256)  1024       ['4c_identity_block_conv1[0][0]']
 rmalization)                                                                                     
                                                                                                  
 4c_identity_block_relu1 (Activ  (None, 14, 14, 256)  0          ['4c_identity_block_bn1[0][0]']  
 ation)                                                                                           
                                                                                                  
 4c_identity_block_conv2 (Conv2  (None, 14, 14, 256)  590080     ['4c_identity_block_relu1[0][0]']
 D)                                                                                               
                                                                                                  
 4c_identity_block_bn2 (BatchNo  (None, 14, 14, 256)  1024       ['4c_identity_block_conv2[0][0]']
 rmalization)                                                                                     
                                                                                                  
 4c_identity_block_relu2 (Activ  (None, 14, 14, 256)  0          ['4c_identity_block_bn2[0][0]']  
 ation)                                                                                           
                                                                                                  
 4c_identity_block_conv3 (Conv2  (None, 14, 14, 1024  263168     ['4c_identity_block_relu2[0][0]']
 D)                             )                                                                 
                                                                                                  
 4c_identity_block_bn3 (BatchNo  (None, 14, 14, 1024  4096       ['4c_identity_block_conv3[0][0]']
 rmalization)                   )                                                                 
                                                                                                  
 global_average_pooling2d_9 (Gl  (None, 1024)        0           ['4c_identity_block_bn3[0][0]']  
 obalAveragePooling2D)                                                                            
                                                                                                  
 reshape_9 (Reshape)            (None, 1, 1, 1024)   0           ['global_average_pooling2d_9[0][0
                                                                 ]']                              
                                                                                                  
 dense_18 (Dense)               (None, 1, 1, 64)     65536       ['reshape_9[0][0]']              
                                                                                                  
 dense_19 (Dense)               (None, 1, 1, 1024)   65536       ['dense_18[0][0]']               
                                                                                                  
 multiply_9 (Multiply)          (None, 14, 14, 1024  0           ['4c_identity_block_bn3[0][0]',  
                                )                                 'dense_19[0][0]']               
                                                                                                  
 4c_identity_block_add (Add)    (None, 14, 14, 1024  0           ['multiply_9[0][0]',             
                                )                                 '4b_identity_block_relu4[0][0]']
                                                                                                  
 4c_identity_block_relu4 (Activ  (None, 14, 14, 1024  0          ['4c_identity_block_add[0][0]']  
 ation)                         )                                                                 
                                                                                                  
 4d_identity_block_conv1 (Conv2  (None, 14, 14, 256)  262400     ['4c_identity_block_relu4[0][0]']
 D)                                                                                               
                                                                                                  
 4d_identity_block_bn1 (BatchNo  (None, 14, 14, 256)  1024       ['4d_identity_block_conv1[0][0]']
 rmalization)                                                                                     
                                                                                                  
 4d_identity_block_relu1 (Activ  (None, 14, 14, 256)  0          ['4d_identity_block_bn1[0][0]']  
 ation)                                                                                           
                                                                                                  
 4d_identity_block_conv2 (Conv2  (None, 14, 14, 256)  590080     ['4d_identity_block_relu1[0][0]']
 D)                                                                                               
                                                                                                  
 4d_identity_block_bn2 (BatchNo  (None, 14, 14, 256)  1024       ['4d_identity_block_conv2[0][0]']
 rmalization)                                                                                     
                                                                                                  
 4d_identity_block_relu2 (Activ  (None, 14, 14, 256)  0          ['4d_identity_block_bn2[0][0]']  
 ation)                                                                                           
                                                                                                  
 4d_identity_block_conv3 (Conv2  (None, 14, 14, 1024  263168     ['4d_identity_block_relu2[0][0]']
 D)                             )                                                                 
                                                                                                  
 4d_identity_block_bn3 (BatchNo  (None, 14, 14, 1024  4096       ['4d_identity_block_conv3[0][0]']
 rmalization)                   )                                                                 
                                                                                                  
 global_average_pooling2d_10 (G  (None, 1024)        0           ['4d_identity_block_bn3[0][0]']  
 lobalAveragePooling2D)                                                                           
                                                                                                  
 reshape_10 (Reshape)           (None, 1, 1, 1024)   0           ['global_average_pooling2d_10[0][
                                                                 0]']                             
                                                                                                  
 dense_20 (Dense)               (None, 1, 1, 64)     65536       ['reshape_10[0][0]']             
                                                                                                  
 dense_21 (Dense)               (None, 1, 1, 1024)   65536       ['dense_20[0][0]']               
                                                                                                  
 multiply_10 (Multiply)         (None, 14, 14, 1024  0           ['4d_identity_block_bn3[0][0]',  
                                )                                 'dense_21[0][0]']               
                                                                                                  
 4d_identity_block_add (Add)    (None, 14, 14, 1024  0           ['multiply_10[0][0]',            
                                )                                 '4c_identity_block_relu4[0][0]']
                                                                                                  
 4d_identity_block_relu4 (Activ  (None, 14, 14, 1024  0          ['4d_identity_block_add[0][0]']  
 ation)                         )                                                                 
                                                                                                  
 4e_identity_block_conv1 (Conv2  (None, 14, 14, 256)  262400     ['4d_identity_block_relu4[0][0]']
 D)                                                                                               
                                                                                                  
 4e_identity_block_bn1 (BatchNo  (None, 14, 14, 256)  1024       ['4e_identity_block_conv1[0][0]']
 rmalization)                                                                                     
                                                                                                  
 4e_identity_block_relu1 (Activ  (None, 14, 14, 256)  0          ['4e_identity_block_bn1[0][0]']  
 ation)                                                                                           
                                                                                                  
 4e_identity_block_conv2 (Conv2  (None, 14, 14, 256)  590080     ['4e_identity_block_relu1[0][0]']
 D)                                                                                               
                                                                                                  
 4e_identity_block_bn2 (BatchNo  (None, 14, 14, 256)  1024       ['4e_identity_block_conv2[0][0]']
 rmalization)                                                                                     
                                                                                                  
 4e_identity_block_relu2 (Activ  (None, 14, 14, 256)  0          ['4e_identity_block_bn2[0][0]']  
 ation)                                                                                           
                                                                                                  
 4e_identity_block_conv3 (Conv2  (None, 14, 14, 1024  263168     ['4e_identity_block_relu2[0][0]']
 D)                             )                                                                 
                                                                                                  
 4e_identity_block_bn3 (BatchNo  (None, 14, 14, 1024  4096       ['4e_identity_block_conv3[0][0]']
 rmalization)                   )                                                                 
                                                                                                  
 global_average_pooling2d_11 (G  (None, 1024)        0           ['4e_identity_block_bn3[0][0]']  
 lobalAveragePooling2D)                                                                           
                                                                                                  
 reshape_11 (Reshape)           (None, 1, 1, 1024)   0           ['global_average_pooling2d_11[0][
                                                                 0]']                             
                                                                                                  
 dense_22 (Dense)               (None, 1, 1, 64)     65536       ['reshape_11[0][0]']             
                                                                                                  
 dense_23 (Dense)               (None, 1, 1, 1024)   65536       ['dense_22[0][0]']               
                                                                                                  
 multiply_11 (Multiply)         (None, 14, 14, 1024  0           ['4e_identity_block_bn3[0][0]',  
                                )                                 'dense_23[0][0]']               
                                                                                                  
 4e_identity_block_add (Add)    (None, 14, 14, 1024  0           ['multiply_11[0][0]',            
                                )                                 '4d_identity_block_relu4[0][0]']
                                                                                                  
 4e_identity_block_relu4 (Activ  (None, 14, 14, 1024  0          ['4e_identity_block_add[0][0]']  
 ation)                         )                                                                 
                                                                                                  
 4f_identity_block_conv1 (Conv2  (None, 14, 14, 256)  262400     ['4e_identity_block_relu4[0][0]']
 D)                                                                                               
                                                                                                  
 4f_identity_block_bn1 (BatchNo  (None, 14, 14, 256)  1024       ['4f_identity_block_conv1[0][0]']
 rmalization)                                                                                     
                                                                                                  
 4f_identity_block_relu1 (Activ  (None, 14, 14, 256)  0          ['4f_identity_block_bn1[0][0]']  
 ation)                                                                                           
                                                                                                  
 4f_identity_block_conv2 (Conv2  (None, 14, 14, 256)  590080     ['4f_identity_block_relu1[0][0]']
 D)                                                                                               
                                                                                                  
 4f_identity_block_bn2 (BatchNo  (None, 14, 14, 256)  1024       ['4f_identity_block_conv2[0][0]']
 rmalization)                                                                                     
                                                                                                  
 4f_identity_block_relu2 (Activ  (None, 14, 14, 256)  0          ['4f_identity_block_bn2[0][0]']  
 ation)                                                                                           
                                                                                                  
 4f_identity_block_conv3 (Conv2  (None, 14, 14, 1024  263168     ['4f_identity_block_relu2[0][0]']
 D)                             )                                                                 
                                                                                                  
 4f_identity_block_bn3 (BatchNo  (None, 14, 14, 1024  4096       ['4f_identity_block_conv3[0][0]']
 rmalization)                   )                                                                 
                                                                                                  
 global_average_pooling2d_12 (G  (None, 1024)        0           ['4f_identity_block_bn3[0][0]']  
 lobalAveragePooling2D)                                                                           
                                                                                                  
 reshape_12 (Reshape)           (None, 1, 1, 1024)   0           ['global_average_pooling2d_12[0][
                                                                 0]']                             
                                                                                                  
 dense_24 (Dense)               (None, 1, 1, 64)     65536       ['reshape_12[0][0]']             
                                                                                                  
 dense_25 (Dense)               (None, 1, 1, 1024)   65536       ['dense_24[0][0]']               
                                                                                                  
 multiply_12 (Multiply)         (None, 14, 14, 1024  0           ['4f_identity_block_bn3[0][0]',  
                                )                                 'dense_25[0][0]']               
                                                                                                  
 4f_identity_block_add (Add)    (None, 14, 14, 1024  0           ['multiply_12[0][0]',            
                                )                                 '4e_identity_block_relu4[0][0]']
                                                                                                  
 4f_identity_block_relu4 (Activ  (None, 14, 14, 1024  0          ['4f_identity_block_add[0][0]']  
 ation)                         )                                                                 
                                                                                                  
 5a_conv_block_conv1 (Conv2D)   (None, 7, 7, 512)    524800      ['4f_identity_block_relu4[0][0]']
                                                                                                  
 5a_conv_block_bn1 (BatchNormal  (None, 7, 7, 512)   2048        ['5a_conv_block_conv1[0][0]']    
 ization)                                                                                         
                                                                                                  
 5a_conv_block_relu1 (Activatio  (None, 7, 7, 512)   0           ['5a_conv_block_bn1[0][0]']      
 n)                                                                                               
                                                                                                  
 5a_conv_block_conv2 (Conv2D)   (None, 7, 7, 512)    2359808     ['5a_conv_block_relu1[0][0]']    
                                                                                                  
 5a_conv_block_bn2 (BatchNormal  (None, 7, 7, 512)   2048        ['5a_conv_block_conv2[0][0]']    
 ization)                                                                                         
                                                                                                  
 5a_conv_block_relu2 (Activatio  (None, 7, 7, 512)   0           ['5a_conv_block_bn2[0][0]']      
 n)                                                                                               
                                                                                                  
 5a_conv_block_conv3 (Conv2D)   (None, 7, 7, 2048)   1050624     ['5a_conv_block_relu2[0][0]']    
                                                                                                  
 5a_conv_block_bn3 (BatchNormal  (None, 7, 7, 2048)  8192        ['5a_conv_block_conv3[0][0]']    
 ization)                                                                                         
                                                                                                  
 global_average_pooling2d_13 (G  (None, 2048)        0           ['5a_conv_block_bn3[0][0]']      
 lobalAveragePooling2D)                                                                           
                                                                                                  
 reshape_13 (Reshape)           (None, 1, 1, 2048)   0           ['global_average_pooling2d_13[0][
                                                                 0]']                             
                                                                                                  
 dense_26 (Dense)               (None, 1, 1, 128)    262144      ['reshape_13[0][0]']             
                                                                                                  
 dense_27 (Dense)               (None, 1, 1, 2048)   262144      ['dense_26[0][0]']               
                                                                                                  
 5a_conv_block_res_conv (Conv2D  (None, 7, 7, 2048)  2099200     ['4f_identity_block_relu4[0][0]']
 )                                                                                                
                                                                                                  
 multiply_13 (Multiply)         (None, 7, 7, 2048)   0           ['5a_conv_block_bn3[0][0]',      
                                                                  'dense_27[0][0]']               
                                                                                                  
 5a_conv_block_res_bn (BatchNor  (None, 7, 7, 2048)  8192        ['5a_conv_block_res_conv[0][0]'] 
 malization)                                                                                      
                                                                                                  
 5a_conv_block_add (Add)        (None, 7, 7, 2048)   0           ['multiply_13[0][0]',            
                                                                  '5a_conv_block_res_bn[0][0]']   
                                                                                                  
 5a_conv_block_relu4 (Activatio  (None, 7, 7, 2048)  0           ['5a_conv_block_add[0][0]']      
 n)                                                                                               
                                                                                                  
 5b_identity_block_conv1 (Conv2  (None, 7, 7, 512)   1049088     ['5a_conv_block_relu4[0][0]']    
 D)                                                                                               
                                                                                                  
 5b_identity_block_bn1 (BatchNo  (None, 7, 7, 512)   2048        ['5b_identity_block_conv1[0][0]']
 rmalization)                                                                                     
                                                                                                  
 5b_identity_block_relu1 (Activ  (None, 7, 7, 512)   0           ['5b_identity_block_bn1[0][0]']  
 ation)                                                                                           
                                                                                                  
 5b_identity_block_conv2 (Conv2  (None, 7, 7, 512)   2359808     ['5b_identity_block_relu1[0][0]']
 D)                                                                                               
                                                                                                  
 5b_identity_block_bn2 (BatchNo  (None, 7, 7, 512)   2048        ['5b_identity_block_conv2[0][0]']
 rmalization)                                                                                     
                                                                                                  
 5b_identity_block_relu2 (Activ  (None, 7, 7, 512)   0           ['5b_identity_block_bn2[0][0]']  
 ation)                                                                                           
                                                                                                  
 5b_identity_block_conv3 (Conv2  (None, 7, 7, 2048)  1050624     ['5b_identity_block_relu2[0][0]']
 D)                                                                                               
                                                                                                  
 5b_identity_block_bn3 (BatchNo  (None, 7, 7, 2048)  8192        ['5b_identity_block_conv3[0][0]']
 rmalization)                                                                                     
                                                                                                  
 global_average_pooling2d_14 (G  (None, 2048)        0           ['5b_identity_block_bn3[0][0]']  
 lobalAveragePooling2D)                                                                           
                                                                                                  
 reshape_14 (Reshape)           (None, 1, 1, 2048)   0           ['global_average_pooling2d_14[0][
                                                                 0]']                             
                                                                                                  
 dense_28 (Dense)               (None, 1, 1, 128)    262144      ['reshape_14[0][0]']             
                                                                                                  
 dense_29 (Dense)               (None, 1, 1, 2048)   262144      ['dense_28[0][0]']               
                                                                                                  
 multiply_14 (Multiply)         (None, 7, 7, 2048)   0           ['5b_identity_block_bn3[0][0]',  
                                                                  'dense_29[0][0]']               
                                                                                                  
 5b_identity_block_add (Add)    (None, 7, 7, 2048)   0           ['multiply_14[0][0]',            
                                                                  '5a_conv_block_relu4[0][0]']    
                                                                                                  
 5b_identity_block_relu4 (Activ  (None, 7, 7, 2048)  0           ['5b_identity_block_add[0][0]']  
 ation)                                                                                           
                                                                                                  
 5c_identity_block_conv1 (Conv2  (None, 7, 7, 512)   1049088     ['5b_identity_block_relu4[0][0]']
 D)                                                                                               
                                                                                                  
 5c_identity_block_bn1 (BatchNo  (None, 7, 7, 512)   2048        ['5c_identity_block_conv1[0][0]']
 rmalization)                                                                                     
                                                                                                  
 5c_identity_block_relu1 (Activ  (None, 7, 7, 512)   0           ['5c_identity_block_bn1[0][0]']  
 ation)                                                                                           
                                                                                                  
 5c_identity_block_conv2 (Conv2  (None, 7, 7, 512)   2359808     ['5c_identity_block_relu1[0][0]']
 D)                                                                                               
                                                                                                  
 5c_identity_block_bn2 (BatchNo  (None, 7, 7, 512)   2048        ['5c_identity_block_conv2[0][0]']
 rmalization)                                                                                     
                                                                                                  
 5c_identity_block_relu2 (Activ  (None, 7, 7, 512)   0           ['5c_identity_block_bn2[0][0]']  
 ation)                                                                                           
                                                                                                  
 5c_identity_block_conv3 (Conv2  (None, 7, 7, 2048)  1050624     ['5c_identity_block_relu2[0][0]']
 D)                                                                                               
                                                                                                  
 5c_identity_block_bn3 (BatchNo  (None, 7, 7, 2048)  8192        ['5c_identity_block_conv3[0][0]']
 rmalization)                                                                                     
                                                                                                  
 global_average_pooling2d_15 (G  (None, 2048)        0           ['5c_identity_block_bn3[0][0]']  
 lobalAveragePooling2D)                                                                           
                                                                                                  
 reshape_15 (Reshape)           (None, 1, 1, 2048)   0           ['global_average_pooling2d_15[0][
                                                                 0]']                             
                                                                                                  
 dense_30 (Dense)               (None, 1, 1, 128)    262144      ['reshape_15[0][0]']             
                                                                                                  
 dense_31 (Dense)               (None, 1, 1, 2048)   262144      ['dense_30[0][0]']               
                                                                                                  
 multiply_15 (Multiply)         (None, 7, 7, 2048)   0           ['5c_identity_block_bn3[0][0]',  
                                                                  'dense_31[0][0]']               
                                                                                                  
 5c_identity_block_add (Add)    (None, 7, 7, 2048)   0           ['multiply_15[0][0]',            
                                                                  '5b_identity_block_relu4[0][0]']
                                                                                                  
 5c_identity_block_relu4 (Activ  (None, 7, 7, 2048)  0           ['5c_identity_block_add[0][0]']  
 ation)                                                                                           
                                                                                                  
 avg_pool (AveragePooling2D)    (None, 1, 1, 2048)   0           ['5c_identity_block_relu4[0][0]']
                                                                                                  
 flatten (Flatten)              (None, 2048)         0           ['avg_pool[0][0]']               
                                                                                                  
 dropout (Dropout)              (None, 2048)         0           ['flatten[0][0]']                
                                                                                                  
 fc2 (Dense)                    (None, 4)            8196        ['dropout[0][0]']                
                                                                                                  
==================================================================================================
Total params: 26,110,852
Trainable params: 26,057,732
Non-trainable params: 53,120
_______________________________________________________________________________________
model.compile(optimizer='adam',
              loss='sparse_categorical_crossentropy',
              metrics=['accuracy'])

epochs = 30

history = model.fit(
    train_ds,
    validation_data=val_ds,
    epochs=epochs,
)
Epoch 1/30
57/57 [==============================] - 120s 2s/step - loss: 1.6071 - accuracy: 0.5022 - val_loss: 1.6805 - val_accuracy: 0.3628
Epoch 2/30
57/57 [==============================] - 101s 2s/step - loss: 1.1572 - accuracy: 0.5973 - val_loss: 2.9043 - val_accuracy: 0.3628
Epoch 3/30
57/57 [==============================] - 103s 2s/step - loss: 1.0106 - accuracy: 0.6438 - val_loss: 3.5882 - val_accuracy: 0.2655
Epoch 4/30
57/57 [==============================] - 104s 2s/step - loss: 0.6960 - accuracy: 0.7345 - val_loss: 3.8824 - val_accuracy: 0.2920
Epoch 5/30
57/57 [==============================] - 103s 2s/step - loss: 0.6722 - accuracy: 0.8009 - val_loss: 1.9140 - val_accuracy: 0.3805
Epoch 6/30
57/57 [==============================] - 102s 2s/step - loss: 0.5720 - accuracy: 0.8009 - val_loss: 1.3526 - val_accuracy: 0.5133
Epoch 7/30
57/57 [==============================] - 103s 2s/step - loss: 0.5234 - accuracy: 0.8252 - val_loss: 1.6950 - val_accuracy: 0.6195
Epoch 8/30
57/57 [==============================] - 103s 2s/step - loss: 0.5409 - accuracy: 0.8186 - val_loss: 1.0905 - val_accuracy: 0.5752
Epoch 9/30
57/57 [==============================] - 102s 2s/step - loss: 0.4960 - accuracy: 0.8230 - val_loss: 1.0269 - val_accuracy: 0.5664
Epoch 10/30
57/57 [==============================] - 106s 2s/step - loss: 0.3521 - accuracy: 0.8761 - val_loss: 0.7942 - val_accuracy: 0.7965
Epoch 11/30
57/57 [==============================] - 103s 2s/step - loss: 0.2162 - accuracy: 0.9204 - val_loss: 0.9084 - val_accuracy: 0.7168
Epoch 12/30
57/57 [==============================] - 103s 2s/step - loss: 0.3159 - accuracy: 0.9093 - val_loss: 1.8489 - val_accuracy: 0.7611
Epoch 13/30
57/57 [==============================] - 102s 2s/step - loss: 0.2727 - accuracy: 0.8960 - val_loss: 2.2825 - val_accuracy: 0.7345
Epoch 14/30
57/57 [==============================] - 104s 2s/step - loss: 0.1902 - accuracy: 0.9381 - val_loss: 1.1050 - val_accuracy: 0.7257
Epoch 15/30
57/57 [==============================] - 105s 2s/step - loss: 0.2085 - accuracy: 0.9292 - val_loss: 0.3290 - val_accuracy: 0.9027
Epoch 16/30
57/57 [==============================] - 105s 2s/step - loss: 0.1697 - accuracy: 0.9358 - val_loss: 1.0470 - val_accuracy: 0.7965
Epoch 17/30
57/57 [==============================] - 106s 2s/step - loss: 0.1955 - accuracy: 0.9381 - val_loss: 9.2690 - val_accuracy: 0.3540
Epoch 18/30
57/57 [==============================] - 103s 2s/step - loss: 0.3337 - accuracy: 0.8960 - val_loss: 1.6920 - val_accuracy: 0.7699
Epoch 19/30
57/57 [==============================] - 103s 2s/step - loss: 0.1869 - accuracy: 0.9292 - val_loss: 9.7153 - val_accuracy: 0.3628
Epoch 20/30
57/57 [==============================] - 103s 2s/step - loss: 0.2506 - accuracy: 0.9049 - val_loss: 0.9142 - val_accuracy: 0.7876
Epoch 21/30
57/57 [==============================] - 107s 2s/step - loss: 0.1941 - accuracy: 0.9358 - val_loss: 0.7740 - val_accuracy: 0.8142
Epoch 22/30
57/57 [==============================] - 103s 2s/step - loss: 0.0971 - accuracy: 0.9690 - val_loss: 0.5248 - val_accuracy: 0.8230
Epoch 23/30
57/57 [==============================] - 104s 2s/step - loss: 0.0549 - accuracy: 0.9845 - val_loss: 2.8425 - val_accuracy: 0.6637
Epoch 24/30
57/57 [==============================] - 107s 2s/step - loss: 0.0251 - accuracy: 0.9934 - val_loss: 0.1835 - val_accuracy: 0.9292
Epoch 25/30
57/57 [==============================] - 110s 2s/step - loss: 0.0131 - accuracy: 1.0000 - val_loss: 0.2147 - val_accuracy: 0.9469
Epoch 26/30
57/57 [==============================] - 103s 2s/step - loss: 0.0043 - accuracy: 1.0000 - val_loss: 0.1484 - val_accuracy: 0.9469
Epoch 27/30
57/57 [==============================] - 106s 2s/step - loss: 0.0029 - accuracy: 1.0000 - val_loss: 0.1338 - val_accuracy: 0.9558
Epoch 28/30
57/57 [==============================] - 107s 2s/step - loss: 0.0013 - accuracy: 1.0000 - val_loss: 0.1428 - val_accuracy: 0.9469
Epoch 29/30
57/57 [==============================] - 108s 2s/step - loss: 6.1017e-04 - accuracy: 1.0000 - val_loss: 0.1412 - val_accuracy: 0.9469
Epoch 30/30
57/57 [==============================] - 111s 2s/step - loss: 5.0776e-04 - accuracy: 1.0000 - val_loss: 0.1457 - val_accuracy: 0.9381
# 获取实际训练轮数
actual_epochs = len(history.history['accuracy'])

acc = history.history['accuracy']
val_acc = history.history['val_accuracy']

loss = history.history['loss']
val_loss = history.history['val_loss']

epochs_range = range(actual_epochs)

plt.figure(figsize=(12, 4))

# 绘制准确率
plt.subplot(1, 2, 1)
plt.plot(epochs_range, acc, label='Training Accuracy')
plt.plot(epochs_range, val_acc, label='Validation Accuracy')
plt.legend(loc='lower right')
plt.title('Training and Validation Accuracy')

# 绘制损失
plt.subplot(1, 2, 2)
plt.plot(epochs_range, loss, label='Training Loss')
plt.plot(epochs_range, val_loss, label='Validation Loss')
plt.legend(loc='upper right')
plt.title('Training and Validation Loss')

plt.show()

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2252739.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

js高级-ajax封装和跨域

ajax简介及相关知识 原生ajax AJAX 简介 AJAX 全称为 Asynchronous JavaScript And XML,就是异步的 JS 和 XML。 通过 AJAX 可以在浏览器中向服务器发送异步请求,最大的优势:无刷新获取数据。 按需请求,可以提高网站的性能 AJ…

【AI】Sklearn

长期更新,建议关注、收藏、点赞。 友情链接: AI中的数学_线代微积分概率论最优化 Python numpy_pandas_matplotlib_spicy 建议路线:机器学习->深度学习->强化学习 目录 预处理模型选择分类实例: 二分类比赛 网格搜索实例&…

如何让控件始终处于父容器的居中位置(父容器可任意改变大小)

前言: 大家好,我是上位机马工,硕士毕业4年年入40万,目前在一家自动化公司担任软件经理,从事C#上位机软件开发8年以上!我们在C#开发winform程序的时候,有时候需要将一个控件居中显示&#xff0c…

Python 调用 Umi-OCR API 批量识别图片/PDF文档数据

目录 一、需求分析 二、方案设计(概要/详细) 三、技术选型 四、OCR 测试 Demo 五、批量文件识别完整代码实现 六、总结 一、需求分析 市场部同事进行采购或给客户报价时,往往基于过往采购合同数据,给出现在采购或报价的金额…

【QT】背景,安装和介绍

TOC 目录 背景 GUI技术 QT的安装 使用流程 QT程序介绍 main.cpp​编辑 Wiget.h Widget.cpp form file .pro文件 临时文件 C作为一门比较古老的语言,在人们的认知里始终是以底层,复杂和高性能著称,所以在很多高性能需求的场景之下…

Linux内核编译流程(Ubuntu24.04+Linux Kernel 6.8.12)

万恶的拯救者,使用Ubuntu没有声音,必须要自己修改一下Linux内核中的相关驱动逻辑才可以,所以被迫学习怎么修改内核&编译内核,记录如下 准备工作 下载Linux源码:在Linux发布页下载并使用gpg签名验证 即&#xff1a…

【阅读笔记】Android广播的处理流程

关于Android的解析,有很多优质内容,看了后记录一下阅读笔记,也是一种有意义的事情, 今天就看看“那个写代码的”这位大佬关于广播的梳理, https://blog.csdn.net/a572423926/category_11509429.html https://blog.c…

linux下Qt程序部署教程

文章目录 [toc]1、概述2、静态编译安装Qt1.1 安装依赖1.2 静态编译1.3 报错1.4 添加环境变量1.5 下载安装QtCreator 3、配置linuxdeployqt环境1.1 在线安装依赖1.2 使用linuxdeployqt提供的程序1.3 编译安装linuxdeployqt 4、使用linuxdeployqt打包依赖1.1 linuxdeployqt使用选…

【PHP】部署和发布PHP网站到IIS服务器

欢迎来到《小5讲堂》 这是《PHP》系列文章,每篇文章将以博主理解的角度展开讲解。 温馨提示:博主能力有限,理解水平有限,若有不对之处望指正! 目录 前言安装PHP稳定版本线程安全版解压使用 PHP配置配置文件扩展文件路径…

视觉经典神经网络学习01_CNN(1)

一、概述 卷积神经网络(Convolutional Neural Network,CNN)是一种专门用于处理具有网格状结构数据的深度学习模型。最初,CNN主要应用于计算机视觉任务,但它的成功启发了在其他领域应用,如自然语言处理等。…

【golang】单元测试,以及出现undefined时的解决方案

单元测试 要对某一方法进行测试时,例如如下这一简单减法函数,选中函数名后右键->转到->测试 1)Empty test file 就是一个空文件,我们可以自己写测试的逻辑 但是直接点绿色箭头运行会出问题: 找不到包。我们要在…

DVWA靶场通关——DOM型XSS漏洞

一、DOM型XSS攻击概述 DOM型XSS(DOM-based Cross-Site Scripting,DOM XSS)是一种跨站脚本攻击(XSS)的变种,它与传统的反射型XSS(Reflected XSS)或存储型XSS(Stored XSS&a…

【Unity 动画】设置跟运动(Apply Root)模型跟着动画产生位移

一、导入的动画本身必须有跟随动画产生位移或者旋转的效果 二、导入Unity后 在Unity中,根运动(Root Motion)是指动画中角色根节点的移动和旋转。根节点通常是角色的根骨骼(Root Bone),它决定了角色的整体…

Spring AI 框架介绍

Spring AI是一个面向人工智能工程的应用框架。它的目标是将Spring生态系统的设计原则(如可移植性和模块化设计)应用于AI领域,并推广使用pojo作为AI领域应用的构建模块。 概述 Spring AI 现在(2024/12)已经支持语言,图像&#xf…

C++小问题

怎么分辨const修饰的是谁 是限定谁不能被改变的? 在C中,const关键字的用途和位置非常关键,它决定了谁不能被修改。const可以修饰变量、指针、引用等不同的对象,并且具体的作用取决于const的修饰位置。理解const的规则能够帮助我们…

近几年,GIS专业的五类就业方向!

近二十几年来,地理信息科学毕业生的就业方向在不断发生变化。 早期的地理信息科学技术主要应用于政府部门,因此学生就业主要在高校、交通运输、规划勘测设计、国土、矿业、水利电力、通讯、农林、城市建设、旅游等国家政府部门或事业单位。 随着地理信…

【Maven】继承和聚合

5. Maven的继承和聚合 5.1 什么是继承 Maven 的依赖传递机制可以一定程度上简化 POM 的配置,但这仅限于存在依赖关系的项目或模块中。当一个项目的多个模块都依赖于相同 jar 包的相同版本,且这些模块之间不存在依赖关系,这就导致同一个依赖…

2、Three.js初步认识场景Scene、相机Camera、渲染器Renderer三要素

三要素之间关系: 有了虚拟场景Scene,相机录像Camera,在相机小屏幕上看到的Renderer Scene当前空间 Mesh人在场景 Camera相机录像 Renderer显示器上 首先先描述下Scene: 这个场景为三要素之一,一切需要展示的东西都需…

工厂方法模式的理解和实践

在软件开发中,设计模式是一种经过验证的解决特定问题的通用方案。工厂方法模式(Factory Method Pattern)是创建型设计模式之一,它提供了一种创建对象的接口,但由子类决定要实例化的类是哪一个。工厂方法让类的实例化推…

Vue教程|搭建vue项目|Vue-CLI2.x 模板脚手架

一、项目构建环境准备 在构建Vue项目之前,需要搭建Node环境以及Vue-CLI脚手架,由于本篇文章为上一篇文章的补充,也是为了给大家分享更为完整的搭建vue项目方式,所以环境准备部分采用Vue教程|搭建vue项目|V…