深度学习:借用vgg的模型进行建模

vgg = tf.keras.applications.VGG16(include_top = False,input_shape=(256,256,3))
for i in vgg.layers:
    i.trainable = False
a1 = tf.keras.Model(inputs=vgg.input,outputs=vgg.get_layer('block1_conv2').output).output
print(a1.shape)
a2 = tf.keras.Model(inputs=vgg.input,outputs=vgg.get_layer('block2_conv2').output).output
print(a2.shape)
a3 = tf.keras.Model(inputs=vgg.input,outputs=vgg.get_layer('block3_conv2').output).output
print(a3.shape)
a4 = tf.keras.Model(inputs=vgg.input,outputs=vgg.get_layer('block4_conv2').output).output
print(a4.shape)
a5 = tf.keras.Model(inputs=vgg.input,outputs=vgg.get_layer('block5_conv2').output).output
print(a5.shape)
print()

b5 = tf.keras.layers.Conv2DTranspose(512,2,strides =2,padding = 'same')(a5)
print(b5.shape)
c5 = tf.keras.layers.concatenate([a4,b5],axis = 3)   # 1代表列合并,2代表行合并,3代表组合合并
print(c5.shape)
c5 = tf.keras.layers.Conv2D(512,2,padding = 'same')(c5)
print(c5.shape)
print()

b4 = tf.keras.layers.Conv2DTranspose(512,2,strides =2,padding = 'same')(c5)
print(b4.shape)
c4 = tf.keras.layers.concatenate([a3,b4],axis = 3)   # 1代表列合并,2代表行合并,3代表组合合并
print(c4.shape)
c4 = tf.keras.layers.Conv2D(512,2,padding = 'same')(c4)
print(c4.shape)
print()

b3 = tf.keras.layers.Conv2DTranspose(512,2,strides =2,padding = 'same')(c4)
print(b3.shape)
c3 = tf.keras.layers.concatenate([a2,b3],axis = 3)   # 1代表列合并,2代表行合并,3代表组合合并
print(c3.shape)
c3 = tf.keras.layers.Conv2D(512,2,padding = 'same')(c3)
print(c3.shape)
print()

b2 = tf.keras.layers.Conv2DTranspose(512,2,strides =2,padding = 'same')(c3)
print(b2.shape)
c2 = tf.keras.layers.concatenate([a1,b2],axis = 3)   # 1代表列合并,2代表行合并,3代表组合合并
print(c2.shape)
c2 = tf.keras.layers.Conv2D(512,2,padding = 'same')(c2)
print(c2.shape)
print()

c = tf.keras.layers.Flatten()(c2)
output = tf.keras.layers.Dense(10,activation = 'softmax')(c)
model = tf.keras.Model(inputs = vgg.input,outputs = output)

深度学习:借用vgg的模型进行建模_第1张图片

 

你可能感兴趣的:(深度学习,人工智能,python)