Coding Ireland STEM Report 2024 Have Your Say
Scratch Artificial Intelligence
Intermediate
60 mins
165 points
What you need:
Computer/laptop
Webcam

Scratch AI Image Model

In this lesson, you will create a Scratch project that uses the TM2Scratch extension to recognize rock, paper, and scissors hand gestures using a Google Teachable Machine Image model.

Note: You will need a webcam or a camera on your computer to do this project.

Learning Goals Learning Outcomes Teacher Notes Lesson Files

1 - Introduction

In this lesson, you will create a Scratch project that uses a Google Teachable Machine Image model to recognize rock, paper, and scissors hand gestures.

If you have not created your own image model in the previous lesson, you can use the following link for an image model that has been trained to recognise rock, paper and scissors hand gestures.

https://teachablemachine.withgoogle.com/models/wUzRtfVIZ/


2 - Create a New Project

First, go to stretch3.github.io to create a new Scratch project.

Stretch3 is an experimental version of Scratch 3 that allows you to use additional extensions like TM2Scratch, which we will need for using our AI image model.

3 - Add the TM2Scratch Extension

Now, let's add the TM2Scratch extension to your project.

Click on the 'Extensions' button at the bottom-left corner of the screen, and then click on 'TM2Scratch'. This extension allows you to use Google Teachable Machine Image models in your Scratch projects.

When you add this extension, it will automatically try and use your computer's camera. If necessary, click on 'Allow' to give it permission to use your camera. You should see what the camera is showing in the stage area.



4 - Set Up the Image Model

Now, let's set up the image model that our project will use. Add the following code to the Cat sprite:

when green flag clicked turn video [on v] :: extension Label once every (1 v) seconds :: extension image classification model URL [link to your model] :: extension

Put the link of your image model into the image classification model URL block.

Here's what the code does:

  • turn video [on v]: This block turns on the video from your webcam or computer camera.
  • Label once every (1 v) seconds: This block tells the program to recognize the hand gesture every second.
  • image classification model URL [link to your model]: This block sets the URL of the image model that will be used to recognize the hand gestures.
If you don't have your own image model URL, you can use this one: https://teachablemachine.withgoogle.com/models/wUzRtfVIZ/

5 - Display Image Label

Click on the 'image label' block in the TM2Scratch extension category to turn it on. This will show you the current image label being applied to what's being recorded on your webcam.


Unlock the Full Learning Experience

Get ready to embark on an incredible learning journey! Get access to this lesson and hundreds more in our courses.

Copyright Notice
This lesson is copyright of Coding Ireland. Unauthorised use, copying or distribution is not allowed.

Scratch is developed by the Lifelong Kindergarten Group at the MIT Media Lab. It is available for free at https://scratch.mit.edu
🍪 Our website uses cookies to make your browsing experience better. By using our website you agree to our use of cookies. Learn more