Image Classification Using CNN Canadian Institute for Advanced Research (CIFAR) provides a dataset that consists of 60000 32x32x3 color images of 10 classes, known as CIFAR-10, with 6000 images per class. There are 50000 training images and 10000 test images. To classify those 10 classes of images a convolutional neural network (CNN) is used here. CNN achieved 85.0% accuracy in the test dataset. The block diagram of the CNN is shown below.
model = Sequential()
# Block 01
model.add(Conv2D(32, (3, 3), padding='same', input_shape=(32, 32, 3)))
model.add(LeakyReLU(alpha=alpha))
model.add(Conv2D(32, (3, 3)))
model.add(LeakyReLU(alpha=alpha))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))
# Block 02
model.add(Conv2D(64, (3, 3), padding='same'))
model.add(LeakyReLU(alpha=alpha))
model.add(Conv2D(64, (3, 3)))
model.add(LeakyReLU(alpha=alpha))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))
# Block 03
model.add(Conv2D(64, (3, 3), padding='same'))
model.add(LeakyReLU(alpha=alpha))
model.add(Conv2D(64, (3, 3)))
model.add(LeakyReLU(alpha=alpha))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))
# Block 04
model.add(Flatten())
model.add(Dense(512, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(512, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(10, activation='softmax'))
return model
Batch size is chosen 256 and the network is trained for 120 epochs.
This is how the outputs look like.
- Load the CIFAR-10 dataset.
- Normalize training and test data.
- Change labels from integer to categorical.
- Build the model.
- Compile the model.
- Train the model.
- Save the model.
- Classify new test image using the trained model.