You can already train an image model for hand gestures. Today in Scratch you will load that model into a rock, paper, scissors game and play against the computer.
Before you build, think: what might go wrong if the model is only slightly sure about a gesture? Open the project space you saved earlier and get ready to build step by step: predict, run, investigate, modify, then make it your own.
Your rock, paper, scissors game has four parts:
The confidence threshold is the interesting one: it decides how sure the model has to be before your game acts on what it thinks it sees.
Go to https://stretch3.github.io/ and start a new Scratch project and delete the Cat sprite.
Then, add the TM2Scratch extension by clicking on the Extensions button at the bottom left corner of the screen and selecting 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.
Scratch Extensions are additional sets of blocks that expand the capabilities of your Scratch projects. They allow you to:
When you add an extension to your project:
Add a new sprite to the project that will represent the computer's choice in the game. You can choose any sprite you like, but for this example, we'll use the 'Gobo' sprite.
To add a sprite from the sprite library follow these steps:
You can use search box or the filter links (Animals, People, Fantasy etc) to locate your sprite.
Create three new variables:
playerChoice - to store the player's choice.computerChoice - to store the computer's choice.result - to store the result of the game.In the Variables palette, create a new variable by clicking the 'Make a Variable' button.
Once you click this button a box will appear asking what you want to call your variable. Give it a name that reminds you what you will be using it for. For example, if you wanted to keep track of your score in a game, you would create a variable called 'score'.
You're previewing this lesson. Get full access to this lesson and hundreds more — each one ready to teach, with interactive activities, printable resources and pupil progress tracking built in.