A CNN example with Keras and CIFAR-10
In Chapter 3, Deep Learning Fundamentals, we tried to classify the CIFAR-10 images with a fully-connected network, but we only managed 51% test accuracy. Let's see if we can do better with all the new things we've learned. This time we'll use CNN with data augmentation.
- We'll start with the imports. We'll use all the layers we introduced in this chapter, as shown in the following example:
import keras from keras.datasets import cifar10 from keras.layers import Conv2D, MaxPooling2D from keras.layers import Dense, Dropout, Activation, Flatten, BatchNormalization from keras.models import Sequential from keras.preprocessing.image import ImageDataGenerator
- We'll define the mini
batch_size
for convenience, as shown in the following code:
batch_size = 50
- Next, we'll import the CIFAR-10 dataset and we'll normalize the data by dividing it to 255 (maximum pixel intensity), as shown in the following code:
(X_train, Y_train), (X_test, Y_test) = cifar10.load_data() X_train...