該文件詳細介紹了如何使用Teachable Machine進行圖像和姿勢分類,包括模型加載、物體分類、標籤顯示、骨架繪製以及將結果轉換為JSON。
圖像
從 URL 載入自訂影像模型
從互聯網載入圖像模型
{"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>"}
這用於從 URL 載入圖像模型。
參數: 字串 (URL)
輸出: 模型預測結果(來自可示教機器圖像模型)
範例代碼:
{"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>"}
輸出:
對圖像上的物件進行分類
影像模型對照片上的物件進行分類並獲得頂部…結果
{"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>"}
這用於載入圖像模型並對圖像上的物件進行分類,並給出最合適的結果。
參數:
- AI模型(可示教機器圖像模型)
- 圖像
- 數字(預設值:0)
輸出: 模型預測結果(來自可示教機器圖像模型)
範例代碼:
{"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>"}
輸出:
對圖像上的物件進行分類並獲取所有結果
圖像模型對照片上的對象進行分類並獲得所有結果
{"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>"}
這用於載入圖像模型並對圖像上的物件進行分類並獲取所有結果。
參數:
- AI模型(可示教機器圖像模型)
- 圖像
- 數字(預設值:0)
輸出: 模型預測結果(來自可示教機器圖像模型)
範例代碼:
{"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>"}
輸出:
在圖像模型中顯示類標籤
圖像模型獲取類標籤
{"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>"}
這用於從圖像模型中獲取類標籤。
參數: AI模型(可示教機器圖像模型)
輸出: 數位語式
範例代碼:
{"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>"}
輸出:
顯示具有圖像模型的類總數
圖像模型獲取類總數
{"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>"}
這用於獲取類的全部數量。
參數: AI模型(可示教機器圖像模型)
輸出: 數位
示例代碼:
{"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>"}
輸出:
姿勢
從 URL 載入自訂姿勢模型
從互聯網載入姿勢模型
{"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>"}
這用於使用 URL 從互聯網載入姿勢模型。
參數: 字串 (URL)
輸出: 模型預測結果(來自可示教機器姿態模型)
範例代碼:
{"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>"}
輸出:
對圖像上的姿勢進行分類
姿勢模型,對照片上的姿勢進行分類,並獲得排名靠前的姿勢。結果
{"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>"}
這用於載入姿勢模型以對圖像上的姿勢進行分類並獲得適當的結果。
參數:
- AI模型(Teachable Machine Pose Model)
- 圖像
- 數字(預設值:0)
輸出: 模型預測結果(來自Teachable Machine姿態模型)
範例代碼:
{"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>"}
輸出:
對圖像上的姿勢進行分類並獲得所有結果
姿勢模型:對照片上的姿勢進行分類並獲得所有結果
{"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>"}
這用於載入姿勢模型以對圖像上的姿勢進行分類並獲得所有結果。
參數:
- AI模型(Teachable Machine Pose Model)
- 圖像
- 數字(預設值:0)
輸出: 模型預測結果(來自Teachable Machine姿態模型)
範例代碼:
{"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>"}
輸出:
在姿勢模型中顯示類標籤
姿勢模型獲取類標籤
{"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>"}
這用於從姿勢模型中獲取類標籤。
參數: AI模型(Teachable Machine Pose Model)
輸出: 數位語式
範例代碼:
{"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>"}
輸出:
顯示帶有姿勢模型的類總數
姿勢模型獲取類總數
{"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>"}
這用於從姿勢模型中獲取全部的類數。
參數: AI模型(Teachable Machine Pose Model)
輸出: 數位
示例代碼:
{"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>"}
輸出:
繪製所有骨架和關鍵點
poseDetectionResult 自信地繪製關鍵點和骨架 >= 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>"}
此塊用於顯示圖像內部的關鍵點和骨架線。
參數:
- AI模型(Teachable Machine Pose Model)
- 螢幕專案(影像)
輸出: 圖像
範例代碼:
{"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>"}
輸出:
在照片中繪製所有骨骼
poseDetectionResult 以置信度繪製骨架 >= 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>"}
此塊用於顯示圖像內部的骨架線。
參數:
- AI模型(Teachable Machine Pose Model)
- 螢幕專案(影像)
輸出: 圖像
範例代碼:
{"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>"}
輸出:
在照片中繪製所有關鍵點
poseDetectionResult 以置信度繪製關鍵點 >= 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>"}
此塊用於顯示圖像內部的關鍵點。
參數:
- AI模型(Teachable Machine Pose Model)
- 螢幕專案(影像)
輸出: 圖像
範例代碼:
{"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>"}
輸出:
結果
將預測結果轉換為 JsonValue
預測結果以 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>"}
這用於將圖像預測結果轉換為 Json 值。
參數: AI模型(Teachable Machine Pose Model)
輸出: Json 值
範例代碼:
{"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>"}
輸出:
目録