> 

 > 

5. 以積木式程式製作Raspberry Pi智慧裝置
Teachable Machine
Teachable Machine

该文件详细介绍了如何使用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>"}

输出:

影像模型,对图像上的物件进行分类,并获取顶部...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>"}

这用于载入图像模型并对图像上的物件进行分类并获取所有结果。

参数:

  • 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 从 Internet 载入姿势模型。

参数: 字符串 (URL)
输出: 模型预测结果(来自Teachable Machine Pose Model)
示例代码:

{"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&amp;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&amp;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 Pose Model)
示例代码:

{"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&amp;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&amp;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 Pose Model)
示例代码:

{"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&amp;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&amp;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>"}

输出:

PoseModel:对照片上的姿势进行分类并获取所有结果 - 输出

在姿势模型中显示类标签

姿势模型获取类标签

{"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&amp;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&amp;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&amp;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&amp;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&amp;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 自信地绘制关键点和骨架 - 输出

在照片中绘制所有骨骼

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&amp;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 自信地绘制骨架 - 输出

在照片中绘制所有关键点

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&amp;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>"}

输出:

PoseDetectionResult 自信地绘制关键点 - 输出

结果

将预测结果转换为 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&amp;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 形式获取结果 - 输出

目录