I have just started building neural networks with tensorflow and different online resources have different ways of creating them. One thing I have noticed is how the sequential API is implemented. Some use tf.keras.Sequential() while others use tf.keras.models.Sequential()? Can anyone tell me the difference and when to use one over the other?
I have tried using them both in this mode but they both provide good results.
model = tf.keras.models.Sequential([
tf.keras.layers.Flatten(input_shape=(28, 28)),
tf.keras.layers.Dense(128, activation='relu'),
tf.keras.layers.Dense(10, activation='softmax')
])
model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])
model.fit(x_train, y_train, epochs=50)
model.evaluate(x_test, y_test)
model = tf.keras.Sequential([
tf.keras.layers.Flatten(input_shape=(28, 28)),
tf.keras.layers.Dense(128, activation='relu'),
tf.keras.layers.Dense(10, activation='softmax')
])
model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])
model.fit(x_train, y_train, epochs=50)
model.evaluate(x_test, y_test)
Collins Mwaura is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.