My CNN produces volatile validation_loss and does not converge in python(Keras)

My model is experiencing wild and big fluctuations in the validation loss and does not converge.

I am doing an image recognition project with my three dogs i.e. classifying the dog in the image. Two dogs are very similar and the 3rd is very different. I took 10 minute videos of each dog, separately. Frames were extracted as images at each second.

This block of code is responsible for augmenting and creating the data to feed the model.

randomize = np.arange(len(imArr)) # imArr is the numpy array of all the images
np.random.shuffle(randomize) # Shuffle the images and labels
imArr = imArr[randomize]
imLab= imLab[randomize] # imLab is the array of labels of the images
lab = to_categorical(imLab, 3)

gen = ImageDataGenerator(zoom_range = 0.2,horizontal_flip = True , vertical_flip = True,validation_split = 0.25)
train_gen = gen.flow(imArr,lab,batch_size = 64, subset = 'training')
test_gen = gen.flow(imArr,lab,batch_size =64,subset = 'validation')


This picture is the result of the model below.

model = Sequential()

model.add(Conv2D(16, (11, 11),strides = 1, input_shape=(imgSize,imgSize,3)))

#Fully connected layer

sgd = SGD(lr=0.004)
model.compile(loss='categorical_crossentropy', optimizer=sgd, metrics=['accuracy'])

batch_size = 64
epochs = 100
model.fit_generator(train_gen, steps_per_epoch=(len(train_gen)), epochs=epochs, validation_data=test_gen, validation_steps=len(test_gen),shuffle = True)


Things I have tried.

• High/low Learning rate ( 0.01 -> 0.0001)
• Increase Dropout to 0.5 in both Dense layers
• Increase/Decrease size of both Dense Layers ( 128 min -> 4048 max)
• Increased number of CNN layers
• Introduced Momentum
• Increased/Decreased Batch Size

Things I have not tried

• I have not used any other loss or metric
• I have not used any other optimiser.
• Have not adjusted any parameters of the CNN layers

It seems that there is some form of randomness or too many parameters in my model. I am aware that it is currently overfitting, but that should not be the cause of the volatility(?). I am not too worried about the performance of the model. I would like to achieve about a 70% accuracy. All I want to do now is to stabilise the validation accuracy and to converge.

Note:

• At some epochs, the training loss is very low ( <0.1 ) but validation loss is very high ( > 3 ).
• The videos are taken on different backgrounds, but +- the same amount on each background for each dog.
• Some images are a bit blurry.
• I forgot to mention that my data set consist of about 1800 images...600 of each dog – Rabbo Pasch May 7 '19 at 11:04
• What is your input image size? – Illuminati0x5B Jun 7 '19 at 12:20
• 256x256. Got it fixed thouguyh – Rabbo Pasch Jun 9 '19 at 14:28

It seems that there is some form of randomness or too many parameters in my model. I am aware that it is currently overfitting, but that should not be the cause of the volatility(?)

It is quite plausible that this behavior is caused by a combination of the model's excessive capacity and the data that you are feeding into it.

As you have pointed out, overfitting is obvious here - the model cannot generalize well and fails on unseen data. If you reduce model capacity (better yet, start off with the bare minimum and incrementally build up from there), then the network will be forced to learn instead of performing memorization. Since you mention that you have already tried tuning rates/layers/sizes, the model alone cannot be the cause, although maybe someone with more expertise in convolutional layers can provide useful insight.

The lack of convergence can be an indicator that there is simply not enough data to learn from - neural networks aren't guaranteed to converge when there is insufficient data. The required amount depends greatly on the specifics of the task.

my data set consist of about 1800 images...600 of each dog

That's quite a small dataset, considering that:

Two dogs are very similar and the 3rd is very different.

So roughly two thirds of your images can cause confusion. The more they look alike, the more samples you will need to capture the details.

The videos are taken on different backgrounds, but +- the same amount on each background for each dog.

The model could then erroneously try to discriminate between the two similar-looking dogs based on the background alone (think worst-case scenario).

In your case, I would look at the data more closely, investigate which images are consistently the easiest/hardest for the model to classify and take full advantage of ImageDataGenerator's image augmentation to improve generalization capabilities. See how the model responds if you place similar-looking dogs under the same label, or have one of them appear exclusively in training, the other in validation. Maybe there are some answers there.