Original article was published by Tee Yee Yang on Artificial Intelligence on Medium
This will be an interactive post using Google Colab notebooks. If you have not used Google Colab before, there is a quick-start tutorial at tutorialspoint. You can access the notebook at this link: Train your first DL model. First, make a copy and save it into your Drive so that you can access it and make changes. Next, make sure the runtime is set to GPU so you can make use of the free resources provided by Google.
!pip install -Uqq fastbook
Running the first code block will install the fastbook package onto the Google Colab environment. Don’t worry, nothing will be installed onto your computer!
Running the second code block will perform a bunch of things:
- Images from the Oxford-IIIT Pet Dataset that contains about 7,000 images of cats and dogs from 37 breeds will be downloaded and stored onto the Google Colab environment.
- A DataLoader object will be created, and this will feed the images to your model for training. Next, a few random images from the DataLoader will be presented in the output. This is one of the advantages of working in a notebook environment; we can easily look at our data as we work!
learn = cnn_learner(dls, resnet34, metrics=error_rate)
The third code block performs the actual training of the model. You will see a progress bar as this happens, and it should be completed in about 2 minutes if you selected the GPU runtime properly. There are many terms introduced such as loss and epochs, but these will be covered in future lessons. For now, just focus on the error rate: a value of 0.0054 means that only 0.54% of images were wrongly classified, that’s pretty good for just 2 minutes of training!
The final code block will create an interactive application within the notebook itself. Here you will see two buttons: Upload and Classify. I downloaded a picture of a cat on the left from Unsplash and uploaded that onto the application. Afterwards, click on classify so that your model can predict what animal it is. The prediction will be printed below the image, along with the probability. Do try it out with your own images of cats and dogs!