FeedForward TensorFlow Keras
FeedForward TensorFlow Keras
TENSORFLOW/KERAS
import tensorflow as tf
mnist = tf.keras.datasets.mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
model = tf.keras.models.Sequential([
tf.keras.layers.Flatten(input_shape=(28, 28)), # Flatten the
28x28 image
tf.keras.layers.Dense(128, activation='relu'), # Fully
connected layer
tf.keras.layers.Dropout(0.2), # Dropout for
regularization
tf.keras.layers.Dense(10, activation='softmax') # Output layer
(10 classes)
])
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
Expected Output:
TensorFlow version: 2.x.x
Epoch 1/5
1875/1875 [==============================] - 5s 2ms/step - loss: 0.2961 -
accuracy: 0.9140
Epoch 2/5
1875/1875 [==============================] - 4s 2ms/step - loss: 0.1415 -
accuracy: 0.9582
Epoch 3/5
1875/1875 [==============================] - 4s 2ms/step - loss: 0.1051 -
accuracy: 0.9681
Epoch 4/5
1875/1875 [==============================] - 4s 2ms/step - loss: 0.0864 -
accuracy: 0.9734
Epoch 5/5
1875/1875 [==============================] - 4s 2ms/step - loss: 0.0736 -
accuracy: 0.9768