This activity is adapted from activities created by Codeweek and licenced under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) licence. You could find the original list of activities in their website. The two datasets used, initial training dataset and test dataset, are also created by them.
We will use Google’s teachable machine to train a machine to classify an image as a bicycle or a motorcycle. To recapitulate, a machine-learning application has to be trained and tested before it can be used. We will gather and group sample pictures of the categories the machine will classify, train the model and test if it classifies correctly a set of example pictures.
Step 1: Gather and group example pictures
- Download the pictures of bicycles found here.
- If necessary, extract the zip folder contents into a local folder on your computer. This will be used as training set for the Machine Learning application.
- Download the pictures of motorcycles found here.
- If necessary, extract the zip-folder contents into a local folder on your computer. This will also be used as training set for the Machine Learning application.
- Download all the pictures found here.
- If necessary, extract the zip-folder contents into a local folder on your computer. This will be used as test dataset.
- Click Google’s Teachable Machine and select Image Project > Standard Image Model.
- Under Class 1, click upload > Choose images from your files > Open the folder of bicycle images you created during steps 1 and 2 and import all the images stored here.
- Under Class 2, click upload > Choose images from your files > Open the folder of motorcycle images you created during steps 3 and 4 and import all the images stored here.
Step 2: Train the model
Under Training, click Train Model. The model learns how to classify bicycles and motorcycles. Wait till it says Model Trained.
Note that we do not have to manually select and input features of bicycles and motorcycles. The algorithms knows how to find its own features from the images!
Step 3: Test the model
- Under Preview, click the arrow near webcam and change input to File.
- Click choose images from your files and choose a test image you stored in steps 5 and 6.
- Scroll down and check output.
- You can repeat with other images to compare performance.
If an image is used to train a classifier, the machine will have already recorded the corresponding label for the particular image. Showing this image to the machine during the testing phase will not measure how well the model generalises. That is why your test and train datasets should be different from each other.
Note: You can also upload your own images to train and test. Here is a good source of free images.