In the notebook, the epoch is set to 2, which is very small. My first run returned a model with accuracy 0.5, for both training and testing. I then increased epochs to 20, but the accuracy is still 0.5 after 6 epochs. I then interrupted the training, and then clicked the submit button. My purpose is just to see what the error will be returned, but surprisingly, my submission passed.
I restarted the kernel and run my notebook again from the beginning. This time the model fitting is better, I think this is because of the randomization of data: we did not set the seed for the python random module. However, what surprised me is, the validation accuracy is even better than the training accuracy:
Epoch 1/2 270/270 [==============================] - 36s 135ms/step - loss: 0.6659 - acc: 0.6074 - val_loss: 0.5956 - val_acc: 0.7100
Epoch 2/2 270/270 [==============================] - 32s 119ms/step - loss: 0.5714 - acc: 0.7122 - val_loss: 0.5651 - val_acc: 0.7267
My questions are:
- For first run, is it possible that the training accuracy keeps 0.5 no matter how large the epoch number is, just because a bad training set is selected accidentally? I did not continue the run after epoch is 6.
- Usually the validation accuracy should be worse than training. Is my observation common or not? Or because the data set is too small?
- In the assignment description, it is said we will “build a classifier using the full Cats v Dogs dataset of 25k images”. Why it ends up just 3000 valid images?
Hi,
There are a couple of things. Accuracy 0.5 does not look good, may be the code picked up some garbage valuses. In such cases reset the kernel and run the code again, if it is the same check your model. Randomeness should make the model more robust, by helping neurons not learn the same thing from data. Randomness adds noise to your plots like your training and validation accuracys goes up and down, but consistent accuracy of 0.5 is not because of randomness.
Secondly, seed is used to get the consitent random numbers every time so that you can reproduce consistent results and, understand the code and the model better. Seed is used while developing in initial stages to get consistent results and not while using in practice or while deploying your model.
- Number of epochs is again a hyper parameter. There is not a fixed number nor there are limits like low or high, it generally depends on the volume of data and the size of your model.
- Yes, generally that should be the case.
- what do you mean by valid images? Do you mean to say 3000 images in the validation set or the whole dataset is of 3000 images?
In Exercise 1 - Cats vs. Dogs | Coursera:it said “One solution to overfitting is to use more data for both training and validation, and that’s this week’s exercise – to build a classifier using the full Cats v Dogs dataset of 25k images”
However, in the whole data set, the total images are 3000 after removing files with zero size. Actually, there is no file will 0 size.
Yes. When overfitting more data will likely help.
Have you passed the assignment? Its should have 11250 images of cats 11250 images of dogs for training and 1250 images for each class for testing. The excersise contains 3000 images but for the weekly assignment the above should be the case. Please let me know others have the same issue.