I followed this guy's tutorial on YouTube. Following is the code that was used for classifying 0 to 9 handwritten digits from MNIST dataset. The dataset contains 70,000 images of 28 x 28. Here, 60,000 are used for training and 10,000 are used for testing.

# Create the model.
model = tf.keras.models.Sequential()

# Flatten layer i.e. instead of 28 x 28 to 784 pixels

# These are two hidden layers with '128' neurons each and 'ReLU' is the activation fuction choosen for them.
model.add(tf.keras.layers.Dense(128, activation=tf.nn.relu))
model.add(tf.keras.layers.Dense(128, activation=tf.nn.relu))

# This one is output layer for 10 classifications
model.add(tf.keras.layers.Dense(10, activation=tf.nn.softmax))

# optimizer and loss functions
model.compile(optimizer='adam', loss='sparse_categorical_crossentropy',metrics=['accuracy'])

# Now, lets train the model.
model.fit(x_train, y_train, epochs=3)

I don't understand a couple of things from this code:

  • Where is the input layer?
  • How are '128' neurons are chosen?
  • And why use two hidden layers?