1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| num_classes = 5
""" 关于卷积核的计算不懂的可以参考文章:https://blog.csdn.net/qq_38251616/article/details/114278995 """
model = models.Sequential([ layers.experimental.preprocessing.Rescaling(1./255, input_shape=(img_height, img_width, 3)), layers.Conv2D(16, (3, 3), activation='relu', input_shape=(img_height, img_width, 3)), # 卷积层1,卷积核3*3 layers.MaxPooling2D((2, 2)), # 池化层1,2*2采样 layers.Conv2D(32, (3, 3), activation='relu'), # 卷积层2,卷积核3*3 layers.MaxPooling2D((2, 2)), # 池化层2,2*2采样 layers.Conv2D(64, (3, 3), activation='relu'), # 卷积层3,卷积核3*3 layers.Flatten(), # Flatten层,连接卷积层与全连接层 layers.Dense(128, activation='relu'), # 全连接层,特征进一步提取 layers.Dense(num_classes) # 输出层,输出预期结果 ])
model.summary() # 打印网络结构 """ Model: "sequential_1" _________________________________________________________________ Layer (type) Output Shape Param # ================================================================= rescaling_1 (Rescaling) (None, 180, 180, 3) 0 _________________________________________________________________ conv2d_3 (Conv2D) (None, 178, 178, 16) 448 _________________________________________________________________ max_pooling2d_2 (MaxPooling2 (None, 89, 89, 16) 0 _________________________________________________________________ conv2d_4 (Conv2D) (None, 87, 87, 32) 4640 _________________________________________________________________ max_pooling2d_3 (MaxPooling2 (None, 43, 43, 32) 0 _________________________________________________________________ conv2d_5 (Conv2D) (None, 41, 41, 64) 18496 _________________________________________________________________ flatten_1 (Flatten) (None, 107584) 0 _________________________________________________________________ dense_2 (Dense) (None, 128) 13770880 _________________________________________________________________ dense_3 (Dense) (None, 5) 645 ================================================================= Total params: 13,795,109 Trainable params: 13,795,109 Non-trainable params: 0 _________________________________________________________________ """
|