Rock, Paper & Scissors with Image Classification
"Using Teachable Machine from Google to recognize voices"
Updated on: 2023-05-17
Table of Content
Reminder
Resources Available! Click here to download the resources provided in this exercise
Train a model using Teachable Machine
- Go to the Teachable Machine site at https://teachablemachine.withgoogle.com/
- Start the project by clicking “Image Project”
- Record live hand gestures with the respective webcam. (or import the project.tm provided on Blackboard by clicking “Open an existing project from a file”.) Click “Train Model” after setting up the required classes. DO NOT switch to other tabs but stay on the same page during the process!
- Test your model by uploading a “file” or using the webcam to show respective hand gestures after the model is trained.
- Click “Export Model” and “Upload my model” to get the shareable link of the model. Save the link to MS Word or Notepad.
- Click the top left menu bar and click "Download Project as file" to save your project. Hint: You may also try to develop a “Pose Project” to classify “Paper, Scissor, and Rock”. You may compare the accuracy and performance between “Image Project” and “Pose Project” concerning this particular task.
Create a "Rock, Paper & Scissors" game on Scratch
Simple Version(with basic game logic)
- Go to Scratch at https://mitmedialab.github.io/prg-extension-boilerplate/create/.
- Rename the sprite to “Player”
- Add “Teachable Machine” extension
- Paste your model link
- Create Variables
- Add codes blocks as shown below to this “Player” sprite.
- Add “Computer” sprite as your enemy
- Add code blocks to “Computer Sprite” as shown below
- Authorize browser to use the camera and play a “Paper, Scissor, and Rock” game with computer.
- Click File and then click “Save to your computer” to save your current project.
- Record a video for a complete demonstration.
Optional Exercise
Full Version(with clear UI design and development) Go to Scratch at https://mitmedialab.github.io/prg-extension-boilerplate/create/.
- Click “Add Extension” and choose “Teachable Machine” to add related code blocks to the Code panel.
- You need 4 sprites for our project: “Player”, “Computer”, “Result”, and “Universal” Go to “Choose a Sprite” and click “Paint”. Then rename the sprite as “Universal”.
- Go back to “Codes”, then paste the previous exported Teachable Machine link to “Use model…” code block.
- Add the code blocks according to the photo below.
- Go back to “Code” and add the code blocks according to the photo below.
- Go to “Choose a Sprite” and click “Paint”. Then rename the sprite as “Result”.
- Click “T” to add new text which displays “Player Win!” and rename the costume as “playerwin”. You may adjust the text according to your preference.
- Right-click the costume to duplicate the costume twice. Amend the text as “Computer Win!” and “ Draw!”, then rename the costumes as “computerwin” and “draw” respectively.
- Go back to “Code” and add the code blocks according to the photo below.
- Go to “Choose a Sprite” and click “Upload Sprite”. Then upload paper.png (provided on Blackboard).
- Click “Costumes”, go to “Choose a Costume” and select “Upload Costume”. Then upload rock.png and scissors.png (provided on Blackboard).
- Click the “Player” sprite, then add the code blocks according to the photo below.
- Go back to “Code” and change the sprite name to “Player”. Then right-click the “Player” sprite to duplicate the sprite and rename the copied sprite as “Computer”.
- You may flip the sprite of computer horizontally in “Costume”
- Click the “Computer” sprite, then add the code blocks according to the photo below.
- You may try out the game now!