import tensorflow as tf # Define a simple CNN model model = tf.keras.models.Sequential([ tf.keras.layers.Conv2D(32, (3, 3), activation='relu', input_shape=(28, 28, 1)), tf.keras.layers.MaxPooling2D((2, 2)), tf.keras.layers.Flatten(), tf.keras.layers.Dense(10, activation='softmax') ]) # Define the optimizer optimizer = tf.keras.optimizers.Adam() # Compile the model with the optimizer and loss function model.compile(optimizer=optimizer, loss='sparse_categorical_crossentropy', metrics=['accuracy']) # Train the model on the dataset model.fit(train_images, train_labels, epochs=10, validation_data=(test_images, test_labels))