LeNet
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/327c77de249a3c8169aed05636c0ecf4.png)
import tensorflow as tf
from tensorflow.keras import datasets, layers, models
model = models.Sequential(name='LeNet-5')
model.add(layers.Conv2D(6, (5, 5), activation='sigmoid', input_shape=(32, 32, 3)))
model.add(layers.MaxPooling2D((2, 2)))
model.add(layers.Conv2D(16, (5, 5), activation='sigmoid'))
model.add(layers.MaxPooling2D((2, 2)))
model.add(layers.Flatten())
model.add(layers.Dense(120, activation='sigmoid'))
model.add(layers.Dense(84, activation='sigmoid'))
model.add(layers.Dense(10,activation='softmax'))
model.summary()
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/383fe116d82285360822ef0b95526fa6.png)
AlexNet
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/a0d3f6bc8bb5d94ac0a73bded82d58e9.png)
import tensorflow as tf
from tensorflow.keras import datasets, layers, models
model = models.Sequential(name='AlexNet')
model.add(layers.Conv2D(96,(11,11),strides=(2,2),input_shape=(224,224,3),
padding='same',activation='relu'))
model.add(layers.MaxPooling2D(pool_size=(3,3),strides=(2,2)))
model.add(layers.Conv2D(256,(5,5),strides=(1,1),padding='same',activation='relu'))
model.add(layers.MaxPooling2D(pool_size=(3,3),strides=(2,2)))
model.add(layers.Conv2D(384,(3,3),strides=(1,1),padding='same',activation='relu'))
model.add(layers.Conv2D(384,(3,3),strides=(1,1),padding='same',activation='relu'))
model.add(layers.Conv2D(256,(3,3),strides=(1,1),padding='same',activation='relu'))
model.add(layers.MaxPooling2D(pool_size=(2,2),strides=(2,2)))
model.add(layers.Flatten())
model.add(layers.Dense(2048,activation='relu'))
model.add(layers.Dropout(0.5))
model.add(layers.Dense(2048,activation='relu'))
model.add(layers.Dropout(0.5))
model.add(layers.Dense(10,activation='softmax'))
model.summary()
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/d214ad7abedcbfe45aad86af50b5caa2.png)
VGG
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/9b030d7b289517291da985f4cf57df28.png)
VGG16
import tensorflow as tf
from tensorflow.keras import datasets, layers, models
model = models.Sequential(name='VGG16')
model.add(layers.Conv2D(64,(3,3),input_shape=(224,224,3),
padding='same',activation='relu'))
model.add(layers.Conv2D(64,(3,3),input_shape=(224,224,3),
padding='same',activation='relu'))
model.add(layers.MaxPooling2D(pool_size=(2,2),strides=(2,2),padding='same'))
model.add(layers.Dropout(0.2))
model.add(layers.Conv2D(128,(3,3),padding='same',activation='relu'))
model.add(layers.Conv2D(128,(3,3),padding='same',activation='relu'))
model.add(layers.MaxPooling2D(pool_size=(2,2),strides=(2,2),padding='same'))
model.add(layers.Dropout(0.2))
model.add(layers.Conv2D(256,(3,3),padding='same',activation='relu'))
model.add(layers.Conv2D(256,(3,3),padding='same',activation='relu'))
model.add(layers.Conv2D(256,(3,3),padding='same',activation='relu'))
model.add(layers.MaxPooling2D(pool_size=(2,2),strides=(2,2),padding='same'))
model.add(layers.Dropout(0.2))
model.add(layers.Conv2D(512,(3,3),padding='same',activation='relu'))
model.add(layers.Conv2D(512,(3,3),padding='same',activation='relu'))
model.add(layers.Conv2D(512,(3,3),padding='same',activation='relu'))
model.add(layers.MaxPooling2D(pool_size=(2,2),strides=(2,2),padding='same'))
model.add(layers.Dropout(0.2))
model.add(layers.Conv2D(512,(3,3),padding='same',activation='relu'))
model.add(layers.Conv2D(512,(3,3),padding='same',activation='relu'))
model.add(layers.Conv2D(512,(3,3),padding='same',activation='relu'))
model.add(layers.MaxPooling2D(pool_size=(2,2),strides=(2,2),padding='same'))
model.add(layers.Dropout(0.2))
model.add(layers.Flatten())
model.add(layers.Dense(4096,activation='relu'))
model.add(layers.Dropout(0.2))
model.add(layers.Dense(4096,activation='relu'))
model.add(layers.Dropout(0.2))
model.add(layers.Dense(1000,activation='relu'))
model.add(layers.Dropout(0.2))
model.add(layers.Dense(10,activation='softmax'))
model.summary()
Model: "VGG16"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
conv2d (Conv2D) (None, 224, 224, 64) 1792
_________________________________________________________________
conv2d_1 (Conv2D) (None, 224, 224, 64) 36928
_________________________________________________________________
max_pooling2d (MaxPooling2D) (None, 112, 112, 64) 0
_________________________________________________________________
dropout (Dropout) (None, 112, 112, 64) 0
_________________________________________________________________
conv2d_2 (Conv2D) (None, 112, 112, 128) 73856
_________________________________________________________________
conv2d_3 (Conv2D) (None, 112, 112, 128) 147584
_________________________________________________________________
max_pooling2d_1 (MaxPooling2 (None, 56, 56, 128) 0
_________________________________________________________________
dropout_1 (Dropout) (None, 56, 56, 128) 0
_________________________________________________________________
conv2d_4 (Conv2D) (None, 56, 56, 256) 295168
_________________________________________________________________
conv2d_5 (Conv2D) (None, 56, 56, 256) 590080
_________________________________________________________________
conv2d_6 (Conv2D) (None, 56, 56, 256) 590080
_________________________________________________________________
max_pooling2d_2 (MaxPooling2 (None, 28, 28, 256) 0
_________________________________________________________________
dropout_2 (Dropout) (None, 28, 28, 256) 0
_________________________________________________________________
conv2d_7 (Conv2D) (None, 28, 28, 512) 1180160
_________________________________________________________________
conv2d_8 (Conv2D) (None, 28, 28, 512) 2359808
_________________________________________________________________
conv2d_9 (Conv2D) (None, 28, 28, 512) 2359808
_________________________________________________________________
max_pooling2d_3 (MaxPooling2 (None, 14, 14, 512) 0
_________________________________________________________________
dropout_3 (Dropout) (None, 14, 14, 512) 0
_________________________________________________________________
conv2d_10 (Conv2D) (None, 14, 14, 512) 2359808
_________________________________________________________________
conv2d_11 (Conv2D) (None, 14, 14, 512) 2359808
_________________________________________________________________
conv2d_12 (Conv2D) (None, 14, 14, 512) 2359808
_________________________________________________________________
max_pooling2d_4 (MaxPooling2 (None, 7, 7, 512) 0
_________________________________________________________________
dropout_4 (Dropout) (None, 7, 7, 512) 0
_________________________________________________________________
flatten (Flatten) (None, 25088) 0
_________________________________________________________________
dense (Dense) (None, 4096) 102764544
_________________________________________________________________
dropout_5 (Dropout) (None, 4096) 0
_________________________________________________________________
dense_1 (Dense) (None, 4096) 16781312
_________________________________________________________________
dropout_6 (Dropout) (None, 4096) 0
_________________________________________________________________
dense_2 (Dense) (None, 1000) 4097000
_________________________________________________________________
dropout_7 (Dropout) (None, 1000) 0
_________________________________________________________________
dense_3 (Dense) (None, 10) 10010
=================================================================
Total params: 138,367,554
Trainable params: 138,367,554
Non-trainable params: 0
_________________________________________________________________
VGG19
import tensorflow as tf
from tensorflow.keras import datasets, layers, models
import matplotlib.pyplot as plt
model = models.Sequential(name='VGG19')
model.add(layers.Conv2D(64,(3,3),input_shape=(224,224,3),
padding='same',activation='relu'))
model.add(layers.Conv2D(64,(3,3),input_shape=(224,224,3),
padding='same',activation='relu'))
model.add(layers.MaxPooling2D(pool_size=(2,2),strides=(2,2),padding='same'))
model.add(layers.Dropout(0.2))
model.add(layers.Conv2D(128,(3,3),padding='same',activation='relu'))
model.add(layers.Conv2D(128,(3,3),padding='same',activation='relu'))
model.add(layers.MaxPooling2D(pool_size=(2,2),strides=(2,2),padding='same'))
model.add(layers.Dropout(0.2))
model.add(layers.Conv2D(256,(3,3),padding='same',activation='relu'))
model.add(layers.Conv2D(256,(3,3),padding='same',activation='relu'))
model.add(layers.Conv2D(256,(3,3),padding='same',activation='relu'))
model.add(layers.Conv2D(256,(3,3),padding='same',activation='relu'))
model.add(layers.MaxPooling2D(pool_size=(2,2),strides=(2,2),padding='same'))
model.add(layers.Dropout(0.2))
model.add(layers.Conv2D(512,(3,3),padding='same',activation='relu'))
model.add(layers.Conv2D(512,(3,3),padding='same',activation='relu'))
model.add(layers.Conv2D(512,(3,3),padding='same',activation='relu'))
model.add(layers.Conv2D(512,(3,3),padding='same',activation='relu'))
model.add(layers.MaxPooling2D(pool_size=(2,2),strides=(2,2),padding='same'))
model.add(layers.Dropout(0.2))
model.add(layers.Conv2D(512,(3,3),padding='same',activation='relu'))
model.add(layers.Conv2D(512,(3,3),padding='same',activation='relu'))
model.add(layers.Conv2D(512,(3,3),padding='same',activation='relu'))
model.add(layers.Conv2D(512,(3,3),padding='same',activation='relu'))
model.add(layers.MaxPooling2D(pool_size=(2,2),strides=(2,2),padding='same'))
model.add(layers.Dropout(0.2))
model.add(layers.Flatten())
model.add(layers.Dense(4096,activation='relu'))
model.add(layers.Dropout(0.2))
model.add(layers.Dense(4096,activation='relu'))
model.add(layers.Dropout(0.2))
model.add(layers.Dense(1000,activation='relu'))
model.add(layers.Dropout(0.2))
model.add(layers.Dense(10,activation='softmax'))
model.summary()
Model: "VGG19"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
conv2d (Conv2D) (None, 224, 224, 64) 1792
_________________________________________________________________
conv2d_1 (Conv2D) (None, 224, 224, 64) 36928
_________________________________________________________________
max_pooling2d (MaxPooling2D) (None, 112, 112, 64) 0
_________________________________________________________________
dropout (Dropout) (None, 112, 112, 64) 0
_________________________________________________________________
conv2d_2 (Conv2D) (None, 112, 112, 128) 73856
_________________________________________________________________
conv2d_3 (Conv2D) (None, 112, 112, 128) 147584
_________________________________________________________________
max_pooling2d_1 (MaxPooling2 (None, 56, 56, 128) 0
_________________________________________________________________
dropout_1 (Dropout) (None, 56, 56, 128) 0
_________________________________________________________________
conv2d_4 (Conv2D) (None, 56, 56, 256) 295168
_________________________________________________________________
conv2d_5 (Conv2D) (None, 56, 56, 256) 590080
_________________________________________________________________
conv2d_6 (Conv2D) (None, 56, 56, 256) 590080
_________________________________________________________________
conv2d_7 (Conv2D) (None, 56, 56, 256) 590080
_________________________________________________________________
max_pooling2d_2 (MaxPooling2 (None, 28, 28, 256) 0
_________________________________________________________________
dropout_2 (Dropout) (None, 28, 28, 256) 0
_________________________________________________________________
conv2d_8 (Conv2D) (None, 28, 28, 512) 1180160
_________________________________________________________________
conv2d_9 (Conv2D) (None, 28, 28, 512) 2359808
_________________________________________________________________
conv2d_10 (Conv2D) (None, 28, 28, 512) 2359808
_________________________________________________________________
conv2d_11 (Conv2D) (None, 28, 28, 512) 2359808
_________________________________________________________________
max_pooling2d_3 (MaxPooling2 (None, 14, 14, 512) 0
_________________________________________________________________
dropout_3 (Dropout) (None, 14, 14, 512) 0
_________________________________________________________________
conv2d_12 (Conv2D) (None, 14, 14, 512) 2359808
_________________________________________________________________
conv2d_13 (Conv2D) (None, 14, 14, 512) 2359808
_________________________________________________________________
conv2d_14 (Conv2D) (None, 14, 14, 512) 2359808
_________________________________________________________________
conv2d_15 (Conv2D) (None, 14, 14, 512) 2359808
_________________________________________________________________
max_pooling2d_4 (MaxPooling2 (None, 7, 7, 512) 0
_________________________________________________________________
dropout_4 (Dropout) (None, 7, 7, 512) 0
_________________________________________________________________
flatten (Flatten) (None, 25088) 0
_________________________________________________________________
dense (Dense) (None, 4096) 102764544
_________________________________________________________________
dropout_5 (Dropout) (None, 4096) 0
_________________________________________________________________
dense_1 (Dense) (None, 4096) 16781312
_________________________________________________________________
dropout_6 (Dropout) (None, 4096) 0
_________________________________________________________________
dense_2 (Dense) (None, 1000) 4097000
_________________________________________________________________
dropout_7 (Dropout) (None, 1000) 0
_________________________________________________________________
dense_3 (Dense) (None, 10) 10010
=================================================================
Total params: 143,677,250
Trainable params: 143,677,250
Non-trainable params: 0
_________________________________________________________________