Distracted Driver Day 3 — Modelling part 1
Welcome back! In the last blog, we pre-processed our data to bring it into a form that our models understand — numbers. In this blog, I will write about the steps I took for modelling.
Transfer-Learning and MobileNet
Transfer Learning is a process where we use pre-trained models and modify them to suit our needs.
Advantages of Transfer Learning :
- Comparatively less data is required
- Pre-defined weights help in better accuracy
- Easier and quicker to train
Modifying our labels
When I tried to train my MobileNet model, I ran into an unexpected error and the model architecture required our labels to be in the form of numbers instead of “c0”, “c1” and so on.
Instead of changing the whole data pre-processing steps, I removed the first character of every labels and converted the remaining character to integers.
earlier, the code was: label = cut[:ind]
this would return “c0”. Now, it returns 0.
After this small change, my model trained normally.
Resizing our images
I had also forgotten to resize the images to (224, 224, 3) from (480, 640, 3). I changed this in the process_image()
function by adding tf.image.resize(image, (224, 224))
Callbacks
Callbacks are special functions that monitor the training of the model and change it or record it in some way.
The callback I used was EarlyStopping callback. this callback monitors the model’s accuracy on the validation split and stops training if the model’s progress stops after a certain “patience”. This helps the model from overfitting (the machine learns the pattern too well and can’t generalize) as it stops the model before it overfits.
Building and training the model
As I mentioned before, I am using MobileNet for my project. I used the default weights for this project, which is imagenet and trained it for 50 epochs. I used CategoricalCrossentropy as my loss function (how wrong our model is)and Adam as my optimizer (an algorithm that tells the model how to improve). my learning rate was 0.0023 (A parameter of Adam; 0.0023 was an arbitrary number). I also used the EarlyStopping callback while training to prevent overfitting.
The model had trained for 14 epochs when my callback stopped it. the final accuracy on train data was 51.22% and the accuracy on validation data was 52.78%.
Conclusion
I couldn’t do much today as model training takes a lot of time (Partly because I forgot to use GPU). I won’t be able to do anything tomorrow, but the day after tomorrow, I will be improving this model by tweaking some of the hyperparameters.
That’s it for today. Bye!