Additional Content

Hands-on Machine Learning

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

  1. Download the pictures of bicycles found here.
  2. 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.
  3. Download the pictures of motorcycles found here.
  4. 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.
  5. Download all the pictures found here.
  6. If necessary, extract the zip-folder contents into a local folder on your computer. This will be used as test dataset.
  7. Click Google’s Teachable Machine and select Image Project > Standard Image Model.
  8. 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.
  9. 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!

Source : Google’s Teachable machine

Step 3: Test the model

  1. Under Preview, click the arrow near webcam and change input to File.
  2. Click choose images from your files and choose a test image you stored in steps 5 and 6.
  3. Scroll down and check output.
  4. 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.

Licence

Icon for the Creative Commons Attribution 4.0 International License

AI for Teachers: an Open Textbook Copyright © 2024 by Colin de la Higuera and Jotsna Iyer is licensed under a Creative Commons Attribution 4.0 International License, except where otherwise noted.

Share This Book