> 

 > 

4. 以积木式编程制作网络应用程式
Teachable Machine
Teachable Machine

本文档详细介绍了使用 Teachable Machine 进行图像和姿势分类,包括模型加载、分类、显示结果以及将 JsonValue预测结果转换为 JsonValue。

图像

从 URL 载入自订影像模型

图像模型通过中止控制对视频/摄像机中的对象进行连续分类

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"TeachableMachine_loadImageModel\"><value name=\"baseUrl\"><shadow type=\"text\"><field name=\"TEXT\"/></shadow></value></block></xml>"}

这用于从 URL 载入图像模型。

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

这些模块可以在获取图像模型信息的同时显示 Json 值结果。

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>imageModel</variable><variable>predictionResult</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><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\">predictionResult</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"TeachableMachine_ImageModel_predict\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">imageModel</field></block></value><value name=\"image\"><block type=\"Download_image\"><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=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Download_image\"><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=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"1\" _input_init=\"true\"></mutation><value name=\"text\"><block type=\"Json_JsonValue_stringify\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"false\"></mutation><value name=\"jsonValue\"><block type=\"TeachableMachine_ImagePredictionResult_getResultAsJsonValue\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">predictionResult</field></block></value></block></value></block></value></block></value></block></next></block></next></block></next></block></next></block></next></block></statement></block></xml>"}

输出:

从互联网加载图像模型 - 输出

参考:

使用中止控制从互联网载入图像模型

图像模型通过中止控制对视频/摄像机中的对象进行连续分类

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"TeachableMachine_ImageModel_continuouslyPredict\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">imageModel</field></block></value><value name=\"HANDLER_DRAG_PARAM_result\"><shadow type=\"variables_get_reporter\"><field name=\"VAR\">result</field></shadow></value></block></xml>"}

这用于从 URL 加载和分类图像模型。

参数:

  • AI模型(Teachable Machine图像模型)
  • 相机
  • 工作(中止控制)
  • 模型预测结果(来自Teachable Machine图像模型)

输出: N/A
示例代码:

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Camera_setOnCameraControlChanged\"><value name=\"HANDLER_DRAG_PARAM_selectedCameras\"><shadow type=\"variables_get_reporter\"><field name=\"VAR\">selectedCameras</field></shadow></value><value name=\"HANDLER_DRAG_PARAM_recentlySelectedCameras\"><shadow type=\"variables_get_reporter\"><field name=\"VAR\">recentlySelectedCameras</field></shadow></value><value name=\"HANDLER_DRAG_PARAM_recentlyUnselectedCameras\"><shadow type=\"variables_get_reporter\"><field name=\"VAR\">recentlyUnselectedCameras</field></shadow></value><statement name=\"HANDLER\"><block type=\"pxt_controls_for_of\"><value name=\"VAR\"><shadow type=\"variables_get_reporter\"><field name=\"VAR\">value2</field></shadow></value><value name=\"LIST\"><block type=\"variables_get\"><field name=\"VAR\">recentlySelectedCameras</field></block></value><statement name=\"DO\"><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">value2</field></block></value><next><block type=\"variables_set\"><field name=\"VAR\">resultTextBlock</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"false\"></mutation></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">resultTextBlock</field></block></value><next><block type=\"TeachableMachine_ImageModel_continuouslyPredict\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">imageModel</field></block></value><value name=\"video\"><block type=\"variables_get\"><field name=\"VAR\">value2</field></block></value><value name=\"abortControl\"><block type=\"variables_get\"><field name=\"VAR\">detectionAbortControl</field></block></value><value name=\"HANDLER_DRAG_PARAM_result\"><shadow type=\"variables_get_reporter\"><field name=\"VAR\">result</field></shadow></value><statement name=\"HANDLER\"><block type=\"Control_TextBlock_setContent\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">resultTextBlock</field></block></value><value name=\"content\"><block type=\"Json_JsonValue_stringify\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"false\"></mutation><value name=\"jsonValue\"><block type=\"TeachableMachine_ImagePredictionResult_getResultAsJsonValue\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">result</field></block></value></block></value></block></value><next><block type=\"Task_sleep\"><value name=\"ms\"><shadow type=\"math_number\"><field name=\"NUM\">1000</field></shadow></value></block></next></block></statement></block></next></block></next></block></next></block></statement></block></statement></block></xml>"}
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>imageModel</variable><variable>cameraControl</variable><variable>selectedCameras</variable><variable>recentlySelectedCameras</variable><variable>recentlyUnselectedCameras</variable><variable>value2</variable><variable>resultTextBlock</variable><variable>detectionAbortControl</variable><variable>result</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><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=\"Camera_enableCameraFeature\"><value name=\"enable\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></shadow></value><next><block type=\"variables_set\"><field name=\"VAR\">cameraControl</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Camera_getCameraControl\"/></value><next><block type=\"Control_OptionList_setMultiple\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">cameraControl</field></block></value><value name=\"isMultiple\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></shadow></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">cameraControl</field></block></value><next><block type=\"Camera_setOnCameraControlChanged\"><value name=\"HANDLER_DRAG_PARAM_selectedCameras\"><shadow type=\"variables_get_reporter\"><field name=\"VAR\">selectedCameras</field></shadow></value><value name=\"HANDLER_DRAG_PARAM_recentlySelectedCameras\"><shadow type=\"variables_get_reporter\"><field name=\"VAR\">recentlySelectedCameras</field></shadow></value><value name=\"HANDLER_DRAG_PARAM_recentlyUnselectedCameras\"><shadow type=\"variables_get_reporter\"><field name=\"VAR\">recentlyUnselectedCameras</field></shadow></value><statement name=\"HANDLER\"><block type=\"pxt_controls_for_of\"><value name=\"VAR\"><shadow type=\"variables_get_reporter\"><field name=\"VAR\">value2</field></shadow></value><value name=\"LIST\"><block type=\"variables_get\"><field name=\"VAR\">recentlySelectedCameras</field></block></value><statement name=\"DO\"><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">value2</field></block></value><next><block type=\"variables_set\"><field name=\"VAR\">resultTextBlock</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"false\"></mutation></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">resultTextBlock</field></block></value><next><block type=\"TeachableMachine_ImageModel_continuouslyPredict\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">imageModel</field></block></value><value name=\"video\"><block type=\"variables_get\"><field name=\"VAR\">value2</field></block></value><value name=\"abortControl\"><block type=\"variables_get\"><field name=\"VAR\">detectionAbortControl</field></block></value><value name=\"HANDLER_DRAG_PARAM_result\"><shadow type=\"variables_get_reporter\"><field name=\"VAR\">result</field></shadow></value><statement name=\"HANDLER\"><block type=\"Control_TextBlock_setContent\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">resultTextBlock</field></block></value><value name=\"content\"><block type=\"Json_JsonValue_stringify\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"false\"></mutation><value name=\"jsonValue\"><block type=\"TeachableMachine_ImagePredictionResult_getResultAsJsonValue\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">result</field></block></value></block></value></block></value><next><block type=\"Task_sleep\"><value name=\"ms\"><shadow type=\"math_number\"><field name=\"NUM\">1000</field></shadow></value></block></next></block></statement></block></next></block></next></block></next></block></statement></block></statement><next><block type=\"variables_set\"><field name=\"VAR\">detectionAbortControl</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Task_createAbortControl\"/></value></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></statement></block></xml>"}

输出:

图像模型在视频或摄像机中连续分类对象,并中止控制结果 - 输出

参考:

对图像上的物件进行分类

图像模型对图像上的对象进行分类

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"TeachableMachine_ImageModel_predict\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">imageModel</field></block></value></block></xml>"}

这用于加载图像模型并在图像上(而不是相机上)对对象进行分类。

参数:

  • AI模型(Teachable Machine图像模型)
  • 图像

输出: 模型预测结果(来自可示教机器图像模型)
范例代码:

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>imageModel</variable><variable>classify</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><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\">classify</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"TeachableMachine_ImageModel_predict\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">imageModel</field></block></value><value name=\"image\"><block type=\"Download_image\"><value name=\"url\"><shadow type=\"text\"><field name=\"TEXT\">https://upload.wikimedia.org/wikipedia/commons/d/d1/One_finger.jpg</field></shadow></value></block></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Download_image\"><value name=\"url\"><shadow type=\"text\"><field name=\"TEXT\">https://upload.wikimedia.org/wikipedia/commons/d/d1/One_finger.jpg</field></shadow></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"1\" _input_init=\"true\"></mutation><value name=\"text\"><block type=\"Json_JsonValue_stringify\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"false\"></mutation><value name=\"jsonValue\"><block type=\"TeachableMachine_ImagePredictionResult_getResultAsJsonValue\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">classify</field></block></value></block></value></block></value></block></value></block></next></block></next></block></next></block></next></block></next></block></statement></block></xml>"}

输出:

图像模型对图像上的对象进行分类 - 第一个输出
图像模型对图像上的对象进行分类 - 第二输出

参考:

在图像模型中显示类标签

图像模型获取类标签

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"TeachableMachine_ImageModel_getClassLabels\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">imageModel</field></block></value></block></xml>"}

这用于从图像模型中获取类标签。

参数: AI模型(Teachable Machine图像模型)
输出: 数组
示例代码:

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>imageModel</variable><variable>classify</variable><variable>label</variable><variable>index</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><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\">classify</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"TeachableMachine_ImageModel_predict\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">imageModel</field></block></value><value name=\"image\"><block type=\"Download_image\"><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=\"variables_set\"><field name=\"VAR\">label</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"TeachableMachine_ImageModel_getClassLabels\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">imageModel</field></block></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Download_image\"><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=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"1\" _input_init=\"true\"></mutation><value name=\"text\"><block type=\"Json_JsonValue_stringify\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"false\"></mutation><value name=\"jsonValue\"><block type=\"TeachableMachine_ImagePredictionResult_getResultAsJsonValue\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">classify</field></block></value></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=\"lists_length\"><value name=\"VALUE\"><block type=\"variables_get\"><field name=\"VAR\">label</field></block></value></block></value><statement name=\"DO\"><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"1\" _input_init=\"true\"></mutation><value name=\"text\"><block type=\"lists_index_get\"><value name=\"LIST\"><block type=\"variables_get\"><field name=\"VAR\">label</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></value></block></statement></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></statement></block></xml>"}

输出:

图像模型获取类标签 - 输出

参考:

显示具有图像模型的类总数

图像模型获取类总数

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"TeachableMachine_ImageModel_getTotalClasses\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">imageModel</field></block></value></block></xml>"}

这用于获取类的全部数量。

参数: AI模型(可示教机器图像模型)
输出:
示例代码:

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>imageModel</variable><variable>classify</variable><variable>total</variable><variable>dateTimeOffset</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><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\">classify</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"TeachableMachine_ImageModel_predict\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">imageModel</field></block></value><value name=\"image\"><block type=\"Download_image\"><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=\"variables_set\"><field name=\"VAR\">total</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"TeachableMachine_ImageModel_getTotalClasses\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">imageModel</field></block></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Download_image\"><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=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"1\" _input_init=\"true\"></mutation><value name=\"text\"><block type=\"Json_JsonValue_stringify\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"false\"></mutation><value name=\"jsonValue\"><block type=\"TeachableMachine_ImagePredictionResult_getResultAsJsonValue\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">classify</field></block></value></block></value></block></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"1\" _input_init=\"true\"></mutation><value name=\"text\"><block type=\"DateTime_DateTimeOffset_toString\"><value name=\"dateTimeOffset\"><block type=\"variables_get\"><field name=\"VAR\">total</field></block></value></block></value></block></value></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></statement></block></xml>"}

输出:

图像模型获取类总数 - 输出

参考:

姿势

从 URL 加载自定义姿势模型

从互联网载入姿势模型

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"TeachableMachine_loadPoseModel\"><value name=\"baseUrl\"><shadow type=\"text\"><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>mainLayout</variable><variable>mainScreen</variable><variable>imageModel</variable><variable>classify</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><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\">classify</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"TeachableMachine_ImageModel_predict\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">imageModel</field></block></value><value name=\"image\"><block type=\"Download_image\"><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=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Download_image\"><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=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"1\" _input_init=\"true\"></mutation><value name=\"text\"><block type=\"Json_JsonValue_stringify\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"false\"></mutation><value name=\"jsonValue\"><block type=\"TeachableMachine_ImagePredictionResult_getResultAsJsonValue\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">classify</field></block></value></block></value></block></value></block></value></block></next></block></next></block></next></block></next></block></next></block></statement></block></xml>"}

输出:

从互联网加载姿势模型 - 输出

参考:

使用中止控制从 Internet 加载姿势模型

姿势模型:在视频/摄像头中连续对姿势进行分类,并中止控制结果

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"TeachableMachine_PoseModel_continuouslyPredict\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">poseModel</field></block></value><value name=\"HANDLER_DRAG_PARAM_result\"><shadow type=\"variables_get_reporter\"><field name=\"VAR\">result</field></shadow></value></block></xml>"}

这用于从 URL 加载和分类姿势模型。

参数:

  • AI模型(Teachable Machine Pose Model)
  • 相机
  • 工作(中止控制)
  • 模型预测结果(来自Teachable Machine Pose Model)

输出: N/A
示例代码:

使用这些块可以获取姿势模型和相机以加载结果。 此外,它还可以创建用于检测的中止控件。 输出应该不断变化。

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Camera_setOnCameraControlChanged\"><value name=\"HANDLER_DRAG_PARAM_selectedCameras\"><shadow type=\"variables_get_reporter\"><field name=\"VAR\">selectedCameras</field></shadow></value><value name=\"HANDLER_DRAG_PARAM_recentlySelectedCameras\"><shadow type=\"variables_get_reporter\"><field name=\"VAR\">recentlySelectedCameras</field></shadow></value><value name=\"HANDLER_DRAG_PARAM_recentlyUnselectedCameras\"><shadow type=\"variables_get_reporter\"><field name=\"VAR\">recentlyUnselectedCameras</field></shadow></value><statement name=\"HANDLER\"><block type=\"pxt_controls_for_of\"><value name=\"VAR\"><shadow type=\"variables_get_reporter\"><field name=\"VAR\">value</field></shadow></value><value name=\"LIST\"><block type=\"variables_get\"><field name=\"VAR\">recentlySelectedCameras</field></block></value><statement name=\"DO\"><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">value</field></block></value><next><block type=\"variables_set\"><field name=\"VAR\">resultTextBlock</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"false\"></mutation></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">resultTextBlock</field></block></value><next><block type=\"TeachableMachine_PoseModel_continuouslyPredict\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">poseModel</field></block></value><value name=\"video\"><block type=\"variables_get\"><field name=\"VAR\">value</field></block></value><value name=\"abortControl\"><block type=\"variables_get\"><field name=\"VAR\">detectionAbortControl</field></block></value><value name=\"HANDLER_DRAG_PARAM_result\"><shadow type=\"variables_get_reporter\"><field name=\"VAR\">result</field></shadow></value><statement name=\"HANDLER\"><block type=\"Control_TextBlock_setContent\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">resultTextBlock</field></block></value><value name=\"content\"><block type=\"Json_JsonValue_stringify\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"false\"></mutation><value name=\"jsonValue\"><block type=\"TeachableMachine_ImagePredictionResult_getResultAsJsonValue\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">result</field></block></value></block></value></block></value><next><block type=\"Task_sleep\"><value name=\"ms\"><shadow type=\"math_number\"><field name=\"NUM\">1000</field></shadow></value></block></next></block></statement></block></next></block></next></block></next></block></statement></block></statement></block></xml>"}
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>poseModel</variable><variable>cameraControl</variable><variable>selectedCameras</variable><variable>recentlySelectedCameras</variable><variable>recentlyUnselectedCameras</variable><variable>value</variable><variable>resultTextBlock</variable><variable>detectionAbortControl</variable><variable>result</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><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=\"Camera_enableCameraFeature\"><value name=\"enable\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></shadow></value><next><block type=\"variables_set\"><field name=\"VAR\">cameraControl</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Camera_getCameraControl\"/></value><next><block type=\"Control_OptionList_setMultiple\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">cameraControl</field></block></value><value name=\"isMultiple\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></shadow></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">cameraControl</field></block></value><next><block type=\"Camera_setOnCameraControlChanged\"><value name=\"HANDLER_DRAG_PARAM_selectedCameras\"><shadow type=\"variables_get_reporter\"><field name=\"VAR\">selectedCameras</field></shadow></value><value name=\"HANDLER_DRAG_PARAM_recentlySelectedCameras\"><shadow type=\"variables_get_reporter\"><field name=\"VAR\">recentlySelectedCameras</field></shadow></value><value name=\"HANDLER_DRAG_PARAM_recentlyUnselectedCameras\"><shadow type=\"variables_get_reporter\"><field name=\"VAR\">recentlyUnselectedCameras</field></shadow></value><statement name=\"HANDLER\"><block type=\"pxt_controls_for_of\"><value name=\"VAR\"><shadow type=\"variables_get_reporter\"><field name=\"VAR\">value</field></shadow></value><value name=\"LIST\"><block type=\"variables_get\"><field name=\"VAR\">recentlySelectedCameras</field></block></value><statement name=\"DO\"><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">value</field></block></value><next><block type=\"variables_set\"><field name=\"VAR\">resultTextBlock</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"false\"></mutation></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">resultTextBlock</field></block></value><next><block type=\"TeachableMachine_PoseModel_continuouslyPredict\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">poseModel</field></block></value><value name=\"video\"><block type=\"variables_get\"><field name=\"VAR\">value</field></block></value><value name=\"abortControl\"><block type=\"variables_get\"><field name=\"VAR\">detectionAbortControl</field></block></value><value name=\"HANDLER_DRAG_PARAM_result\"><shadow type=\"variables_get_reporter\"><field name=\"VAR\">result</field></shadow></value><statement name=\"HANDLER\"><block type=\"Control_TextBlock_setContent\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">resultTextBlock</field></block></value><value name=\"content\"><block type=\"Json_JsonValue_stringify\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"false\"></mutation><value name=\"jsonValue\"><block type=\"TeachableMachine_ImagePredictionResult_getResultAsJsonValue\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">result</field></block></value></block></value></block></value><next><block type=\"Task_sleep\"><value name=\"ms\"><shadow type=\"math_number\"><field name=\"NUM\">1000</field></shadow></value></block></next></block></statement></block></next></block></next></block></next></block></statement></block></statement><next><block type=\"variables_set\"><field name=\"VAR\">detectionAbortControl</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Task_createAbortControl\"/></value></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></statement></block></xml>"}

输出:

姿势模型:在视频或摄像机中连续分类姿势,并中止控制结果 - 输出

参考:

对图像上的姿势进行分类

姿势模型:对图像上的姿势进行分类

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"TeachableMachine_PoseModel_predict\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">poseModel</field></block></value></block></xml>"}

这用于加载姿势模型以对图像上的姿势进行分类,而不是相机上的姿势。

参数:

  • AI模型(Teachable Machine Pose Model)
  • 图像

输出: 模型预测结果(来自Teachable Machine Pose Model)
示例代码:

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>poseModel</variable><variable>predictionResult</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><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\">predictionResult</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"TeachableMachine_PoseModel_predict\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">poseModel</field></block></value><value name=\"image\"><block type=\"Download_image\"><value name=\"url\"><shadow type=\"text\"><field name=\"TEXT\">https://thumbs.dreamstime.com/b/inviting-business-man-sitting-chair-relaxed-attitude-31717628.jpg</field></shadow></value></block></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Download_image\"><value name=\"url\"><shadow type=\"text\"><field name=\"TEXT\">https://thumbs.dreamstime.com/b/inviting-business-man-sitting-chair-relaxed-attitude-31717628.jpg</field></shadow></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"1\" _input_init=\"true\"></mutation><value name=\"text\"><block type=\"Json_JsonValue_stringify\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"false\"></mutation><value name=\"jsonValue\"><block type=\"TeachableMachine_ImagePredictionResult_getResultAsJsonValue\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">predictionResult</field></block></value></block></value></block></value></block></value></block></next></block></next></block></next></block></next></block></next></block></statement></block></xml>"}

输出:

姿势模型:对图像上的姿势进行分类 - 第一个输出
姿势模型:对图像上的姿势进行分类 - 第二输出

参考:

在姿势模型中显示类标签

姿势模型获取类标签

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"TeachableMachine_PoseModel_getClassLabels\"><value name=\"this\"><block type=\"variables_get\"><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>mainLayout</variable><variable>mainScreen</variable><variable>poseModel</variable><variable>predictionResult</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\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><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\">predictionResult</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"TeachableMachine_PoseModel_predict\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">poseModel</field></block></value><value name=\"image\"><block type=\"Download_image\"><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=\"this\"><block type=\"variables_get\"><field name=\"VAR\">poseModel</field></block></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Download_image\"><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=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"1\" _input_init=\"true\"></mutation><value name=\"text\"><block type=\"Json_JsonValue_stringify\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"false\"></mutation><value name=\"jsonValue\"><block type=\"TeachableMachine_ImagePredictionResult_getResultAsJsonValue\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">predictionResult</field></block></value></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=\"lists_length\"><value name=\"VALUE\"><block type=\"variables_get\"><field name=\"VAR\">labels</field></block></value></block></value><statement name=\"DO\"><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"1\" _input_init=\"true\"></mutation><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></value></block></statement></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></statement></block></xml>"}

输出:

姿势模型获取类标签 - 输出

参考:

显示带有姿势模型的类总数

姿势模型获取类总数

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"TeachableMachine_PoseModel_getTotalClasses\"><value name=\"this\"><block type=\"variables_get\"><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>mainLayout</variable><variable>mainScreen</variable><variable>poseModel</variable><variable>classify</variable><variable>total</variable><variable>dateTimeOffset</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><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\">classify</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"TeachableMachine_PoseModel_predict\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">poseModel</field></block></value><value name=\"image\"><block type=\"Download_image\"><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\">total</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"TeachableMachine_PoseModel_getTotalClasses\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">poseModel</field></block></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Download_image\"><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=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"1\" _input_init=\"true\"></mutation><value name=\"text\"><block type=\"Json_JsonValue_stringify\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"false\"></mutation><value name=\"jsonValue\"><block type=\"TeachableMachine_ImagePredictionResult_getResultAsJsonValue\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">classify</field></block></value></block></value></block></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"1\" _input_init=\"true\"></mutation><value name=\"text\"><block type=\"DateTime_DateTimeOffset_toString\"><value name=\"dateTimeOffset\"><block type=\"variables_get\"><field name=\"VAR\">total</field></block></value></block></value></block></value></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></statement></block></xml>"}

输出:

姿势模型获取类总数 - 输出

参考:

结果

按照概率的顺序来预测结果

预测结果按概率排序

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"TeachableMachine_ImagePredictionResult_orderByProbability\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"false\"></mutation><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">predictionResult</field></block></value></block></xml>"}

这用于按概率对预测结果进行排序。

参数:

  • AI模型(Teachable Machine Pose Model)
  • 条件:升序(默认)/降序

输出: N/A
示例代码:

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>poseModel</variable><variable>predictionResult</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><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\">predictionResult</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"TeachableMachine_PoseModel_predict\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">poseModel</field></block></value><value name=\"image\"><block type=\"Download_image\"><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=\"TeachableMachine_ImagePredictionResult_orderByProbability\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"1\" _input_init=\"true\"></mutation><field name=\"order\">SortingOrder.Ascending</field><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">predictionResult</field></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Download_image\"><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=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"1\" _input_init=\"true\"></mutation><value name=\"text\"><block type=\"Json_JsonValue_stringify\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"false\"></mutation><value name=\"jsonValue\"><block type=\"TeachableMachine_ImagePredictionResult_getResultAsJsonValue\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">predictionResult</field></block></value></block></value></block></value></block></value></block></next></block></next></block></next></block></next></block></next></block></next></block></statement></block></xml>"}

当它按升序排列时,输出:

预测结果按概率排序 - 升序输出

当它按降序排列时,输出:

预测结果按概率排序 - 降序输出

参考:

显示预测结果项目

预测结果 获取结果项

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"TeachableMachine_ImagePredictionResult_getResultItems\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">predictionResult</field></block></value></block></xml>"}

它用于获取使用概率或类标签获取结果的结果项。

参数: AI模型(Teachable Machine Prediction Result)
输出: 数位语式
示例代码:

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>imageModel</variable><variable>downloadImage</variable><variable>predictionResult</variable><variable>resultItems</variable><variable>probability</variable><variable>dateTimeOffset</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><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\">downloadImage</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Download_image\"><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\">predictionResult</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"TeachableMachine_ImageModel_predict\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">imageModel</field></block></value><value name=\"image\"><block type=\"variables_get\"><field name=\"VAR\">downloadImage</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">resultItems</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"lists_index_get\"><value name=\"LIST\"><block type=\"TeachableMachine_ImagePredictionResult_getResultItems\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">predictionResult</field></block></value></block></value><value name=\"INDEX\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">probability</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"TeachableMachine_PredictionResultItem_getProbability\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">resultItems</field></block></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">downloadImage</field></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"1\" _input_init=\"true\"></mutation><value name=\"text\"><block type=\"DateTime_DateTimeOffset_toString\"><value name=\"dateTimeOffset\"><block type=\"variables_get\"><field name=\"VAR\">probability</field></block></value></block></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"1\" _input_init=\"true\"></mutation><value name=\"text\"><block type=\"TeachableMachine_PredictionResultItem_getClassLabel\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">resultItems</field></block></value></block></value></block></value></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></statement></block></xml>"}

输出:

预测结果 获取结果项 - 输出

参考:

将预测结果转换为 JsonValue

预测结果以 JsonValue 的形式获取结果

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"TeachableMachine_ImagePredictionResult_getResultAsJsonValue\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">predictionResult</field></block></value></block></xml>"}

这用于将图像预测结果转换为 Json 值。

参数: 模型预测结果(Teachable Machine姿态模型)
输出: Json Value
示例代码:

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>poseModel</variable><variable>classify</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><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\">classify</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"TeachableMachine_PoseModel_predict\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">poseModel</field></block></value><value name=\"image\"><block type=\"Download_image\"><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=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Download_image\"><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=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"1\" _input_init=\"true\"></mutation><value name=\"text\"><block type=\"Json_JsonValue_stringify\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"false\"></mutation><value name=\"jsonValue\"><block type=\"TeachableMachine_ImagePredictionResult_getResultAsJsonValue\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">classify</field></block></value></block></value></block></value></block></value></block></next></block></next></block></next></block></next></block></next></block></statement></block></xml>"}

输出:

预测结果以 JsonValue 的形式获取结果 - 输出

参考:

结果项目

使用结果项显示概率

结果 项获取概率

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"TeachableMachine_PredictionResultItem_getProbability\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">resultItem</field></block></value></block></xml>"}

这用于从结果项中获取概率。

参数: 模型预测结果(Teachable Machine姿态模型)
输出: Json Value
示例代码:

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>imageModel</variable><variable>downloadImage</variable><variable>predictionResult</variable><variable>resultItems</variable><variable>probability</variable><variable>dateTimeOffset</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><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_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\">downloadImage</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Download_image\"><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=\"variables_set\"><field name=\"VAR\">predictionResult</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"TeachableMachine_PoseModel_predict\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">imageModel</field></block></value><value name=\"image\"><block type=\"variables_get\"><field name=\"VAR\">downloadImage</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">resultItems</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"lists_index_get\"><value name=\"LIST\"><block type=\"TeachableMachine_ImagePredictionResult_getResultItems\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">predictionResult</field></block></value></block></value><value name=\"INDEX\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">probability</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"TeachableMachine_PredictionResultItem_getProbability\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">resultItems</field></block></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">downloadImage</field></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"1\" _input_init=\"true\"></mutation><value name=\"text\"><block type=\"DateTime_DateTimeOffset_toString\"><value name=\"dateTimeOffset\"><block type=\"variables_get\"><field name=\"VAR\">probability</field></block></value></block></value></block></value></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></statement></block></xml>"}

输出:

结果 项获取概率 - 输出

参考:

使用结果项显示类标签

结果项获取类标签

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"TeachableMachine_PredictionResultItem_getClassLabel\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">resultItem</field></block></value></block></xml>"}

这用于从结果项中获取类标签。

参数: AI模型(Teachable Machine结果项目)
输出: 字串
示例代码:

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>imageModel</variable><variable>downloadImage</variable><variable>predictionResult</variable><variable>resultItems</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><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_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\">downloadImage</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Download_image\"><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=\"variables_set\"><field name=\"VAR\">predictionResult</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"TeachableMachine_PoseModel_predict\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">imageModel</field></block></value><value name=\"image\"><block type=\"variables_get\"><field name=\"VAR\">downloadImage</field></block></value></block></value><next><block type=\"TeachableMachine_ImagePredictionResult_orderByProbability\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"1\" _input_init=\"true\"></mutation><field name=\"order\">SortingOrder.Descending</field><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">predictionResult</field></block></value><next><block type=\"variables_set\"><field name=\"VAR\">resultItems</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"lists_index_get\"><value name=\"LIST\"><block type=\"TeachableMachine_ImagePredictionResult_getResultItems\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">predictionResult</field></block></value></block></value><value name=\"INDEX\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">downloadImage</field></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"1\" _input_init=\"true\"></mutation><value name=\"text\"><block type=\"TeachableMachine_PredictionResultItem_getClassLabel\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">resultItems</field></block></value></block></value></block></value></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></statement></block></xml>"}

输出:

结果项获取类标签 - 输出

参考:

目录