import tensorflow as tf from tensorflow import keras from tensorflow.keras import layers # Load CIFAR-10 dataset (x_train, y_train), (x_test, y_test) = keras.datasets.cifar10.load_data() # Normalize pixel values between 0 and 1 x_train = x_train.astype("float32") / 255.0 x_test = x_test.astype("float32") / 255.0 # Define the CNN architecture model = keras.Sequential([ layers.Conv2D(32, (3, 3), activation="relu", input_shape=(32, 32, 3)), layers.MaxPooling2D(pool_size=(2, 2)), layers.Conv2D(64, (3, 3), activation="relu"), layers.MaxPooling2D(pool_size=(2, 2)), layers.Flatten(), layers.Dense(64, activation="relu"), layers.Dense(10), ]) # Compile the model model.compile(optimizer="adam", loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True), metrics=["accuracy"]) # Train the model model.fit(x_train, y_train, epochs=10, batch_size=64, validation_split=0.1) # Evaluate the model on the test dataset test_loss, test_acc = model.evaluate(x_test, y_test) print("Test Loss:", test_loss) print("Test Accuracy:", test_acc)