Use an image classification model from Teachable Machine to recognise images and make Marty respond in Blocks. The model uses your computer or tablet's camera; Marty needs to be connected when you want the robot to perform an action.
New to Teachable Machine? Start with its videos on gathering samples and training a model. For a model built directly in Blocks, see Machine Learning in Blocks.
Copy the model link, which has the form https://teachablemachine.withgoogle.com/models/…/. You do not need to copy the JavaScript code shown below it.
Paste the shareable link into Paste TM model URL here, then select Load.
Wait for the imported model to appear in the Models list. It is already trained, so you do not need to train it again in Blocks. Keep the same Marty device selected when you return to Code: the imported model belongs to that device in your project.
In Code, choose Machine Learning. Drag Load Machine Learning model into your program and select the imported model from its dropdown. Place it below when green flag clicked, then click the green flag to load it before using the prediction blocks.
Allow Blocks to use your camera when prompted. Loading an image model starts continuous classification. Use turn classification off/on to pause or resume it; classify image requests an image classification.
The examples below use a model named Image example with a Rock class. Choose your own model and class names. These are alternative ways to respond to a prediction:
Tick the checkbox beside image label in the palette to display the latest label. It may be empty when no prediction meets the confidence threshold.
Use turn video on to show the camera preview on the stage. Select Switch to large stage beside the green flag and stop controls for a larger view. turn video off hides the stage preview; use turn classification off separately when you want to pause predictions.
To keep your imported model and code, save the project from Save/Load.