import tensorflow as tffrom tensorflow.keras import datasets, layers, modelsimport matplotlib.pyplot as plt
# LOAD AND SPLIT DATASET(train_images, train_labels), (test_images, test_labels) =\ datasets.cifar10.load_data()# Normalize pixel values to be between 0 and 1train_images, test_images = train_images /255.0, test_images /255.0class_names = ['airplane', 'automobile', 'bird', 'cat', 'deer','dog', 'frog', 'horse', 'ship', 'truck']
# Let's look at a one imageIMG_INDEX =7# change this to look at other imagesplt.imshow(train_images[IMG_INDEX] ,cmap=plt.cm.binary)plt.xlabel(class_names[train_labels[IMG_INDEX][0]])plt.show()
model = models.Sequential()## CONVOLUTIONAL BASE# first layer receives 32,32,3 images. 32 filters of size 3x3 model.add(layers.Conv2D(32, (3, 3), activation='relu', input_shape=(32, 32, 3)))# second layer pools 2x2 with a stide of 2x2 (not specified defaults to pool)model.add(layers.MaxPooling2D((2, 2)))# further layers use more filters due to the pooling shrinking the images # allowing more depthmodel.add(layers.Conv2D(64, (3, 3), activation='relu'))model.add(layers.MaxPooling2D((2, 2)))model.add(layers.Conv2D(64, (3, 3), activation='relu'))
# flatten 4,4,64 to a single vectormodel.add(layers.Flatten())# feed it into a dense layermodel.add(layers.Dense(64, activation='relu'))# do the 10 object classificationmodel.add(layers.Dense(10))