


CIFAR has 10 output classes, so you use a final Dense layer with 10 outputs. First, you will flatten (or unroll) the 3D output to 1D, then add one or more Dense layers on top. Dense layers take vectors as input (which are 1D), while the current output is a 3D tensor. To complete the model, you will feed the last output tensor from the convolutional base (of shape (4, 4, 64)) into one or more Dense layers to perform classification. Typically, as the width and height shrink, you can afford (computationally) to add more output channels in each Conv2D layer. The number of output channels for each Conv2D layer is controlled by the first argument (e.g., 32 or 64). The width and height dimensions tend to shrink as you go deeper in the network. Max_pooling2d_1 (MaxPoolin (None, 6, 6, 64) 0Ībove, you can see that the output of every Conv2D and MaxPooling2D layer is a 3D tensor of shape (height, width, channels). Let's display the architecture of your model so far: model.summary() You can do this by passing the argument input_shape to your first layer. In this example, you will configure your CNN to process inputs of shape (32, 32, 3), which is the format of CIFAR images. If you are new to these dimensions, color_channels refers to (R,G,B).
TENSORFLOW SEQUENTIAL CODE
The 6 lines of code below define the convolutional base using a common pattern: a stack of Conv2D and MaxPooling2D layers.Īs input, a CNN takes tensors of shape (image_height, image_width, color_channels), ignoring the batch size. To verify that the dataset looks correct, let's plot the first 25 images from the training set and display the class name below each image: class_names = ['airplane', 'automobile', 'bird', 'cat', 'deer', # Normalize pixel values to be between 0 and 1 (train_images, train_labels), (test_images, test_labels) = _data() The classes are mutually exclusive and there is no overlap between them. The dataset is divided into 50,000 training images and 10,000 testing images. The CIFAR10 dataset contains 60,000 color images in 10 classes, with 6,000 images in each class. Import TensorFlow import tensorflow as tfįrom tensorflow.keras import datasets, layers, models Because this tutorial uses the Keras Sequential API, creating and training your model will take just a few lines of code. This tutorial demonstrates training a simple Convolutional Neural Network (CNN) to classify CIFAR images.
