Skip to content

Commit 4b5b7c7

Browse files
committed
Update tensorflow.keras.mnist.classifier.py
1 parent 4cd242b commit 4b5b7c7

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

tensorflow/code/tensorflow.keras.mnist.classifier.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
model.add(tf.keras.layers.MaxPool2D(pool_size=(2,2), strides=(2,2)))
9090
model.add(tf.keras.layers.Dropout(0.25))
9191

92-
model.add(tf.keras.layers.Conv2D(filters=64, kernel_size=(3,3), padding='Same', activation='relu'))
92+
model.add(tf.keras.layers.Conv2D(filters=64, kernel_size=(3,3), padding='Same', activation='relu'))
9393
model.add(tf.keras.layers.BatchNormalization())
9494
model.add(tf.keras.layers.Dropout(0.25))
9595

@@ -99,6 +99,7 @@
9999
model.add(tf.keras.layers.Dropout(0.25))
100100

101101
model.add(tf.keras.layers.Dense(10, activation="softmax"))
102+
model.add(tf.keras.layers.Dense(256, kernel_constraint=tf.keras.constraints.MaxNorm(2)))
102103

103104
# 打印出model 看看
104105
tf.keras.utils.plot_model(model, to_file='model.png', show_shapes=True, show_layer_names=True)
@@ -117,6 +118,8 @@
117118
verbose=1,
118119
factor=0.5,
119120
min_lr=0.00001)
121+
122+
# should add early_stopping to the model training callbacks later
120123
early_stopping = tf.keras.callbacks.EarlyStopping(monitor='val_loss', restore_best_weights=True)
121124

122125
# 设置epochs和batch size

0 commit comments

Comments
 (0)