CNN


Work with your assigned partner to write a convolutional neural network to classify images in the CIFAR10 dataset.


Use Keras to load the data set and build the model. See example code to import the data set below:

from keras.datasets import cifar10
(trainX, trainy), (testX, testy) = cifar10.load_data()

# normalize the pixel data
trainX = trainX.astype('float32') / 255
testX = testX.astype('float32') / 255


Here is an example of a MLP/feed forward neural network:

# a MLP with two hidden layers, 12 & 8, and predicts 10 classes
model = Sequential()

# 784 features, 12 size in the hidden layer
model.add(Dense(12, input_shape=(784,), activation='relu'))

# 8 neurons in the second hidden layer
model.add(Dense(8, activation='relu'))

# predicts 10 classes with logistic regression (softmax)
model.add(Dense(10, activation='softmax'))

# build the model
model.compile(loss='categorical_crossentropy', optimizer=SGD(learning_rate=0.01), metrics=['accuracy'])

# train the model
model.fit(train_x, train_y, validation_data=(dev_x, dev_y), epochs=10, batch_size=32)

# evaluate the model
scores = model.evaluate(test_x, test_y, verbose=0)
print("Accuracy: %.2f%%" % (scores[1]*100))


Make a CNN that resembles LeNet, train it, and evaluate via per class F1 scores. You will likely need to sample from the training and testing data since there 50,000 images in the training set and 10,000 in the testing set.


This page was last modified on 2026-08-19 at 20:15:10.

Copyright © 2018–2026 George Fox University. All rights reserved.