def train_mnist(x_train, y_train):
### START CODE HERE
# Instantiate the callback class
callbacks = myCallback()
# Define the model, it should have 3 layers:
# - A Flatten layer that receives inputs with the same shape as the images
# - A Dense layer with 512 units and ReLU activation function
# - A Dense layer with 10 units and softmax activation function
model = tf.keras.models.Sequential([
tf.keras.layers.Flatten(input_shape=(28,28)),
tf.keras.layers.Dense(512, activation=tf.nn.relu),
tf.keras.layers.Dense(10, activation=tf.nn.softmax) ]),
# Compile the model
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
# Fit the model for 10 epochs adding the callbacks
# and save the training history
history = model.fit(x_train, y_train, epochs=10, callbacks=[Callbacks])
### END CODE HERE
return history
Output Error
AttributeError Traceback (most recent call last)
in
----> 1 hist = train_mnist(x_train, y_train)
in train_mnist(x_train, y_train)
18
19 # Compile the model
—> 20 model.compile(optimizer=‘adam’,
21 loss=‘sparse_categorical_crossentropy’,
22 metrics=[‘accuracy’])
AttributeError: ‘tuple’ object has no attribute ‘compile’
Above is my code of week two buy on running the hist = train_mist… line of action, I’m getting the error message above and this seems a bit confusing. How can I correct this please.
Thanks