Image Classification Project Using Google Teachable Machine (Part 1)

Abdul Azzam Ajhari
8 min readJan 16, 2023

--

Teachable Machine is a web-based Google AutoML platform that is a tool for creating ML models quickly, easily, and accessible to everyone (Carney, Michelle et.al., Teachable Machine: Approachable Web-Based Tool for Exploring Machine Learning Classification, 2020)

You can create models to classify images, audio, or even poses (movements). Once you have created a model, you can download the trained model to use in your application, thus providing accessibility to various research (H. Kacorri, (2018).Teachable Machines for Accessibility, no. March, doi: 10.1145/3167902.3167904). The Teachable Machine website can be accessed at the url https://teachablemachine.withgoogle.com/.

Figure 1. Main Webpage Google Teachable Machine

The Main Page in Figure 1 contains information about Teachable Machine and how to use it. Teachable Machine model uses a TensorFlow.js algorithm model that can work anywhere on javascript that runs. They are well suited to be combined with tools like Glitch, P5.js, Node.js & others. Additionally, models can be exported to several different formats for use elsewhere such as Coral, Arduino, Android & others. In this book, we will be doing image classification using Teachable Machine and its implementation on Android device.

Several projects that can be done on Teachable Machine can be accessed via https://teachablemachine.withgoogle.com/train and can be seen in Figure 2.

Figure 2. Webpage Project

This time we will be doing image classification using Teachable Machine. If you already have a project saved on Google Drive or your computer, you can open it by selecting the Open an existing project from Drive button in Figure 3 or Open an existing project from a file button in Figure 4.

Figure 3. Open an existing project from Drive
Figure 4. Open an existing project from a file

The Image Project is a part of image classification that teaches the machine through photos or images that are on your computer or camera captures. We can create image classification with several steps as follows.

  • Select the Image Project menu as shown in Figure 5
Figure 5. Image Project
  • After the menu is selected, you will see a popup to determine the choice of images to be classified as shown in Figure 6
Figure 6. Image selection popup

If the model we are going to use is applied to mobile apps or desktop apps, you can select the Standard image model where the color image pixel size is 224x224 and the model size is about 5 megabytes (mb). In the implementation of the model on microcontrollers such as Raspberry, Arduino, and others, you can select the Embedded image model. The pixel size of the images processed on Embedded image model is in the form of a greyscale image with a size of 96x96 and an estimated model size of about 500kb. Since we will be applying the Teachable Machine model on an Android device, we choose the Standard image model.

Figure 7. Image Project Training

By default, the data classes displayed in Figure 7 only have two classes, Class 1 and Class 2. However, with its current development Teachable Machine states that we can add as many data classes as you like.

Because we are still learning to explore, create 2 classes only, which are the phone and laptop classes with each existing image. Then select upload, a choice like in Figure 8 will appear.

Figure 8. File selection section of Images

In Figure 8, select Choose images from your files or you can directly drag & drop image files to Teachable Machine. After uploading, make sure that the display is as shown in Figure 9.

Figure 9. The display of the uploaded images
Figure 10. Training Image Project part

After all the images are uploaded and correct, the next step for us is to adjust the training and test parameters. Adjust the settings as shown in Figure 10 and click the Train Model button.

In the Training Model section, we can choose to Train the model with parameters that have been automatically set by Teachable Machine or we can perform hyperparameter tuning in the Advanced dropdown as shown in Figure 10. We can set the Epochs, Batch size, and Learning rate.

  • Epochs is a hyperparameter that determines the number of learning algorithms working on processing the entire training dataset. The number of iterations performed in processing the dataset is represented by the number of Epochs value.
  • Batch size is a hyperparameter of gradient descent that controls the number of training samples to be processed before the internal model parameters are updated. The calculation of Batch size can be done with Calculationas follows.
  • Learning rate is one of the training parameters to calculate the weight correction value at the time of the training process. The learning rate value is in the range of zero (0) to one (1). The greater the learning rate value, the faster the training process will run but the accuracy of the model network will decrease. Conversely, the smaller the learning rate value, the higher the accuracy of the model network will be or increase with the consequence that the training process will take longer.

After you adjust the parameters, the model will be evaluated for performance. The dataset we entered will be divided into 85% as training data and 15% as test data.

  • Training data/ training samples are used to train the model correctly in classifying data into the classes that have been created.
  • Test data/ test samples are not used in training the model, so after the model is trained with the training data, that data is used to evaluate the performance of the model on new unknown data using a confusion matrix.

The model performance is measured based on the classification of the test data compared to its ground truth. Comparison of classification results and ground truth test data is tabulated into a confusion matrix as shown in Figure 11.

Figure 11. Confusion matrix

From the confusion matrix in Figure 11, there are four terms representing the results of the classification process, namely true positive, true negative, false positive, and false negative, which can be explained as follows.

  1. True Positive (TP) is positive data that is predicted correctly or true class data that is classified as positive class.
  2. True negative (TN) is a negative data that is correctly predicted or a wrong class data that is classified as negative class.
  3. False positive (FP) or type one error, is a negative data that is incorrectly predicted as positive or a wrong class data that is classified as positive class.
  4. False negative (FN) or type two error, is a true class data that is incorrectly predicted as negative or a true class data that is classified as wrong class.

The calculation of confusion matrix is divided into four stages, namely accuracy, precision, recall, and f1-score, which can be explained as follows:

  • Accuracy, used to calculate the classification accuracy in measuring the performance of data prediction
  • Precision, technique for measuring the ratio of correctly predicted positive observations.
  • Recall, where the ratio of correctly predicted positive observations to all observations in the actual class.
  • F1-score, produces a value that is balanced between the calculation of the average of precision and recall.

From 100 image dataset in each class (handphone and laptop) divided into 85% training data or about 85 data for each class and 15% test data about 15 data for each class. The results of overall accuracy training and test accuracy performance evaluation can be seen in Figure 12 and Figure 13.

Figure 12. Evaluation Performance of Accuracy per epoch

Figure 12 shows the performance evaluation of overall accuracy training which obtains the maximum value, that is acc:1 or 100%. While the test accuracy value has a similar value, that is test acc: 0.933333277702 or 93%.

Figure 13. Evaluation Performance of Loss

In addition to obtaining the value of overall accuracy training and test accuracy performance evaluation, we are also given the loss value of each accuracy in Figure 13. The loss of overall accuracy training is obtained at 0.0001957 or 0.0002% and the loss of test accuracy is obtained at 0.07%.

The performance of testing each class is calculated using the confusion matrix which can be seen in Figure 14.

Figure 14. Performance Evaluation of Testing with Confusion Matrix

It can be seen the performance of each class in Figure 14, for the handphone class it gets an accuracy of 0.87 or 87% and laptop class accuracy is 1 or 100%. Only in the handphone class there are 2 datasets that experienced misclassification.

Figure 15. Preview Model

After you feel that the performance of the model has been optimal and in line with expectations, you can try it directly by uploading the image file you want to test as in Figure 15. Since we will try to implement the model on the android application, we need to download the model on the Export Model menu in Figure 16.

Figure 16. Export Model

After we download the model, the next step is to implement the model on the android device which will be published in the next article (Part 2).

--

--

Responses (1)