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
| with tpu_strategy.scope(): model = tf.keras.Sequential() model.add(tf.keras.layers.Conv2D(filters = 32, kernel_size = (5,5),padding = 'Same', activation ='relu', input_shape = (28,28,1))) model.add(tf.keras.layers.Conv2D(filters = 32, kernel_size = (5,5),padding = 'Same', activation ='relu')) model.add(tf.keras.layers.MaxPool2D(pool_size=(2,2))) model.add(tf.keras.layers.Dropout(0.25))
model.add(tf.keras.layers.Conv2D(filters = 64, kernel_size = (3,3),padding = 'Same', activation ='relu')) model.add(tf.keras.layers.Conv2D(filters = 64, kernel_size = (3,3),padding = 'Same', activation ='relu')) model.add(tf.keras.layers.MaxPool2D(pool_size=(2,2), strides=(2,2))) model.add(tf.keras.layers.Dropout(0.25))
model.add(tf.keras.layers.Flatten()) model.add(tf.keras.layers.Dense(256, activation = "relu")) model.add(tf.keras.layers.Dropout(0.5)) model.add(tf.keras.layers.Dense(10))
optimizer = tf.keras.optimizers.RMSprop(lr=0.001, rho=0.9, epsilon=1e-08, decay=0.0) model.compile(optimizer = optimizer , loss = "mse", metrics=["accuracy"])
model.fit(X_train, Y_train, epochs=9, batch_size=42)
|