Image Classification with Convolutional Neural Networks (CNN)
For this project, I implement an AlexNet-like deep convolutional neural network with Keras. I use the CNN to classify a dataset with over 1300 images of 17 different categories of flowers from the Oxford Flowers dataset. At the end I will do some transfer learning using VGGNet19.
First, a supplemental function for plotting learning curves
I'm defining a function called plot_learning_curve which takes an instance of History as input and draws learning curves based on accuracy and on loss. This will be supplemental in testing the CNN model.

Setting up the model and classifying data

I import the oxflower17 dataset from tflearn and assign it to inputs X and Y, turned on one-hot encoding, and resized the images to (227,227). Example of an image is shown on the right.
Data Shape



Designing Neural Network Architecture
The architecture of the AlexNet Network is shown on the right. I'll be using ReLU activation functions within the convolutional layers and Tanh as the activation function in the fully connected layers before the output layer.

The Model
I defined a sequential model, and inputting the three main convolutional blocks. I used kernel size (11,11). Below is the summary of the model parameters.


Compiling and Fitting the model to test accuracy
I chose to use categorical cross-entropy as the cost function and adam (adaptive moment estimation) as the optimizer. I then fit the model with an 80/20 split, setting batch-size to 64 and epochs to 100. The learning curve outputs are shown below, and as you can see, training accuracy is very high, around 90%, but the validation accuracy is stuck oscillating at around 55%. Lets see how we can improve.





Improving via Transfer Learning with VGGNet19
To finetune our flower classification model, I import VGG19 and ImageDataGenerator from keras. I load images from disk and use it to perform random data augmentations in real time. I rescale the data between 0 and 1, and split the data into training and testing data. I load the model and freeze all layers in the base VGGNet19 model, then classify the flowers into the 17 categories.




Improving via Transfer Learning with VGGNet19

Finally, I configure, train, and plot the accuracy and loss. As you can see the curve is much smoother and has a significantly higher model accuracy and lower loss.



