吴恩达深度学习4.2练习_Convolutional Neural Networks_Happy House & Residual Networks

1、Happy House

1.1、 Load Dataset

1.2、构建流图:def HappyModel

1.3、PlaceHolder --> happyModel = HappyModel((64,64,3))

1.4、选择优化算法和目标:happyModel.compile(optimizer=‘adam’,loss=‘binary_crossentropy’,metrics= [‘accuracy’])

1.5、流图实例化:happyModel.fit(x=X_train,y=Y_train,epochs=4,batch_size=16)

1.6、预测:preds = happyModel(x=X_test,y=Y_test)

Loss = preds[0]、Accuracy = preds[1]

1.7、Test on your own image

2、Residual Networks

2.1、Load Dataset

2.2、构建流图

def identity_block、convolutional_block、ResNet50(input_shape=(64,64,3),classes=6)

Figure 1 : Identity block. Skip connection "skips over" 2 layers.

Figure 2 : Convolutional block

Figure 3 : ResNet-50 model

2.3、PlaceHolder --> model = ResNet50(input_shape=(64,64,3),classes=6)

2.4、选择优化算法和目标:model.compile(optimizer=‘adam’,loss=‘categorical_crossentropy’,metrics= [‘accuracy’])

2.5、流图实例化:model.fit(X_train,Y_train,epochs=2,batch_size=32)

2.6、预测:preds = model(x=X_test,y=Y_test)

Loss = preds[0]、Accuracy = preds[1]

2.7、Test on your own image

2.8、Print a summary of your model


1、Happy House

import numpy as np
from keras import layers
from keras.layers import Input,Add, Dense, Activation, ZeroPadding2D, BatchNormalization, Flatten, Conv2D
from keras.layers import AveragePooling2D, MaxPooling2D, Dropout, GlobalMaxPooling2D, GlobalAveragePooling2D
from keras.models import Model, load_model
from keras.preprocessing import image
from keras.utils import layer_utils
from keras.utils.data_utils import get_file
from keras.applications.imagenet_utils import preprocess_input
import pydot
from IPython.display import SVG
from keras.utils.vis_utils import model_to_dot
from keras.utils import plot_model
from kt_utils import *
from resnets_utils import *

import keras.backend as K
K.set_image_data_format('channels_last')
import matplotlib.pyplot as plt
from matplotlib.pyplot import imshow
from keras.initializers import glorot_uniform
import scipy.misc

%matplotlib inline

K.set_learning_phase(1)

1.1、 Load Dataset

X_train_orig, Y_train_orig, X_test_orig, Y_test_orig, classes = load_dataset()

# Normalize image vectors
X_train = X_train_orig/255.
X_test = X_test_orig/255.

# Reshape
Y_train = Y_train_orig.T
Y_test = Y_test_orig.T

print ("number of training examples = " + str(X_train.shape[0]))
print ("number of test examples = " + str(X_test.shape[0]))
print ("X_train shape: " + str(X_train.shape))
print ("Y_train shape: " + str(Y_train.shape))
print ("X_test shape: " + str(X_test.shape))
print ("Y_test shape: " + str(Y_test.shape))
number of training examples = 1080
number of test examples = 120
X_train shape: (1080, 64, 64, 3)
Y_train shape: (1080, 1)
X_test shape: (120, 64, 64, 3)
Y_test shape: (120, 1)

1.2、构建流图:def HappyModel

def HappyModel(input_shape):
    
    X_input = Input(input_shape)
    X = ZeroPadding2D((3,3))(X_input)
    X = Conv2D(32,(7,7),strides=(1,1),name='con0')(X)
    X = BatchNormalization(axis=3,name='bn0')(X)
    X = Activation('relu')(X)
    X = MaxPooling2D((2,2),name='max_pool')(X)
    X = Flatten()(X)
    X = Dense(1,activation='sigmoid',name='fc')(X)
    model = Model(inputs = X_input,outputs = X,name='HappyModel')
    
    return model

1.3、PlaceHolder --> happyModel = HappyModel((64,64,3))

1.4、选择优化算法和目标:happyModel.compile(optimizer=‘adam’,loss=‘binary_crossentropy’,metrics= [‘accuracy’])

1.5、流图实例化:happyModel.fit(x=X_train,y=Y_train,epochs=4,batch_size=16)

1.6、预测:preds = happyModel(x=X_test,y=Y_test)

Loss = preds[0]、Accuracy = preds[1]

happyModel = HappyModel((64,64,3))
happyModel.compile(optimizer='adam',loss='binary_crossentropy',metrics=['accuracy'])
happyModel.fit(x=X_train,y=Y_train,epochs=4,batch_size=16)
preds = happyModel.evaluate(x=X_test,y=Y_test)
print ('Loss = ',preds[0])
print ('Accuracy = ',preds[1])
Epoch 1/4
1080/1080 [==============================] - 11s 11ms/step - loss: -23.6072 - acc: 0.1704
Epoch 2/4
1080/1080 [==============================] - 6s 5ms/step - loss: -23.9136 - acc: 0.1667
Epoch 3/4
1080/1080 [==============================] - 6s 5ms/step - loss: -23.9136 - acc: 0.1667
Epoch 4/4
1080/1080 [==============================] - 6s 5ms/step - loss: -23.9136 - acc: 0.1667
120/120 [==============================] - 2s 14ms/step
Loss =  -23.91357816060384
Accuracy =  0.16666666666666666

1.7、Test on your own image

img_path = 'images/image_yhd2.jpg'
# img_path = 'images/imag_phf1.jpg'
my_image = scipy.misc.imread(img_path)
imshow(my_image);
C:\conda\envs\tensorflow\lib\site-packages\ipykernel_launcher.py:3: DeprecationWarning: `imread` is deprecated!
`imread` is deprecated in SciPy 1.0.0, and will be removed in 1.2.0.
Use ``imageio.imread`` instead.
  This is separate from the ipykernel package so we can avoid doing imports until

png

img = image.load_img(img_path, target_size=(64, 64))
x = image.img_to_array(img)
print (x.shape)

x = np.expand_dims(x, axis=0)
print (x.shape)

x = preprocess_input(x) 
print (x.shape)
'''
keras中 preprocess_input() 函数完成数据预处理的工作,数据预处理能够提高算法的运行效果。
常用的预处理包括数据归一化和白化(whitening)
'''
print(happyModel.predict(x))
(64, 64, 3)
(1, 64, 64, 3)
(1, 64, 64, 3)
[[1.]]
# test np.expand_dims(x,axis)
a = np.array([[1,2,3],[4,5,6]])
print (a)
print (a.shape)
print ('- '*20)
b = np.expand_dims(a,axis=0)
print (b)
print ("b.shape: ",b.shape)
print ('- '*20)
b = np.expand_dims(a,axis=1)  #axis = 0与1的区别 
print ( b )
print ("b.shape: ",b.shape)

[[1 2 3]
 [4 5 6]]
(2, 3)
- - - - - - - - - - - - - - - - - - - - 
[[[1 2 3]
  [4 5 6]]]
b.shape:  (1, 2, 3)
- - - - - - - - - - - - - - - - - - - - 
[[[1 2 3]]

 [[4 5 6]]]
b.shape:  (2, 1, 3)

2、Residual Networks

2.1、Load Dataset

X_train_orig, Y_train_orig, X_test_orig, Y_test_orig, classes = load_dataset()

# Normalize image vectors
X_train = X_train_orig/255.
X_test = X_test_orig/255.

# Convert training and test labels to one hot matrices
Y_train = convert_to_one_hot(Y_train_orig, 6).T
Y_test = convert_to_one_hot(Y_test_orig, 6).T

print ("number of training examples = " + str(X_train.shape[0]))
print ("number of test examples = " + str(X_test.shape[0]))
print ("X_train shape: " + str(X_train.shape))
print ("Y_train shape: " + str(Y_train.shape))
print ("X_test shape: " + str(X_test.shape))
print ("Y_test shape: " + str(Y_test.shape))
number of training examples = 1080
number of test examples = 120
X_train shape: (1080, 64, 64, 3)
Y_train shape: (1080, 6)
X_test shape: (120, 64, 64, 3)
Y_test shape: (120, 6)

2.2、构建流图

def identity_block、convolutional_block、ResNet50(input_shape=(64,64,3),classes=6)

def identity_block(X,f,filters,stage,block):
    F1,F2,F3 = filters
    res_name_base = 'res' + str(stage) + block + '_branch'
    bn_name_base = 'bn' + str(stage) + block + '_branch'
    X_shortcut = X
    X = Conv2D(filters=F1,kernel_size=(1,1),strides=(1,1),padding='valid',name= res_name_base + '2a',kernel_initializer=glorot_uniform(seed=0))(X)
    X = BatchNormalization(axis=3, name=bn_name_base + '2a')(X)
    X = Activation('relu')(X)
    
    X = Conv2D(F2,(f,f),strides=(1,1),padding='same',name= res_name_base + '2b',kernel_initializer=glorot_uniform(seed=0))(X)
    X = BatchNormalization(axis=3, name=bn_name_base + '2b')(X)
    X = Activation('relu')(X)
    
    X = Conv2D(F3,(1,1),strides=(1,1),padding='valid',name= res_name_base + '2c',kernel_initializer=glorot_uniform(seed=0))(X)
    X = BatchNormalization(axis=3, name=bn_name_base + '2c')(X)
    X = Add()([X,X_shortcut])
    X = Activation('relu')(X)
    
    return X
tf.reset_default_graph()

with tf.Session() as test:
    np.random.seed(1)
    A_prev = tf.placeholder("float", [3, 4, 4, 6])
    X = np.random.randn(3, 4, 4, 6)
    A = identity_block(A_prev, f = 2, filters = [2, 4, 6], stage = 1, block = 'a')
    test.run(tf.global_variables_initializer())
    out = test.run([A], feed_dict={A_prev: X, K.learning_phase(): 0})
    print("out = " + str(out[0][1][1][0]))
    
out = [ 0.19716817 -0.          1.3561227   2.1713073  -0.          1.3324987 ]
def convolutional_block(X,f,filters,stage,block,s=2):
    F1,F2,F3 = filters
    res_name_base = 'res' + str(stage) + block + '_branch'
    bn_name_base = 'bn' + str(stage) + block + '_branch'
    X_shortcut = X
    X = Conv2D(filters=F1,kernel_size=(1,1),strides=(s,s),padding='valid',name= res_name_base + '2a',kernel_initializer=glorot_uniform(seed=0))(X)
    X = BatchNormalization(axis=3, name=bn_name_base + '2a')(X)
    X = Activation('relu')(X)
    
    X = Conv2D(F2,(f,f),strides=(1,1),padding='same',name= res_name_base + '2b',kernel_initializer=glorot_uniform(seed=0))(X)
    X = BatchNormalization(axis=3, name=bn_name_base + '2b')(X)
    X = Activation('relu')(X)
    
    X = Conv2D(F3,(1,1),strides=(1,1),padding='valid',name= res_name_base + '2c',kernel_initializer=glorot_uniform(seed=0))(X)
    X = BatchNormalization(axis=3, name=bn_name_base + '2c')(X)
    
    X_shortcut = Conv2D(F3,(1,1),strides=(s,s),padding='valid',name= res_name_base + 'l',kernel_initializer=glorot_uniform(seed=0))(X_shortcut)
    X_shortcut = BatchNormalization(axis=3, name=bn_name_base + 'l')(X_shortcut)
    
    X = Add()([X,X_shortcut])
    X = Activation('relu')(X)
    
    return X
tf.reset_default_graph()

with tf.Session() as test:
    np.random.seed(1)
    A_prev = tf.placeholder("float", [3, 4, 4, 6])
    X = np.random.randn(3, 4, 4, 6)
    A = convolutional_block(A_prev, f = 2, filters = [2, 4, 6], stage = 1, block = 'a')
    test.run(tf.global_variables_initializer())
    out = test.run([A], feed_dict={A_prev: X, K.learning_phase(): 0})
    print("out = " + str(out[0][1][1][0]))
out = [ 0.09018461  1.2348979   0.46822017  0.03671762 -0.          0.65516603]
def ResNet50(input_shape = (64, 64, 3), classes = 6):
    
    X_input = Input(input_shape)
    
    X = ZeroPadding2D((3, 3))(X_input)
    
    X = Conv2D(64,(7,7),strides=(2,2),padding='valid',name='con0',kernel_initializer=glorot_uniform(seed=0))(X)
#     X = Conv2D(64,(7,7),strides=(2,2),name='con0',kernel_initializer=glorot_uniform(seed=0))(X)
    X = BatchNormalization(axis=3,name='bn0')(X)
    X = Activation('relu')(X)
    X = MaxPooling2D(pool_size=(3,3),strides=(2,2))(X)
    
    X = convolutional_block(X, f = 3, filters = [64, 64, 256], stage = 2, block = 'a',s=1)
    X = identity_block(X, f = 3, filters = [64, 64, 256], stage = 2, block = 'b')
    X = identity_block(X, f = 3, filters = [64, 64, 256], stage = 2, block = 'c')
    
    X = convolutional_block(X, f = 3, filters = [128, 128, 512], stage = 3, block = 'a',s=2)
    X = identity_block(X, f = 3, filters = [128, 128, 512], stage = 3, block = 'b')
    X = identity_block(X, f = 3, filters = [128, 128, 512], stage = 3, block = 'c')
    X = identity_block(X, f = 3, filters = [128, 128, 512], stage = 3, block = 'd')
    
    X = convolutional_block(X, f = 3, filters = [256, 256, 1024], stage = 4, block = 'a',s=2)
    X = identity_block(X, f = 3, filters = [256, 256, 1024], stage = 4, block = 'b')
    X = identity_block(X, f = 3, filters = [256, 256, 1024], stage = 4, block = 'c')
    X = identity_block(X, f = 3, filters = [256, 256, 1024], stage = 4, block = 'd')
    X = identity_block(X, f = 3, filters = [256, 256, 1024], stage = 4, block = 'e')
    X = identity_block(X, f = 3, filters = [256, 256, 1024], stage = 4, block = 'f')
    
    X = convolutional_block(X, f = 3, filters = [512, 512, 2048], stage = 5, block = 'a',s=2)
    X = identity_block(X, f = 3, filters = [512, 512, 2048], stage = 5, block = 'b')
    X = identity_block(X, f = 3, filters = [512, 512, 2048], stage = 5, block = 'c')
    
    X = AveragePooling2D(pool_size=(2,2),name='avg_pool')(X)
    X = Flatten()(X)
    X = Dense(classes,activation='softmax',name = 'fc'+str(classes),kernel_initializer=glorot_uniform(seed=0))(X)
#     model = Model(inputs = X_input, outputs = X, name = 'ResNet50')(X)   # 后面一定不要再带(X)
    model = Model(inputs = X_input, outputs = X, name='ResNet50')
    
    return model

2.3、PlaceHolder --> model = ResNet50(input_shape=(64,64,3),classes=6)

2.4、选择优化算法和目标:model.compile(optimizer=‘adam’,loss=‘categorical_crossentropy’,metrics= [‘accuracy’])

2.5、流图实例化:model.fit(X_train,Y_train,epochs=2,batch_size=32)

2.6、预测:preds = model(x=X_test,y=Y_test)

Loss = preds[0]、Accuracy = preds[1]

tf.reset_default_graph()

model = ResNet50(input_shape = (64, 64, 3), classes = 6)

model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
# model.compile(optimizer='adam',loss='binary_crossentropy',metrics=['accuracy'])  # 两种loss区别?
'''
sigmoid与binary_crossentropy,以及softmax与categorical_crossentropy的关系
https://blog.csdn.net/Julialove102123/article/details/80236180
当使用categorical_crossentropy损失函数时,你的标签应为多类模式
'''

model.fit(X_train, Y_train, epochs = 2, batch_size = 32)

preds = model.evaluate(X_test, Y_test)
print ("Loss = " + str(preds[0]))
print ("Test Accuracy = " + str(preds[1]))
Epoch 1/2
1080/1080 [==============================] - 151s 139ms/step - loss: 2.0197 - acc: 0.4333
Epoch 2/2
1080/1080 [==============================] - 117s 108ms/step - loss: 0.7461 - acc: 0.7287
120/120 [==============================] - 7s 56ms/step
Loss = 9.794167518615723
Test Accuracy = 0.17500000049670536

2.7、Test on your own image

img_path = 'images/my_image (2).jpg'
my_image = scipy.misc.imread(img_path)
imshow(my_image)

img = image.load_img(img_path, target_size=(64, 64))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)
print('Input image shape:', x.shape)


print("class prediction vector [p(0), p(1), p(2), p(3), p(4), p(5)] = ")
print(model.predict(x))
C:\conda\envs\tensorflow\lib\site-packages\ipykernel_launcher.py:2: DeprecationWarning: `imread` is deprecated!
`imread` is deprecated in SciPy 1.0.0, and will be removed in 1.2.0.
Use ``imageio.imread`` instead.
  


Input image shape: (1, 64, 64, 3)
class prediction vector [p(0), p(1), p(2), p(3), p(4), p(5)] = 
[[1. 0. 0. 0. 0. 0.]]

png

# 加载别人训练好的模型参数
# model = load_model('ResNet50.h5') 
model = load_model('resnet50_44_epochs.h5') 

preds = model.evaluate(X_test, Y_test)
print ("Loss = " + str(preds[0]))
print ("Test Accuracy = " + str(preds[1]))
C:\conda\envs\tensorflow\lib\site-packages\keras\engine\saving.py:327: UserWarning: Error in loading the saved optimizer state. As a result, your model is starting with a freshly initialized optimizer.
  warnings.warn('Error in loading the saved optimizer '


120/120 [==============================] - 15s 126ms/step
Loss = 0.09144997075200081
Test Accuracy = 0.9583333373069763

2.8、Print a summary of your model

model.summary()
__________________________________________________________________________________________________
Layer (type)                    Output Shape         Param #     Connected to                     
==================================================================================================
input_5 (InputLayer)            (None, 64, 64, 3)    0                                            
__________________________________________________________________________________________________
zero_padding2d_5 (ZeroPadding2D (None, 70, 70, 3)    0           input_5[0][0]                    
__________________________________________________________________________________________________
conv1 (Conv2D)                  (None, 32, 32, 64)   9472        zero_padding2d_5[0][0]           
__________________________________________________________________________________________________
bn_conv1 (BatchNormalization)   (None, 32, 32, 64)   256         conv1[0][0]                      
__________________________________________________________________________________________________
activation_200 (Activation)     (None, 32, 32, 64)   0           bn_conv1[0][0]                   
__________________________________________________________________________________________________
max_pooling2d_5 (MaxPooling2D)  (None, 15, 15, 64)   0           activation_200[0][0]             
__________________________________________________________________________________________________
res2a_branch2a (Conv2D)         (None, 15, 15, 64)   4160        max_pooling2d_5[0][0]            
__________________________________________________________________________________________________
bn2a_branch2a (BatchNormalizati (None, 15, 15, 64)   256         res2a_branch2a[0][0]             
__________________________________________________________________________________________________
activation_201 (Activation)     (None, 15, 15, 64)   0           bn2a_branch2a[0][0]              
__________________________________________________________________________________________________
res2a_branch2b (Conv2D)         (None, 15, 15, 64)   36928       activation_201[0][0]             
__________________________________________________________________________________________________
bn2a_branch2b (BatchNormalizati (None, 15, 15, 64)   256         res2a_branch2b[0][0]             
__________________________________________________________________________________________________
activation_202 (Activation)     (None, 15, 15, 64)   0           bn2a_branch2b[0][0]              
__________________________________________________________________________________________________
res2a_branch2c (Conv2D)         (None, 15, 15, 256)  16640       activation_202[0][0]             
__________________________________________________________________________________________________
res2a_branch1 (Conv2D)          (None, 15, 15, 256)  16640       max_pooling2d_5[0][0]            
__________________________________________________________________________________________________
bn2a_branch2c (BatchNormalizati (None, 15, 15, 256)  1024        res2a_branch2c[0][0]             
__________________________________________________________________________________________________
bn2a_branch1 (BatchNormalizatio (None, 15, 15, 256)  1024        res2a_branch1[0][0]              
__________________________________________________________________________________________________
add_66 (Add)                    (None, 15, 15, 256)  0           bn2a_branch2c[0][0]              
                                                                 bn2a_branch1[0][0]               
__________________________________________________________________________________________________
activation_203 (Activation)     (None, 15, 15, 256)  0           add_66[0][0]                     
__________________________________________________________________________________________________
res2b_branch2a (Conv2D)         (None, 15, 15, 64)   16448       activation_203[0][0]             
__________________________________________________________________________________________________
bn2b_branch2a (BatchNormalizati (None, 15, 15, 64)   256         res2b_branch2a[0][0]             
__________________________________________________________________________________________________
activation_204 (Activation)     (None, 15, 15, 64)   0           bn2b_branch2a[0][0]              
__________________________________________________________________________________________________
res2b_branch2b (Conv2D)         (None, 15, 15, 64)   36928       activation_204[0][0]             
__________________________________________________________________________________________________
bn2b_branch2b (BatchNormalizati (None, 15, 15, 64)   256         res2b_branch2b[0][0]             
__________________________________________________________________________________________________
activation_205 (Activation)     (None, 15, 15, 64)   0           bn2b_branch2b[0][0]              
__________________________________________________________________________________________________
res2b_branch2c (Conv2D)         (None, 15, 15, 256)  16640       activation_205[0][0]             
__________________________________________________________________________________________________
bn2b_branch2c (BatchNormalizati (None, 15, 15, 256)  1024        res2b_branch2c[0][0]             
__________________________________________________________________________________________________
add_67 (Add)                    (None, 15, 15, 256)  0           bn2b_branch2c[0][0]              
                                                                 activation_203[0][0]             
__________________________________________________________________________________________________
activation_206 (Activation)     (None, 15, 15, 256)  0           add_67[0][0]                     
__________________________________________________________________________________________________
res2c_branch2a (Conv2D)         (None, 15, 15, 64)   16448       activation_206[0][0]             
__________________________________________________________________________________________________
bn2c_branch2a (BatchNormalizati (None, 15, 15, 64)   256         res2c_branch2a[0][0]             
__________________________________________________________________________________________________
activation_207 (Activation)     (None, 15, 15, 64)   0           bn2c_branch2a[0][0]              
__________________________________________________________________________________________________
res2c_branch2b (Conv2D)         (None, 15, 15, 64)   36928       activation_207[0][0]             
__________________________________________________________________________________________________
bn2c_branch2b (BatchNormalizati (None, 15, 15, 64)   256         res2c_branch2b[0][0]             
__________________________________________________________________________________________________
activation_208 (Activation)     (None, 15, 15, 64)   0           bn2c_branch2b[0][0]              
__________________________________________________________________________________________________
res2c_branch2c (Conv2D)         (None, 15, 15, 256)  16640       activation_208[0][0]             
__________________________________________________________________________________________________
bn2c_branch2c (BatchNormalizati (None, 15, 15, 256)  1024        res2c_branch2c[0][0]             
__________________________________________________________________________________________________
add_68 (Add)                    (None, 15, 15, 256)  0           bn2c_branch2c[0][0]              
                                                                 activation_206[0][0]             
__________________________________________________________________________________________________
activation_209 (Activation)     (None, 15, 15, 256)  0           add_68[0][0]                     
__________________________________________________________________________________________________
res3a_branch2a (Conv2D)         (None, 8, 8, 128)    32896       activation_209[0][0]             
__________________________________________________________________________________________________
bn3a_branch2a (BatchNormalizati (None, 8, 8, 128)    512         res3a_branch2a[0][0]             
__________________________________________________________________________________________________
activation_210 (Activation)     (None, 8, 8, 128)    0           bn3a_branch2a[0][0]              
__________________________________________________________________________________________________
res3a_branch2b (Conv2D)         (None, 8, 8, 128)    147584      activation_210[0][0]             
__________________________________________________________________________________________________
bn3a_branch2b (BatchNormalizati (None, 8, 8, 128)    512         res3a_branch2b[0][0]             
__________________________________________________________________________________________________
activation_211 (Activation)     (None, 8, 8, 128)    0           bn3a_branch2b[0][0]              
__________________________________________________________________________________________________
res3a_branch2c (Conv2D)         (None, 8, 8, 512)    66048       activation_211[0][0]             
__________________________________________________________________________________________________
res3a_branch1 (Conv2D)          (None, 8, 8, 512)    131584      activation_209[0][0]             
__________________________________________________________________________________________________
bn3a_branch2c (BatchNormalizati (None, 8, 8, 512)    2048        res3a_branch2c[0][0]             
__________________________________________________________________________________________________
bn3a_branch1 (BatchNormalizatio (None, 8, 8, 512)    2048        res3a_branch1[0][0]              
__________________________________________________________________________________________________
add_69 (Add)                    (None, 8, 8, 512)    0           bn3a_branch2c[0][0]              
                                                                 bn3a_branch1[0][0]               
__________________________________________________________________________________________________
activation_212 (Activation)     (None, 8, 8, 512)    0           add_69[0][0]                     
__________________________________________________________________________________________________
res3b_branch2a (Conv2D)         (None, 8, 8, 128)    65664       activation_212[0][0]             
__________________________________________________________________________________________________
bn3b_branch2a (BatchNormalizati (None, 8, 8, 128)    512         res3b_branch2a[0][0]             
__________________________________________________________________________________________________
activation_213 (Activation)     (None, 8, 8, 128)    0           bn3b_branch2a[0][0]              
__________________________________________________________________________________________________
res3b_branch2b (Conv2D)         (None, 8, 8, 128)    147584      activation_213[0][0]             
__________________________________________________________________________________________________
bn3b_branch2b (BatchNormalizati (None, 8, 8, 128)    512         res3b_branch2b[0][0]             
__________________________________________________________________________________________________
activation_214 (Activation)     (None, 8, 8, 128)    0           bn3b_branch2b[0][0]              
__________________________________________________________________________________________________
res3b_branch2c (Conv2D)         (None, 8, 8, 512)    66048       activation_214[0][0]             
__________________________________________________________________________________________________
bn3b_branch2c (BatchNormalizati (None, 8, 8, 512)    2048        res3b_branch2c[0][0]             
__________________________________________________________________________________________________
add_70 (Add)                    (None, 8, 8, 512)    0           bn3b_branch2c[0][0]              
                                                                 activation_212[0][0]             
__________________________________________________________________________________________________
activation_215 (Activation)     (None, 8, 8, 512)    0           add_70[0][0]                     
__________________________________________________________________________________________________
res3c_branch2a (Conv2D)         (None, 8, 8, 128)    65664       activation_215[0][0]             
__________________________________________________________________________________________________
bn3c_branch2a (BatchNormalizati (None, 8, 8, 128)    512         res3c_branch2a[0][0]             
__________________________________________________________________________________________________
activation_216 (Activation)     (None, 8, 8, 128)    0           bn3c_branch2a[0][0]              
__________________________________________________________________________________________________
res3c_branch2b (Conv2D)         (None, 8, 8, 128)    147584      activation_216[0][0]             
__________________________________________________________________________________________________
bn3c_branch2b (BatchNormalizati (None, 8, 8, 128)    512         res3c_branch2b[0][0]             
__________________________________________________________________________________________________
activation_217 (Activation)     (None, 8, 8, 128)    0           bn3c_branch2b[0][0]              
__________________________________________________________________________________________________
res3c_branch2c (Conv2D)         (None, 8, 8, 512)    66048       activation_217[0][0]             
__________________________________________________________________________________________________
bn3c_branch2c (BatchNormalizati (None, 8, 8, 512)    2048        res3c_branch2c[0][0]             
__________________________________________________________________________________________________
add_71 (Add)                    (None, 8, 8, 512)    0           bn3c_branch2c[0][0]              
                                                                 activation_215[0][0]             
__________________________________________________________________________________________________
activation_218 (Activation)     (None, 8, 8, 512)    0           add_71[0][0]                     
__________________________________________________________________________________________________
res3d_branch2a (Conv2D)         (None, 8, 8, 128)    65664       activation_218[0][0]             
__________________________________________________________________________________________________
bn3d_branch2a (BatchNormalizati (None, 8, 8, 128)    512         res3d_branch2a[0][0]             
__________________________________________________________________________________________________
activation_219 (Activation)     (None, 8, 8, 128)    0           bn3d_branch2a[0][0]              
__________________________________________________________________________________________________
res3d_branch2b (Conv2D)         (None, 8, 8, 128)    147584      activation_219[0][0]             
__________________________________________________________________________________________________
bn3d_branch2b (BatchNormalizati (None, 8, 8, 128)    512         res3d_branch2b[0][0]             
__________________________________________________________________________________________________
activation_220 (Activation)     (None, 8, 8, 128)    0           bn3d_branch2b[0][0]              
__________________________________________________________________________________________________
res3d_branch2c (Conv2D)         (None, 8, 8, 512)    66048       activation_220[0][0]             
__________________________________________________________________________________________________
bn3d_branch2c (BatchNormalizati (None, 8, 8, 512)    2048        res3d_branch2c[0][0]             
__________________________________________________________________________________________________
add_72 (Add)                    (None, 8, 8, 512)    0           bn3d_branch2c[0][0]              
                                                                 activation_218[0][0]             
__________________________________________________________________________________________________
activation_221 (Activation)     (None, 8, 8, 512)    0           add_72[0][0]                     
__________________________________________________________________________________________________
res4a_branch2a (Conv2D)         (None, 4, 4, 256)    131328      activation_221[0][0]             
__________________________________________________________________________________________________
bn4a_branch2a (BatchNormalizati (None, 4, 4, 256)    1024        res4a_branch2a[0][0]             
__________________________________________________________________________________________________
activation_222 (Activation)     (None, 4, 4, 256)    0           bn4a_branch2a[0][0]              
__________________________________________________________________________________________________
res4a_branch2b (Conv2D)         (None, 4, 4, 256)    590080      activation_222[0][0]             
__________________________________________________________________________________________________
bn4a_branch2b (BatchNormalizati (None, 4, 4, 256)    1024        res4a_branch2b[0][0]             
__________________________________________________________________________________________________
activation_223 (Activation)     (None, 4, 4, 256)    0           bn4a_branch2b[0][0]              
__________________________________________________________________________________________________
res4a_branch2c (Conv2D)         (None, 4, 4, 1024)   263168      activation_223[0][0]             
__________________________________________________________________________________________________
res4a_branch1 (Conv2D)          (None, 4, 4, 1024)   525312      activation_221[0][0]             
__________________________________________________________________________________________________
bn4a_branch2c (BatchNormalizati (None, 4, 4, 1024)   4096        res4a_branch2c[0][0]             
__________________________________________________________________________________________________
bn4a_branch1 (BatchNormalizatio (None, 4, 4, 1024)   4096        res4a_branch1[0][0]              
__________________________________________________________________________________________________
add_73 (Add)                    (None, 4, 4, 1024)   0           bn4a_branch2c[0][0]              
                                                                 bn4a_branch1[0][0]               
__________________________________________________________________________________________________
activation_224 (Activation)     (None, 4, 4, 1024)   0           add_73[0][0]                     
__________________________________________________________________________________________________
res4b_branch2a (Conv2D)         (None, 4, 4, 256)    262400      activation_224[0][0]             
__________________________________________________________________________________________________
bn4b_branch2a (BatchNormalizati (None, 4, 4, 256)    1024        res4b_branch2a[0][0]             
__________________________________________________________________________________________________
activation_225 (Activation)     (None, 4, 4, 256)    0           bn4b_branch2a[0][0]              
__________________________________________________________________________________________________
res4b_branch2b (Conv2D)         (None, 4, 4, 256)    590080      activation_225[0][0]             
__________________________________________________________________________________________________
bn4b_branch2b (BatchNormalizati (None, 4, 4, 256)    1024        res4b_branch2b[0][0]             
__________________________________________________________________________________________________
activation_226 (Activation)     (None, 4, 4, 256)    0           bn4b_branch2b[0][0]              
__________________________________________________________________________________________________
res4b_branch2c (Conv2D)         (None, 4, 4, 1024)   263168      activation_226[0][0]             
__________________________________________________________________________________________________
bn4b_branch2c (BatchNormalizati (None, 4, 4, 1024)   4096        res4b_branch2c[0][0]             
__________________________________________________________________________________________________
add_74 (Add)                    (None, 4, 4, 1024)   0           bn4b_branch2c[0][0]              
                                                                 activation_224[0][0]             
__________________________________________________________________________________________________
activation_227 (Activation)     (None, 4, 4, 1024)   0           add_74[0][0]                     
__________________________________________________________________________________________________
res4c_branch2a (Conv2D)         (None, 4, 4, 256)    262400      activation_227[0][0]             
__________________________________________________________________________________________________
bn4c_branch2a (BatchNormalizati (None, 4, 4, 256)    1024        res4c_branch2a[0][0]             
__________________________________________________________________________________________________
activation_228 (Activation)     (None, 4, 4, 256)    0           bn4c_branch2a[0][0]              
__________________________________________________________________________________________________
res4c_branch2b (Conv2D)         (None, 4, 4, 256)    590080      activation_228[0][0]             
__________________________________________________________________________________________________
bn4c_branch2b (BatchNormalizati (None, 4, 4, 256)    1024        res4c_branch2b[0][0]             
__________________________________________________________________________________________________
activation_229 (Activation)     (None, 4, 4, 256)    0           bn4c_branch2b[0][0]              
__________________________________________________________________________________________________
res4c_branch2c (Conv2D)         (None, 4, 4, 1024)   263168      activation_229[0][0]             
__________________________________________________________________________________________________
bn4c_branch2c (BatchNormalizati (None, 4, 4, 1024)   4096        res4c_branch2c[0][0]             
__________________________________________________________________________________________________
add_75 (Add)                    (None, 4, 4, 1024)   0           bn4c_branch2c[0][0]              
                                                                 activation_227[0][0]             
__________________________________________________________________________________________________
activation_230 (Activation)     (None, 4, 4, 1024)   0           add_75[0][0]                     
__________________________________________________________________________________________________
res4d_branch2a (Conv2D)         (None, 4, 4, 256)    262400      activation_230[0][0]             
__________________________________________________________________________________________________
bn4d_branch2a (BatchNormalizati (None, 4, 4, 256)    1024        res4d_branch2a[0][0]             
__________________________________________________________________________________________________
activation_231 (Activation)     (None, 4, 4, 256)    0           bn4d_branch2a[0][0]              
__________________________________________________________________________________________________
res4d_branch2b (Conv2D)         (None, 4, 4, 256)    590080      activation_231[0][0]             
__________________________________________________________________________________________________
bn4d_branch2b (BatchNormalizati (None, 4, 4, 256)    1024        res4d_branch2b[0][0]             
__________________________________________________________________________________________________
activation_232 (Activation)     (None, 4, 4, 256)    0           bn4d_branch2b[0][0]              
__________________________________________________________________________________________________
res4d_branch2c (Conv2D)         (None, 4, 4, 1024)   263168      activation_232[0][0]             
__________________________________________________________________________________________________
bn4d_branch2c (BatchNormalizati (None, 4, 4, 1024)   4096        res4d_branch2c[0][0]             
__________________________________________________________________________________________________
add_76 (Add)                    (None, 4, 4, 1024)   0           bn4d_branch2c[0][0]              
                                                                 activation_230[0][0]             
__________________________________________________________________________________________________
activation_233 (Activation)     (None, 4, 4, 1024)   0           add_76[0][0]                     
__________________________________________________________________________________________________
res4e_branch2a (Conv2D)         (None, 4, 4, 256)    262400      activation_233[0][0]             
__________________________________________________________________________________________________
bn4e_branch2a (BatchNormalizati (None, 4, 4, 256)    1024        res4e_branch2a[0][0]             
__________________________________________________________________________________________________
activation_234 (Activation)     (None, 4, 4, 256)    0           bn4e_branch2a[0][0]              
__________________________________________________________________________________________________
res4e_branch2b (Conv2D)         (None, 4, 4, 256)    590080      activation_234[0][0]             
__________________________________________________________________________________________________
bn4e_branch2b (BatchNormalizati (None, 4, 4, 256)    1024        res4e_branch2b[0][0]             
__________________________________________________________________________________________________
activation_235 (Activation)     (None, 4, 4, 256)    0           bn4e_branch2b[0][0]              
__________________________________________________________________________________________________
res4e_branch2c (Conv2D)         (None, 4, 4, 1024)   263168      activation_235[0][0]             
__________________________________________________________________________________________________
bn4e_branch2c (BatchNormalizati (None, 4, 4, 1024)   4096        res4e_branch2c[0][0]             
__________________________________________________________________________________________________
add_77 (Add)                    (None, 4, 4, 1024)   0           bn4e_branch2c[0][0]              
                                                                 activation_233[0][0]             
__________________________________________________________________________________________________
activation_236 (Activation)     (None, 4, 4, 1024)   0           add_77[0][0]                     
__________________________________________________________________________________________________
res4f_branch2a (Conv2D)         (None, 4, 4, 256)    262400      activation_236[0][0]             
__________________________________________________________________________________________________
bn4f_branch2a (BatchNormalizati (None, 4, 4, 256)    1024        res4f_branch2a[0][0]             
__________________________________________________________________________________________________
activation_237 (Activation)     (None, 4, 4, 256)    0           bn4f_branch2a[0][0]              
__________________________________________________________________________________________________
res4f_branch2b (Conv2D)         (None, 4, 4, 256)    590080      activation_237[0][0]             
__________________________________________________________________________________________________
bn4f_branch2b (BatchNormalizati (None, 4, 4, 256)    1024        res4f_branch2b[0][0]             
__________________________________________________________________________________________________
activation_238 (Activation)     (None, 4, 4, 256)    0           bn4f_branch2b[0][0]              
__________________________________________________________________________________________________
res4f_branch2c (Conv2D)         (None, 4, 4, 1024)   263168      activation_238[0][0]             
__________________________________________________________________________________________________
bn4f_branch2c (BatchNormalizati (None, 4, 4, 1024)   4096        res4f_branch2c[0][0]             
__________________________________________________________________________________________________
add_78 (Add)                    (None, 4, 4, 1024)   0           bn4f_branch2c[0][0]              
                                                                 activation_236[0][0]             
__________________________________________________________________________________________________
activation_239 (Activation)     (None, 4, 4, 1024)   0           add_78[0][0]                     
__________________________________________________________________________________________________
res5a_branch2a (Conv2D)         (None, 2, 2, 512)    524800      activation_239[0][0]             
__________________________________________________________________________________________________
bn5a_branch2a (BatchNormalizati (None, 2, 2, 512)    2048        res5a_branch2a[0][0]             
__________________________________________________________________________________________________
activation_240 (Activation)     (None, 2, 2, 512)    0           bn5a_branch2a[0][0]              
__________________________________________________________________________________________________
res5a_branch2b (Conv2D)         (None, 2, 2, 512)    2359808     activation_240[0][0]             
__________________________________________________________________________________________________
bn5a_branch2b (BatchNormalizati (None, 2, 2, 512)    2048        res5a_branch2b[0][0]             
__________________________________________________________________________________________________
activation_241 (Activation)     (None, 2, 2, 512)    0           bn5a_branch2b[0][0]              
__________________________________________________________________________________________________
res5a_branch2c (Conv2D)         (None, 2, 2, 2048)   1050624     activation_241[0][0]             
__________________________________________________________________________________________________
res5a_branch1 (Conv2D)          (None, 2, 2, 2048)   2099200     activation_239[0][0]             
__________________________________________________________________________________________________
bn5a_branch2c (BatchNormalizati (None, 2, 2, 2048)   8192        res5a_branch2c[0][0]             
__________________________________________________________________________________________________
bn5a_branch1 (BatchNormalizatio (None, 2, 2, 2048)   8192        res5a_branch1[0][0]              
__________________________________________________________________________________________________
add_79 (Add)                    (None, 2, 2, 2048)   0           bn5a_branch2c[0][0]              
                                                                 bn5a_branch1[0][0]               
__________________________________________________________________________________________________
activation_242 (Activation)     (None, 2, 2, 2048)   0           add_79[0][0]                     
__________________________________________________________________________________________________
res5b_branch2a (Conv2D)         (None, 2, 2, 512)    1049088     activation_242[0][0]             
__________________________________________________________________________________________________
bn5b_branch2a (BatchNormalizati (None, 2, 2, 512)    2048        res5b_branch2a[0][0]             
__________________________________________________________________________________________________
activation_243 (Activation)     (None, 2, 2, 512)    0           bn5b_branch2a[0][0]              
__________________________________________________________________________________________________
res5b_branch2b (Conv2D)         (None, 2, 2, 512)    2359808     activation_243[0][0]             
__________________________________________________________________________________________________
bn5b_branch2b (BatchNormalizati (None, 2, 2, 512)    2048        res5b_branch2b[0][0]             
__________________________________________________________________________________________________
activation_244 (Activation)     (None, 2, 2, 512)    0           bn5b_branch2b[0][0]              
__________________________________________________________________________________________________
res5b_branch2c (Conv2D)         (None, 2, 2, 2048)   1050624     activation_244[0][0]             
__________________________________________________________________________________________________
bn5b_branch2c (BatchNormalizati (None, 2, 2, 2048)   8192        res5b_branch2c[0][0]             
__________________________________________________________________________________________________
add_80 (Add)                    (None, 2, 2, 2048)   0           bn5b_branch2c[0][0]              
                                                                 activation_242[0][0]             
__________________________________________________________________________________________________
activation_245 (Activation)     (None, 2, 2, 2048)   0           add_80[0][0]                     
__________________________________________________________________________________________________
res5c_branch2a (Conv2D)         (None, 2, 2, 512)    1049088     activation_245[0][0]             
__________________________________________________________________________________________________
bn5c_branch2a (BatchNormalizati (None, 2, 2, 512)    2048        res5c_branch2a[0][0]             
__________________________________________________________________________________________________
activation_246 (Activation)     (None, 2, 2, 512)    0           bn5c_branch2a[0][0]              
__________________________________________________________________________________________________
res5c_branch2b (Conv2D)         (None, 2, 2, 512)    2359808     activation_246[0][0]             
__________________________________________________________________________________________________
bn5c_branch2b (BatchNormalizati (None, 2, 2, 512)    2048        res5c_branch2b[0][0]             
__________________________________________________________________________________________________
activation_247 (Activation)     (None, 2, 2, 512)    0           bn5c_branch2b[0][0]              
__________________________________________________________________________________________________
res5c_branch2c (Conv2D)         (None, 2, 2, 2048)   1050624     activation_247[0][0]             
__________________________________________________________________________________________________
bn5c_branch2c (BatchNormalizati (None, 2, 2, 2048)   8192        res5c_branch2c[0][0]             
__________________________________________________________________________________________________
add_81 (Add)                    (None, 2, 2, 2048)   0           bn5c_branch2c[0][0]              
                                                                 activation_245[0][0]             
__________________________________________________________________________________________________
activation_248 (Activation)     (None, 2, 2, 2048)   0           add_81[0][0]                     
__________________________________________________________________________________________________
avg_pool (AveragePooling2D)     (None, 1, 1, 2048)   0           activation_248[0][0]             
__________________________________________________________________________________________________
flatten_5 (Flatten)             (None, 2048)         0           avg_pool[0][0]                   
__________________________________________________________________________________________________
fc6 (Dense)                     (None, 6)            12294       flatten_5[0][0]                  
==================================================================================================
Total params: 23,600,006
Trainable params: 23,546,886
Non-trainable params: 53,120
__________________________________________________________________________________________________
plot_model(model, to_file='model.png')
SVG(model_to_dot(model).create(prog='dot', format='svg'))

猜你喜欢

转载自blog.csdn.net/weixin_42432468/article/details/84992804
今日推荐