This documentation details using Teachable Machine for image and pose classification, including model loading, object classification, label display, skeleton drawing, and converting results to JSON.
Image
Loading Custom Image Model from URL
Load image model from internet
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>duration</variable></variables><block type=\"TeachableMachine_loadImageModel\" disabled=\"true\" x=\"-23\" y=\"112\"><value name=\"baseUrl\"><shadow type=\"text\" disabled=\"true\"><field name=\"TEXT\"/></shadow></value></block></xml>"}
This is used to load the image model from the URL.
Parameters: String (URL)
Output: Model Prediction Result (From Teachable Machine Image Model)
Sample code:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>imageModel</variable><variable>imagePredictionResult</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">imageModel</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"TeachableMachine_loadImageModel\"><value name=\"baseUrl\"><shadow type=\"text\"><field name=\"TEXT\">https://teachablemachine.withgoogle.com/models/tghdF3FXI/</field></shadow></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">imagePredictionResult</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"TeachableMachine_ImageModel_predict\"><value name=\"imageModel\"><block type=\"variables_get\"><field name=\"VAR\">imageModel</field></block></value><value name=\"photo\"><block type=\"Resources_getPhotoByURL\"><value name=\"url\"><shadow type=\"text\"><field name=\"TEXT\">https://image.shutterstock.com/image-photo/boy-raising-two-fingers-on-260nw-297974771.jpg</field></shadow></value></block></value></block></value><next><block type=\"Camera_showPhoto\"><value name=\"photo\"><block type=\"Resources_getPhotoByURL\"><value name=\"url\"><shadow type=\"text\"><field name=\"TEXT\">https://image.shutterstock.com/image-photo/boy-raising-two-fingers-on-260nw-297974771.jpg</field></shadow></value></block></value><next><block type=\"basic_consoleLogText\"><value name=\"text\"><block type=\"Json_JsonValue_stringify\"><value name=\"jsonValue\"><block type=\"TeachableMachine_ImagePredictionResult_getResults\"><value name=\"imagePredictionResult\"><block type=\"variables_get\"><field name=\"VAR\">imagePredictionResult</field></block></value></block></value></block></value></block></next></block></next></block></next></block></statement></block></xml>"}
The output:
Classifying Objects on Image
Image Model classify objects on photo and get top … result
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>imageModel</variable><variable>imagePredictionResult</variable></variables><block type=\"TeachableMachine_ImageModel_predictTopK\" disabled=\"true\" x=\"-23\" y=\"202\"><value name=\"imageModel\"><block type=\"variables_get\" disabled=\"true\"><field name=\"VAR\">imageModel</field></block></value><value name=\"maxPredictions\"><shadow type=\"math_number\" disabled=\"true\"><field name=\"NUM\">0</field></shadow></value></block></xml>"}
This is used for loading the image model and classify objects on image and give the most appropriate result.
Parameters:
- AI Model (Teachable Machine Image Model)
- Image
- Number (Default: 0)
Output: Model Prediction Result (From Teachable Machine Image Model)
Sample code:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>imageModel</variable><variable>imagePredictionResult</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">imageModel</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"TeachableMachine_loadImageModel\"><value name=\"baseUrl\"><shadow type=\"text\"><field name=\"TEXT\">https://teachablemachine.withgoogle.com/models/tghdF3FXI/</field></shadow></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">imagePredictionResult</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"TeachableMachine_ImageModel_predictTopK\"><value name=\"imageModel\"><block type=\"variables_get\"><field name=\"VAR\">imageModel</field></block></value><value name=\"photo\"><block type=\"Resources_getPhotoByURL\"><value name=\"url\"><shadow type=\"text\"><field name=\"TEXT\">https://image.shutterstock.com/image-photo/boy-raising-two-fingers-on-260nw-297974771.jpg</field></shadow></value></block></value><value name=\"maxPredictions\"><shadow type=\"math_number\"><field name=\"NUM\">1</field></shadow></value></block></value><next><block type=\"Camera_showPhoto\"><value name=\"photo\"><block type=\"Resources_getPhotoByURL\"><value name=\"url\"><shadow type=\"text\"><field name=\"TEXT\">https://image.shutterstock.com/image-photo/boy-raising-two-fingers-on-260nw-297974771.jpg</field></shadow></value></block></value><next><block type=\"basic_consoleLogText\"><value name=\"text\"><block type=\"Json_JsonValue_stringify\"><value name=\"jsonValue\"><block type=\"TeachableMachine_ImagePredictionResult_getResults\"><value name=\"imagePredictionResult\"><block type=\"variables_get\"><field name=\"VAR\">imagePredictionResult</field></block></value></block></value></block></value></block></next></block></next></block></next></block></statement></block></xml>"}
The output:
Classifying Objects on Image and Get All Result
Image Model classify objects on photo and get all result
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>imageModel</variable><variable>imagePredictionResult</variable></variables><block type=\"TeachableMachine_ImageModel_predict\" disabled=\"true\" x=\"-23\" y=\"247\"><value name=\"imageModel\"><block type=\"variables_get\" disabled=\"true\"><field name=\"VAR\">imageModel</field></block></value></block></xml>"}
This is used for loading the image model and classify objects on image and get all result.
Parameters:
- AI Model (Teachable Machine Image Model)
- Image
- Number (Default: 0)
Output: Model Prediction Result (From Teachable Machine Image Model)
Sample code:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>imageModel</variable><variable>imagePredictionResult</variable></variables><block type=\"pxt-on-start\" x=\"20\" y=\"20\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">imageModel</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"TeachableMachine_loadImageModel\"><value name=\"baseUrl\"><shadow type=\"text\"><field name=\"TEXT\">https://teachablemachine.withgoogle.com/models/tghdF3FXI/</field></shadow></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">imagePredictionResult</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"TeachableMachine_ImageModel_predict\"><value name=\"imageModel\"><block type=\"variables_get\"><field name=\"VAR\">imageModel</field></block></value><value name=\"photo\"><block type=\"Resources_getPhotoByURL\"><value name=\"url\"><shadow type=\"text\"><field name=\"TEXT\">https://image.shutterstock.com/image-photo/boy-raising-two-fingers-on-260nw-297974771.jpg</field></shadow></value></block></value></block></value><next><block type=\"Camera_showPhoto\"><value name=\"photo\"><block type=\"Resources_getPhotoByURL\"><value name=\"url\"><shadow type=\"text\"><field name=\"TEXT\">https://image.shutterstock.com/image-photo/boy-raising-two-fingers-on-260nw-297974771.jpg</field></shadow></value></block></value><next><block type=\"basic_consoleLogText\"><value name=\"text\"><block type=\"Json_JsonValue_stringify\"><value name=\"jsonValue\"><block type=\"TeachableMachine_ImagePredictionResult_getResults\"><value name=\"imagePredictionResult\"><block type=\"variables_get\"><field name=\"VAR\">imagePredictionResult</field></block></value></block></value></block></value></block></next></block></next></block></next></block></statement></block></xml>"}
The output:
Showing the Class Labels in Image Model
Image Model get class labels
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>imageModel</variable><variable>imagePredictionResult</variable></variables><block type=\"TeachableMachine_ImageModel_getClassLabels\" disabled=\"true\" x=\"23\" y=\"293\"><value name=\"imageModel\"><block type=\"variables_get\" disabled=\"true\"><field name=\"VAR\">imageModel</field></block></value></block></xml>"}
This is used for getting class labels from image model.
Parameters: AI Model (Teachable Machine Image Model)
Output: Array
Sample code:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>imageModel</variable><variable>imagePredictionResult</variable><variable>labels</variable><variable>index</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">imageModel</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"TeachableMachine_loadImageModel\"><value name=\"baseUrl\"><shadow type=\"text\"><field name=\"TEXT\">https://teachablemachine.withgoogle.com/models/tghdF3FXI/</field></shadow></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">imagePredictionResult</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"TeachableMachine_ImageModel_predict\"><value name=\"imageModel\"><block type=\"variables_get\"><field name=\"VAR\">imageModel</field></block></value><value name=\"photo\"><block type=\"Resources_getPhotoByURL\"><value name=\"url\"><shadow type=\"text\"><field name=\"TEXT\">https://image.shutterstock.com/image-photo/boy-raising-two-fingers-on-260nw-297974771.jpg</field></shadow></value></block></value></block></value><next><block type=\"Camera_showPhoto\"><value name=\"photo\"><block type=\"Resources_getPhotoByURL\"><value name=\"url\"><shadow type=\"text\"><field name=\"TEXT\">https://image.shutterstock.com/image-photo/boy-raising-two-fingers-on-260nw-297974771.jpg</field></shadow></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">labels</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"TeachableMachine_ImageModel_getClassLabels\"><value name=\"imageModel\"><block type=\"variables_get\"><field name=\"VAR\">imageModel</field></block></value></block></value><next><block type=\"basic_consoleLogText\"><value name=\"text\"><block type=\"Json_JsonValue_stringify\"><value name=\"jsonValue\"><block type=\"TeachableMachine_ImagePredictionResult_getResults\"><value name=\"imagePredictionResult\"><block type=\"variables_get\"><field name=\"VAR\">imagePredictionResult</field></block></value></block></value></block></value><next><block type=\"pxt_controls_for\"><value name=\"VAR\"><shadow type=\"variables_get_reporter\"><field name=\"VAR\">index</field></shadow></value><value name=\"TO\"><shadow type=\"math_whole_number\"><field name=\"NUM\">0</field></shadow><block type=\"math_arithmetic\"><field name=\"OP\">MINUS</field><value name=\"A\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"lists_length\"><value name=\"VALUE\"><block type=\"variables_get\"><field name=\"VAR\">labels</field></block></value></block></value><value name=\"B\"><shadow type=\"math_number\"><field name=\"NUM\">1</field></shadow></value></block></value><statement name=\"DO\"><block type=\"basic_consoleLogText\"><value name=\"text\"><block type=\"lists_index_get\"><value name=\"LIST\"><block type=\"variables_get\"><field name=\"VAR\">labels</field></block></value><value name=\"INDEX\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"variables_get\"><field name=\"VAR\">index</field></block></value></block></value></block></statement></block></next></block></next></block></next></block></next></block></next></block></statement></block></xml>"}
The output:
Showing the Total Amount of Classes with Image Model
Image Model get total number of classes
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>poseModel</variable><variable>posePredictionResult</variable><variable>imageModel</variable></variables><block type=\"TeachableMachine_ImageModel_getTotalClasses\" disabled=\"true\" x=\"-22\" y=\"-22\"><value name=\"imageModel\"><block type=\"variables_get\" disabled=\"true\"><field name=\"VAR\">imageModel</field></block></value></block></xml>"}
This is used to get the full number of classes.
Parameters: AI Model (Teachable Machine Image Model)
Output: Number
Sample code:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>imageModel</variable><variable>imagePredictionResult</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">imageModel</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"TeachableMachine_loadImageModel\"><value name=\"baseUrl\"><shadow type=\"text\"><field name=\"TEXT\">https://teachablemachine.withgoogle.com/models/tghdF3FXI/</field></shadow></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">imagePredictionResult</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"TeachableMachine_ImageModel_predict\"><value name=\"imageModel\"><block type=\"variables_get\"><field name=\"VAR\">imageModel</field></block></value><value name=\"photo\"><block type=\"Resources_getPhotoByURL\"><value name=\"url\"><shadow type=\"text\"><field name=\"TEXT\">https://image.shutterstock.com/image-photo/boy-raising-two-fingers-on-260nw-297974771.jpg</field></shadow></value></block></value></block></value><next><block type=\"Camera_showPhoto\"><value name=\"photo\"><block type=\"Resources_getPhotoByURL\"><value name=\"url\"><shadow type=\"text\"><field name=\"TEXT\">https://image.shutterstock.com/image-photo/boy-raising-two-fingers-on-260nw-297974771.jpg</field></shadow></value></block></value><next><block type=\"basic_consoleLogText\"><value name=\"text\"><block type=\"Json_JsonValue_stringify\"><value name=\"jsonValue\"><block type=\"TeachableMachine_ImagePredictionResult_getResults\"><value name=\"imagePredictionResult\"><block type=\"variables_get\"><field name=\"VAR\">imagePredictionResult</field></block></value></block></value></block></value><next><block type=\"basic_consoleLogNum\"><value name=\"num\"><block type=\"TeachableMachine_ImageModel_getTotalClasses\"><value name=\"imageModel\"><block type=\"variables_get\"><field name=\"VAR\">imageModel</field></block></value></block></value></block></next></block></next></block></next></block></next></block></statement></block></xml>"}
The output:
Pose
Loading Custom Pose Model from URL
Load pose model from internet
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>imageModel</variable><variable>imagePredictionResult</variable></variables><block type=\"TeachableMachine_loadPoseModel\" disabled=\"true\" x=\"-22\" y=\"158\"><value name=\"baseUrl\"><shadow type=\"text\" disabled=\"true\"><field name=\"TEXT\"/></shadow></value></block></xml>"}
This is used to load the pose model from the internet with the URL.
Parameters: String (URL)
Output: Model Prediction Result (From Teachable Machine Pose Model)
Sample code:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>poseModel</variable><variable>posePredictionResult</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">poseModel</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"TeachableMachine_loadPoseModel\"><value name=\"baseUrl\"><shadow type=\"text\"><field name=\"TEXT\">https://teachablemachine.withgoogle.com/models/LL-rF1gZS/</field></shadow></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">posePredictionResult</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"TeachableMachine_PoseModel_predict\"><value name=\"poseModel\"><block type=\"variables_get\"><field name=\"VAR\">poseModel</field></block></value><value name=\"photo\"><block type=\"Resources_getPhotoByURL\"><value name=\"url\"><shadow type=\"text\"><field name=\"TEXT\">https://i2.wp.com/runnersfirst.co.uk/wp-content/uploads/2019/01/running-woman.jpg?resize=678%2C381&ssl=1</field></shadow></value></block></value></block></value><next><block type=\"Camera_showPhoto\"><value name=\"photo\"><block type=\"Resources_getPhotoByURL\"><value name=\"url\"><shadow type=\"text\"><field name=\"TEXT\">https://i2.wp.com/runnersfirst.co.uk/wp-content/uploads/2019/01/running-woman.jpg?resize=678%2C381&ssl=1</field></shadow></value></block></value><next><block type=\"basic_consoleLogText\"><value name=\"text\"><block type=\"Json_JsonValue_stringify\"><value name=\"jsonValue\"><block type=\"TeachableMachine_PosePredictionResult_getResults\"><value name=\"posePredictionResult\"><block type=\"variables_get\"><field name=\"VAR\">posePredictionResult</field></block></value></block></value></block></value></block></next></block></next></block></next></block></statement></block></xml>"}
The output:
Classifying Pose on Image
Pose Model classify pose on photo and get top … result
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>poseModel</variable><variable>posePredictionResult</variable><variable>imageModel</variable></variables><block type=\"TeachableMachine_PoseModel_predictTopK\" disabled=\"true\" x=\"-22\" y=\"203\"><value name=\"poseModel\"><block type=\"variables_get\" disabled=\"true\"><field name=\"VAR\">poseModel</field></block></value><value name=\"maxPredictions\"><shadow type=\"math_number\" disabled=\"true\"><field name=\"NUM\">0</field></shadow></value></block></xml>"}
This is used for loading the pose model to classify pose on image and get the appropriate result.
Parameters:
- AI Model (Teachable Machine Pose Model)
- Image
- Number (Default: 0)
Output: Model Prediction Result (From Teachable Machine Pose Model)
Sample code:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>poseModel</variable><variable>posePredictionResult</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">poseModel</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"TeachableMachine_loadPoseModel\"><value name=\"baseUrl\"><shadow type=\"text\"><field name=\"TEXT\">https://teachablemachine.withgoogle.com/models/LL-rF1gZS/</field></shadow></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">posePredictionResult</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"TeachableMachine_PoseModel_predictTopK\"><value name=\"poseModel\"><block type=\"variables_get\"><field name=\"VAR\">poseModel</field></block></value><value name=\"photo\"><block type=\"Resources_getPhotoByURL\"><value name=\"url\"><shadow type=\"text\"><field name=\"TEXT\">https://i2.wp.com/runnersfirst.co.uk/wp-content/uploads/2019/01/running-woman.jpg?resize=678%2C381&ssl=1</field></shadow></value></block></value><value name=\"maxPredictions\"><shadow type=\"math_number\"><field name=\"NUM\">1</field></shadow></value></block></value><next><block type=\"Camera_showPhoto\"><value name=\"photo\"><block type=\"Resources_getPhotoByURL\"><value name=\"url\"><shadow type=\"text\"><field name=\"TEXT\">https://i2.wp.com/runnersfirst.co.uk/wp-content/uploads/2019/01/running-woman.jpg?resize=678%2C381&ssl=1</field></shadow></value></block></value><next><block type=\"basic_consoleLogText\"><value name=\"text\"><block type=\"Json_JsonValue_stringify\"><value name=\"jsonValue\"><block type=\"TeachableMachine_PosePredictionResult_getResults\"><value name=\"posePredictionResult\"><block type=\"variables_get\"><field name=\"VAR\">posePredictionResult</field></block></value></block></value></block></value></block></next></block></next></block></next></block></statement></block></xml>"}
The output:
Classifying Pose on Image and Get All Result
Pose Model classify pose on photo and get all result
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>poseModel</variable><variable>posePredictionResult</variable></variables><block type=\"TeachableMachine_PoseModel_predict\" disabled=\"true\" x=\"-202\" y=\"-67\"><value name=\"poseModel\"><block type=\"variables_get\" disabled=\"true\"><field name=\"VAR\">poseModel</field></block></value></block></xml>"}
This is used for loading the pose model to classify pose on image and get all result.
Parameters:
- AI Model (Teachable Machine Pose Model)
- Image
- Number (Default: 0)
Output: Model Prediction Result (From Teachable Machine Pose Model)
Sample code:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>poseModel</variable><variable>posePredictionResult</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">poseModel</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"TeachableMachine_loadPoseModel\"><value name=\"baseUrl\"><shadow type=\"text\"><field name=\"TEXT\">https://teachablemachine.withgoogle.com/models/LL-rF1gZS/</field></shadow></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">posePredictionResult</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"TeachableMachine_PoseModel_predict\"><value name=\"poseModel\"><block type=\"variables_get\"><field name=\"VAR\">poseModel</field></block></value><value name=\"photo\"><block type=\"Resources_getPhotoByURL\"><value name=\"url\"><shadow type=\"text\"><field name=\"TEXT\">https://i2.wp.com/runnersfirst.co.uk/wp-content/uploads/2019/01/running-woman.jpg?resize=678%2C381&ssl=1</field></shadow></value></block></value></block></value><next><block type=\"Camera_showPhoto\"><value name=\"photo\"><block type=\"Resources_getPhotoByURL\"><value name=\"url\"><shadow type=\"text\"><field name=\"TEXT\">https://i2.wp.com/runnersfirst.co.uk/wp-content/uploads/2019/01/running-woman.jpg?resize=678%2C381&ssl=1</field></shadow></value></block></value><next><block type=\"basic_consoleLogText\"><value name=\"text\"><block type=\"Json_JsonValue_stringify\"><value name=\"jsonValue\"><block type=\"TeachableMachine_PosePredictionResult_getResults\"><value name=\"posePredictionResult\"><block type=\"variables_get\"><field name=\"VAR\">posePredictionResult</field></block></value></block></value></block></value></block></next></block></next></block></next></block></statement></block></xml>"}
The output:
Showing the Class Labels in Pose Model
Pose Model get class labels
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>poseModel</variable><variable>posePredictionResult</variable></variables><block type=\"TeachableMachine_PoseModel_getClassLabels\" disabled=\"true\" x=\"-22\" y=\"113\"><value name=\"poseModel\"><block type=\"variables_get\" disabled=\"true\"><field name=\"VAR\">poseModel</field></block></value></block></xml>"}
This is used for getting class labels from pose model.
Parameters: AI Model (Teachable Machine Pose Model)
Output: Array
Sample code:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>poseModel</variable><variable>posePredictionResult</variable><variable>labels</variable><variable>index</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">poseModel</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"TeachableMachine_loadPoseModel\"><value name=\"baseUrl\"><shadow type=\"text\"><field name=\"TEXT\">https://teachablemachine.withgoogle.com/models/LL-rF1gZS/</field></shadow></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">posePredictionResult</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"TeachableMachine_PoseModel_predict\"><value name=\"poseModel\"><block type=\"variables_get\"><field name=\"VAR\">poseModel</field></block></value><value name=\"photo\"><block type=\"Resources_getPhotoByURL\"><value name=\"url\"><shadow type=\"text\"><field name=\"TEXT\">https://i2.wp.com/runnersfirst.co.uk/wp-content/uploads/2019/01/running-woman.jpg?resize=678%2C381&ssl=1</field></shadow></value></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">labels</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"TeachableMachine_PoseModel_getClassLabels\"><value name=\"poseModel\"><block type=\"variables_get\"><field name=\"VAR\">poseModel</field></block></value></block></value><next><block type=\"Camera_showPhoto\"><value name=\"photo\"><block type=\"Resources_getPhotoByURL\"><value name=\"url\"><shadow type=\"text\"><field name=\"TEXT\">https://i2.wp.com/runnersfirst.co.uk/wp-content/uploads/2019/01/running-woman.jpg?resize=678%2C381&ssl=1</field></shadow></value></block></value><next><block type=\"basic_consoleLogText\"><value name=\"text\"><block type=\"Json_JsonValue_stringify\"><value name=\"jsonValue\"><block type=\"TeachableMachine_PosePredictionResult_getResults\"><value name=\"posePredictionResult\"><block type=\"variables_get\"><field name=\"VAR\">posePredictionResult</field></block></value></block></value></block></value><next><block type=\"pxt_controls_for\"><value name=\"VAR\"><shadow type=\"variables_get_reporter\"><field name=\"VAR\">index</field></shadow></value><value name=\"TO\"><shadow type=\"math_whole_number\"><field name=\"NUM\">0</field></shadow><block type=\"math_arithmetic\"><field name=\"OP\">MINUS</field><value name=\"A\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"lists_length\"><value name=\"VALUE\"><block type=\"variables_get\"><field name=\"VAR\">labels</field></block></value></block></value><value name=\"B\"><shadow type=\"math_number\"><field name=\"NUM\">1</field></shadow></value></block></value><statement name=\"DO\"><block type=\"basic_consoleLogText\"><value name=\"text\"><block type=\"lists_index_get\"><value name=\"LIST\"><block type=\"variables_get\"><field name=\"VAR\">labels</field></block></value><value name=\"INDEX\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"variables_get\"><field name=\"VAR\">index</field></block></value></block></value></block></statement></block></next></block></next></block></next></block></next></block></next></block></statement></block></xml>"}
The output:
Showing the Total Amount of Classes with Pose Model
Pose Model get total number of classes
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>poseModel</variable><variable>posePredictionResult</variable><variable>labels</variable><variable>index</variable></variables><block type=\"TeachableMachine_PoseModel_getTotalClasses\" disabled=\"true\" x=\"-22\" y=\"202\"><value name=\"poseModel\"><block type=\"variables_get\" disabled=\"true\"><field name=\"VAR\">poseModel</field></block></value></block></xml>"}
This is used to get the full number of classes from pose model.
Parameters: AI Model (Teachable Machine Pose Model)
Output: Number
Sample code:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>poseModel</variable><variable>posePredictionResult</variable><variable>labels</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">poseModel</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"TeachableMachine_loadPoseModel\"><value name=\"baseUrl\"><shadow type=\"text\"><field name=\"TEXT\">https://teachablemachine.withgoogle.com/models/LL-rF1gZS/</field></shadow></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">posePredictionResult</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"TeachableMachine_PoseModel_predict\"><value name=\"poseModel\"><block type=\"variables_get\"><field name=\"VAR\">poseModel</field></block></value><value name=\"photo\"><block type=\"Resources_getPhotoByURL\"><value name=\"url\"><shadow type=\"text\"><field name=\"TEXT\">https://i2.wp.com/runnersfirst.co.uk/wp-content/uploads/2019/01/running-woman.jpg?resize=678%2C381&ssl=1</field></shadow></value></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">labels</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"TeachableMachine_PoseModel_getClassLabels\"><value name=\"poseModel\"><block type=\"variables_get\"><field name=\"VAR\">poseModel</field></block></value></block></value><next><block type=\"Camera_showPhoto\"><value name=\"photo\"><block type=\"Resources_getPhotoByURL\"><value name=\"url\"><shadow type=\"text\"><field name=\"TEXT\">https://i2.wp.com/runnersfirst.co.uk/wp-content/uploads/2019/01/running-woman.jpg?resize=678%2C381&ssl=1</field></shadow></value></block></value><next><block type=\"basic_consoleLogText\"><value name=\"text\"><block type=\"Json_JsonValue_stringify\"><value name=\"jsonValue\"><block type=\"TeachableMachine_PosePredictionResult_getResults\"><value name=\"posePredictionResult\"><block type=\"variables_get\"><field name=\"VAR\">posePredictionResult</field></block></value></block></value></block></value><next><block type=\"basic_consoleLogNum\"><value name=\"num\"><block type=\"TeachableMachine_PoseModel_getTotalClasses\"><value name=\"poseModel\"><block type=\"variables_get\"><field name=\"VAR\">poseModel</field></block></value></block></value></block></next></block></next></block></next></block></next></block></next></block></statement></block></xml>"}
The output:
Draw All Skeleton and the Key Points
poseDetectionResult draw key points and skeleton with confidence >= 0
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>poseModel</variable><variable>posePredictionResult</variable><variable>labels</variable></variables><block type=\"TeachableMachine_PosePredictionResult_drawKeypointsAndSkeleton\" disabled=\"true\" x=\"-22\" y=\"247\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"false\"></mutation><value name=\"posePredictionResult\"><block type=\"variables_get\" disabled=\"true\"><field name=\"VAR\">posePredictionResult</field></block></value><value name=\"minConfidence\"><shadow type=\"math_number\" disabled=\"true\"><field name=\"NUM\">0</field></shadow></value></block></xml>"}
This block is used for displaying the key points and skeleton line inside the image.
Parameters:
- AI Model (Teachable Machine Pose Model)
- Screen Item (Image)
Output: Image
Sample code:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>poseModel</variable><variable>posePredictionResult</variable><variable>labels</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">poseModel</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"TeachableMachine_loadPoseModel\"><value name=\"baseUrl\"><shadow type=\"text\"><field name=\"TEXT\">https://teachablemachine.withgoogle.com/models/LL-rF1gZS/</field></shadow></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">posePredictionResult</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"TeachableMachine_PoseModel_predict\"><value name=\"poseModel\"><block type=\"variables_get\"><field name=\"VAR\">poseModel</field></block></value><value name=\"photo\"><block type=\"Resources_getPhotoByURL\"><value name=\"url\"><shadow type=\"text\"><field name=\"TEXT\">https://i2.wp.com/runnersfirst.co.uk/wp-content/uploads/2019/01/running-woman.jpg?resize=678%2C381&ssl=1</field></shadow></value></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">labels</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"TeachableMachine_PoseModel_getClassLabels\"><value name=\"poseModel\"><block type=\"variables_get\"><field name=\"VAR\">poseModel</field></block></value></block></value><next><block type=\"Camera_showPhoto\"><value name=\"photo\"><block type=\"TeachableMachine_PosePredictionResult_drawKeypointsAndSkeleton\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"false\"></mutation><value name=\"posePredictionResult\"><block type=\"variables_get\"><field name=\"VAR\">posePredictionResult</field></block></value><value name=\"minConfidence\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow></value></block></value><next><block type=\"basic_consoleLogText\"><value name=\"text\"><block type=\"Json_JsonValue_stringify\"><value name=\"jsonValue\"><block type=\"TeachableMachine_PosePredictionResult_getResults\"><value name=\"posePredictionResult\"><block type=\"variables_get\"><field name=\"VAR\">posePredictionResult</field></block></value></block></value></block></value></block></next></block></next></block></next></block></next></block></statement></block></xml>"}
The output:
Draw All Skeleton Inside a Photo
poseDetectionResult draw skeleton with confidence >= 0
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>poseModel</variable><variable>posePredictionResult</variable><variable>labels</variable></variables><block type=\"TeachableMachine_PosePredictionResult_drawSkeleton\" disabled=\"true\" x=\"-113\" y=\"292\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"false\"></mutation><value name=\"posePredictionResult\"><block type=\"variables_get\" disabled=\"true\"><field name=\"VAR\">posePredictionResult</field></block></value><value name=\"minConfidence\"><shadow type=\"math_number\" disabled=\"true\"><field name=\"NUM\">0</field></shadow></value></block></xml>"}
This block is used for displaying the skeleton line inside the image.
Parameters:
- AI Model (Teachable Machine Pose Model)
- Screen Item (Image)
Output: Image
Sample code:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>poseModel</variable><variable>posePredictionResult</variable><variable>labels</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">poseModel</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"TeachableMachine_loadPoseModel\"><value name=\"baseUrl\"><shadow type=\"text\"><field name=\"TEXT\">https://teachablemachine.withgoogle.com/models/LL-rF1gZS/</field></shadow></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">posePredictionResult</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"TeachableMachine_PoseModel_predict\"><value name=\"poseModel\"><block type=\"variables_get\"><field name=\"VAR\">poseModel</field></block></value><value name=\"photo\"><block type=\"Resources_getPhotoByURL\"><value name=\"url\"><shadow type=\"text\"><field name=\"TEXT\">https://i2.wp.com/runnersfirst.co.uk/wp-content/uploads/2019/01/running-woman.jpg?resize=678%2C381&ssl=1</field></shadow></value></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">labels</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"TeachableMachine_PoseModel_getClassLabels\"><value name=\"poseModel\"><block type=\"variables_get\"><field name=\"VAR\">poseModel</field></block></value></block></value><next><block type=\"Camera_showPhoto\"><value name=\"photo\"><block type=\"TeachableMachine_PosePredictionResult_drawSkeleton\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"false\"></mutation><value name=\"posePredictionResult\"><block type=\"variables_get\"><field name=\"VAR\">posePredictionResult</field></block></value><value name=\"minConfidence\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow></value></block></value><next><block type=\"basic_consoleLogText\"><value name=\"text\"><block type=\"Json_JsonValue_stringify\"><value name=\"jsonValue\"><block type=\"TeachableMachine_PosePredictionResult_getResults\"><value name=\"posePredictionResult\"><block type=\"variables_get\"><field name=\"VAR\">posePredictionResult</field></block></value></block></value></block></value></block></next></block></next></block></next></block></next></block></statement></block></xml>"}
The output:
Draw All Key Points Inside a Photo
poseDetectionResult draw key points with confidence >= 0
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>poseModel</variable><variable>posePredictionResult</variable><variable>labels</variable></variables><block type=\"TeachableMachine_PosePredictionResult_drawKeypoints\" disabled=\"true\" x=\"-22\" y=\"382\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"false\"></mutation><value name=\"posePredictionResult\"><block type=\"variables_get\" disabled=\"true\"><field name=\"VAR\">posePredictionResult</field></block></value><value name=\"minConfidence\"><shadow type=\"math_number\" disabled=\"true\"><field name=\"NUM\">0</field></shadow></value></block></xml>"}
This block is used for displaying the key points inside the image.
Parameters:
- AI Model (Teachable Machine Pose Model)
- Screen Item (Image)
Output: Image
Sample code:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>poseModel</variable><variable>posePredictionResult</variable><variable>labels</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">poseModel</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"TeachableMachine_loadPoseModel\"><value name=\"baseUrl\"><shadow type=\"text\"><field name=\"TEXT\">https://teachablemachine.withgoogle.com/models/LL-rF1gZS/</field></shadow></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">posePredictionResult</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"TeachableMachine_PoseModel_predict\"><value name=\"poseModel\"><block type=\"variables_get\"><field name=\"VAR\">poseModel</field></block></value><value name=\"photo\"><block type=\"Resources_getPhotoByURL\"><value name=\"url\"><shadow type=\"text\"><field name=\"TEXT\">https://i2.wp.com/runnersfirst.co.uk/wp-content/uploads/2019/01/running-woman.jpg?resize=678%2C381&ssl=1</field></shadow></value></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">labels</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"TeachableMachine_PoseModel_getClassLabels\"><value name=\"poseModel\"><block type=\"variables_get\"><field name=\"VAR\">poseModel</field></block></value></block></value><next><block type=\"Camera_showPhoto\"><value name=\"photo\"><block type=\"TeachableMachine_PosePredictionResult_drawKeypoints\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"false\"></mutation><value name=\"posePredictionResult\"><block type=\"variables_get\"><field name=\"VAR\">posePredictionResult</field></block></value><value name=\"minConfidence\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow></value></block></value><next><block type=\"basic_consoleLogText\"><value name=\"text\"><block type=\"Json_JsonValue_stringify\"><value name=\"jsonValue\"><block type=\"TeachableMachine_PosePredictionResult_getResults\"><value name=\"posePredictionResult\"><block type=\"variables_get\"><field name=\"VAR\">posePredictionResult</field></block></value></block></value></block></value></block></next></block></next></block></next></block></next></block></statement></block></xml>"}
The output:
Result
Converting Prediction Result to JsonValue
Prediction Result get results as JsonValue
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>poseModel</variable><variable>posePredictionResult</variable><variable>labels</variable></variables><block type=\"TeachableMachine_PosePredictionResult_getResults\" disabled=\"true\" x=\"-22\" y=\"472\"><value name=\"posePredictionResult\"><block type=\"variables_get\" disabled=\"true\"><field name=\"VAR\">posePredictionResult</field></block></value></block></xml>"}
This is used to convert the image prediction result to Json Value.
Parameters: AI Model (Teachable Machine Pose Model)
Output: Json Value
Sample code:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>poseModel</variable><variable>posePredictionResult</variable><variable>labels</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">poseModel</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"TeachableMachine_loadPoseModel\"><value name=\"baseUrl\"><shadow type=\"text\"><field name=\"TEXT\">https://teachablemachine.withgoogle.com/models/LL-rF1gZS/</field></shadow></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">posePredictionResult</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"TeachableMachine_PoseModel_predict\"><value name=\"poseModel\"><block type=\"variables_get\"><field name=\"VAR\">poseModel</field></block></value><value name=\"photo\"><block type=\"Resources_getPhotoByURL\"><value name=\"url\"><shadow type=\"text\"><field name=\"TEXT\">https://i2.wp.com/runnersfirst.co.uk/wp-content/uploads/2019/01/running-woman.jpg?resize=678%2C381&ssl=1</field></shadow></value></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">labels</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"TeachableMachine_PoseModel_getClassLabels\"><value name=\"poseModel\"><block type=\"variables_get\"><field name=\"VAR\">poseModel</field></block></value></block></value><next><block type=\"Camera_showPhoto\"><value name=\"photo\"><block type=\"TeachableMachine_PosePredictionResult_drawKeypoints\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"false\"></mutation><value name=\"posePredictionResult\"><block type=\"variables_get\"><field name=\"VAR\">posePredictionResult</field></block></value><value name=\"minConfidence\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow></value></block></value><next><block type=\"basic_consoleLogText\"><value name=\"text\"><block type=\"Json_JsonValue_stringify\"><value name=\"jsonValue\"><block type=\"TeachableMachine_PosePredictionResult_getResults\"><value name=\"posePredictionResult\"><block type=\"variables_get\"><field name=\"VAR\">posePredictionResult</field></block></value></block></value></block></value></block></next></block></next></block></next></block></next></block></statement></block></xml>"}
The output:
Table of Content