Complete the code to import the necessary library for building a neural network model.
from tensorflow import [1]
We use keras from TensorFlow to build and train neural network models.
Complete the code to load the CIFAR-10 dataset for training and testing.
(train_images, train_labels), (test_images, test_labels) = keras.datasets.cifar10.[1]()The load_data() function loads the CIFAR-10 dataset as training and testing sets.
Fix the error in the model compilation step by completing the optimizer argument.
model.compile(optimizer='[1]', loss='sparse_categorical_crossentropy', metrics=['accuracy'])
The 'adam' optimizer is commonly used for training image classifiers and works well here.
Fill both blanks to normalize the image pixel values between 0 and 1.
train_images = train_images [1] 255.0 test_images = test_images [2] 255.0
Dividing pixel values by 255.0 scales them from 0-255 to 0-1, which helps model training.
Fill all three blanks to define a simple CNN model with Conv2D, MaxPooling2D, and Dense layers.
model = keras.Sequential([
keras.layers.Conv2D(32, (3, 3), activation='relu', input_shape=[1]),
keras.layers.MaxPooling2D([2]),
keras.layers.Flatten(),
keras.layers.Dense([3], activation='softmax')
])The input shape for CIFAR-10 images is (32, 32, 3). MaxPooling2D commonly uses a pool size of (2, 2). The Dense output layer has 10 units for the 10 classes.