Rock, Paper & Scissors with Image Classification

"Using Teachable Machine from Google to recognize voices"

Updated on: 2023-05-17
Reminder
Resources Available! Click here to download the resources provided in this exercise

Train a model using Teachable Machine

  1. Go to the Teachable Machine site at https://teachablemachine.withgoogle.com/
  2. Start the project by clicking “Image Project” image1
  3. 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! image2
  4. Test your model by uploading a “file” or using the webcam to show respective hand gestures after the model is trained. image3
  5. Click “Export Model” and “Upload my model” to get the shareable link of the model. Save the link to MS Word or Notepad.
  6. Click the top left menu bar and click "Download Project as file" to save your project. image4 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. image5

Create a "Rock, Paper & Scissors" game on Scratch

Simple Version(with basic game logic)

  1. Go to Scratch at https://mitmedialab.github.io/prg-extension-boilerplate/create/. image6
  2. Rename the sprite to “Player”
  3. Add “Teachable Machine” extension image7
  4. Paste your model link image8
  5. Create Variables image9
  6. Add codes blocks as shown below to this “Player” sprite. image10
  7. Add “Computer” sprite as your enemy image11
  8. Add code blocks to “Computer Sprite” as shown below image12
  9. Authorize browser to use the camera and play a “Paper, Scissor, and Rock” game with computer. image13
  10. Click File and then click “Save to your computer” to save your current project. image14
  11. 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/. image15

  1. Click “Add Extension” and choose “Teachable Machine” to add related code blocks to the Code panel. image16
  2. 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”. image17
  3. Go back to “Codes”, then paste the previous exported Teachable Machine link to “Use model…” code block.
  4. Add the code blocks according to the photo below. image18
  5. Go back to “Code” and add the code blocks according to the photo below.
  6. Go to “Choose a Sprite” and click “Paint”. Then rename the sprite as “Result”.
  7. 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.
  8. 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. image19
  9. Go back to “Code” and add the code blocks according to the photo below. image20
  10. Go to “Choose a Sprite” and click “Upload Sprite”. Then upload paper.png (provided on Blackboard). image21
  11. Click “Costumes”, go to “Choose a Costume” and select “Upload Costume”. Then upload rock.png and scissors.png (provided on Blackboard). image22
  12. Click the “Player” sprite, then add the code blocks according to the photo below. image23
  13. 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”. image24
  14. You may flip the sprite of computer horizontally in “Costume” image25
  15. Click the “Computer” sprite, then add the code blocks according to the photo below. image26
  16. You may try out the game now!
We share all the resources here for free.We create practical AI workshops for students to gain hands-on experience and learn AI with fun. They will have more concrete ideas and feel more connected with the AI applications. After collecting the public resources on AI, we plan to create a website to organize these resources and categorize them by AI topics.
Contact

Core E, 6/F, Department of Electronic and Information Engineering, The Hong Kong Polytechnic University, Hung Hom, Kowloon, Hong Kong

pauli.lai@polyu.edu.hk