Azure 机器学习 - 使用自动化机器学习训练计算机视觉模型的数据架构

目录

    • 一、用于训练的数据架构
      • 图像分类(二进制/多类)
      • 多标签图像分类
      • 对象检测
      • 实例分段
    • 二、用于联机评分的数据架构
      • 输入格式
      • 输出格式
        • 图像分类(二进制/多类)
        • 多标签图像分类
        • 对象检测
        • 实例分段
    • 在线评分和可解释性 (XAI) 的数据格式
      • 支持的可解释性方法:
      • 输入格式 (XAI)
      • 输出格式 (XAI)
        • 图像分类(二进制/多类)
        • 多标签图像分类
        • 对象检测
        • 实例分段

了解如何设置Azure Machine Learning JSONL 文件格式,以便在训练和推理期间在计算机视觉任务的自动化 ML 实验中使用数据。

关注TechLead,分享AI全维度知识。作者拥有10+年互联网服务架构、AI产品研发经验、团队管理经验,同济本复旦硕,复旦机器人智能实验室成员,阿里云认证的资深架构师,项目管理专业人士,上亿营收AI产品研发负责人。

file

一、用于训练的数据架构

Azure 机器学习的图像 AutoML 要求以 JSONL(JSON 行)格式准备输入图像数据。 本部分介绍多类图像分类、多标签图像分类、对象检测和实例分段的输入数据格式或架构。 我们还将提供最终训练或验证 JSON 行文件的示例。

图像分类(二进制/多类)

每个 JSON 行中的输入数据格式/架构:

{
   "image_url":"azureml://subscriptions/<my-subscription-id>/resourcegroups/<my-resource-group>/workspaces/<my-workspace>/datastores/<my-datastore>/paths/<path_to_image>",
   "image_details":{
      "format":"image_format",
      "width":"image_width",
      "height":"image_height"
   },
   "label":"class_name",
}
密钥说明示例
image_urlAzure 机器学习数据存储中的图像位置。
my-subscription-id 需要替换为图像所在的 Azure 订阅。 若要详细了解 Azure 订阅,请单击此处。 类似地,my-resource-groupmy-workspacemy-datastore 应分别替换为资源组名称、工作区名称和数据存储名称。
path_to_image 应该是图像在数据存储上的完整路径。
Required, String"azureml://subscriptions/my-subscription-id/resourcegroups/my-resource-group/workspaces/my-workspace/datastores/my-datastore/paths/image_data/Image_01.jpg"
image_details图像详细信息
Optional, Dictionary"image_details":{"format": "jpg", "width": "400px", "height": "258px"}
format图像类型(支持 Pillow 库中所有可用的图像格式)
Optional, String from {"jpg", "jpeg", "png", "jpe", "jfif","bmp", "tif", "tiff"}"jpg" or "jpeg" or "png" or "jpe" or "jfif" or "bmp" or "tif" or "tiff"
width图像的宽度
Optional, String or Positive Integer"400px" or 400
height图像的高度
Optional, String or Positive Integer"200px" or 200
label图像的类/标签
Required, String"cat"

多类图像分类的 JSONL 文件示例:

{"image_url": "azureml://subscriptions/my-subscription-id/resourcegroups/my-resource-group/workspaces/my-workspace/datastores/my-datastore/paths/image_data/Image_01.jpg", "image_details":{"format": "jpg", "width": "400px", "height": "258px"}, "label": "can"}
{"image_url": "azureml://subscriptions/my-subscription-id/resourcegroups/my-resource-group/workspaces/my-workspace/datastores/my-datastore/paths/image_data/Image_02.jpg", "image_details": {"format": "jpg", "width": "397px", "height": "296px"}, "label": "milk_bottle"}
.
.
.
{"image_url": "azureml://subscriptions/my-subscription-id/resourcegroups/my-resource-group/workspaces/my-workspace/datastores/my-datastore/paths/image_data/Image_n.jpg", "image_details": {"format": "jpg", "width": "1024px", "height": "768px"}, "label": "water_bottle"}

file

多标签图像分类

下面是每个 JSON 行中用于图像分类的输入数据格式/架构示例。

{
   "image_url":"azureml://subscriptions/<my-subscription-id>/resourcegroups/<my-resource-group>/workspaces/<my-workspace>/datastores/<my-datastore>/paths/<path_to_image>",
   "image_details":{
      "format":"image_format",
      "width":"image_width",
      "height":"image_height"
   },
   "label":[
      "class_name_1",
      "class_name_2",
      "class_name_3",
      "...",
      "class_name_n"
        
   ]
}
密钥说明示例
image_urlAzure 机器学习数据存储中的图像位置。
my-subscription-id 需要替换为图像所在的 Azure 订阅。 若要详细了解 Azure 订阅,请单击此处。 类似地,my-resource-groupmy-workspacemy-datastore 应分别替换为资源组名称、工作区名称和数据存储名称。
path_to_image 应该是图像在数据存储上的完整路径。
Required, String"azureml://subscriptions/my-subscription-id/resourcegroups/my-resource-group/workspaces/my-workspace/datastores/my-datastore/paths/image_data/Image_01.jpg"
image_details图像详细信息
Optional, Dictionary"image_details":{"format": "jpg", "width": "400px", "height": "258px"}
format图像类型(支持 Pillow 库中所有可用的图像格式)
Optional, String from {"jpg", "jpeg", "png", "jpe", "jfif", "bmp", "tif", "tiff"}"jpg" or "jpeg" or "png" or "jpe" or "jfif" or "bmp" or "tif" or "tiff"
width图像的宽度
Optional, String or Positive Integer"400px" or 400
height图像的高度
Optional, String or Positive Integer"200px" or 200
label图像中的类/标签列表
Required, List of Strings["cat","dog"]

多标签图像分类的 JSONL 文件示例:

{"image_url": "azureml://subscriptions/my-subscription-id/resourcegroups/my-resource-group/workspaces/my-workspace/datastores/my-datastore/paths/image_data/Image_01.jpg", "image_details":{"format": "jpg", "width": "400px", "height": "258px"}, "label": ["can"]}
{"image_url": "azureml://subscriptions/my-subscription-id/resourcegroups/my-resource-group/workspaces/my-workspace/datastores/my-datastore/paths/image_data/Image_02.jpg", "image_details": {"format": "jpg", "width": "397px", "height": "296px"}, "label": ["can","milk_bottle"]}
.
.
.
{"image_url": "azureml://subscriptions/my-subscription-id/resourcegroups/my-resource-group/workspaces/my-workspace/datastores/my-datastore/paths/image_data/Image_n.jpg", "image_details": {"format": "jpg", "width": "1024px", "height": "768px"}, "label": ["carton","milk_bottle","water_bottle"]}

file

对象检测

下面是用于对象检测的示例 JSONL 文件。

{
   "image_url":"azureml://subscriptions/<my-subscription-id>/resourcegroups/<my-resource-group>/workspaces/<my-workspace>/datastores/<my-datastore>/paths/<path_to_image>",
   "image_details":{
      "format":"image_format",
      "width":"image_width",
      "height":"image_height"
   },
   "label":[
      {
         "label":"class_name_1",
         "topX":"xmin/width",
         "topY":"ymin/height",
         "bottomX":"xmax/width",
         "bottomY":"ymax/height",
         "isCrowd":"isCrowd"
      },
      {
         "label":"class_name_2",
         "topX":"xmin/width",
         "topY":"ymin/height",
         "bottomX":"xmax/width",
         "bottomY":"ymax/height",
         "isCrowd":"isCrowd"
      },
      "..."
   ]
}

其中:

  • xmin = 边界框左上角的 x 坐标
  • ymin = 边界框左上角的 y 坐标
  • xmax = 边界框右下角的 x 坐标
  • ymax = 边界框右下角的 y 坐标
密钥说明示例
image_urlAzure 机器学习数据存储中的图像位置。
my-subscription-id 需要替换为图像所在的 Azure 订阅。 若要详细了解 Azure 订阅,请单击此处。 类似地,my-resource-groupmy-workspacemy-datastore 应分别替换为资源组名称、工作区名称和数据存储名称。
path_to_image 应该是图像在数据存储上的完整路径。
Required, String"azureml://subscriptions/my-subscription-id/resourcegroups/my-resource-group/workspaces/my-workspace/datastores/my-datastore/paths/image_data/Image_01.jpg"
image_details图像详细信息
Optional, Dictionary"image_details":{"format": "jpg", "width": "400px", "height": "258px"}
format图像类型(支持 Pillow 库中提供的所有图像格式。但对于 YOLO,仅支持 opencv 允许的图像格式)
Optional, String from {"jpg", "jpeg", "png", "jpe", "jfif", "bmp", "tif", "tiff"}"jpg" or "jpeg" or "png" or "jpe" or "jfif" or "bmp" or "tif" or "tiff"
width图像的宽度
Optional, String or Positive Integer"499px" or 499
height图像的高度
Optional, String or Positive Integer"665px" or 665
label(外部键)边界框列表,其中每个框都是其左上方和右下方坐标的 label, topX, topY, bottomX, bottomY, isCrowd 字典
Required, List of dictionaries[{"label": "cat", "topX": 0.260, "topY": 0.406, "bottomX": 0.735, "bottomY": 0.701, "isCrowd": 0}]
label(内部键)边界框中对象的类/标签
Required, String"cat"
topX边界框左上角的 x 坐标与图像宽度的比率
Required, Float in the range [0,1]0.260
topY边界框左上角的 y 坐标与图像高度的比率
Required, Float in the range [0,1]0.406
bottomX边界框右下角的 x 坐标与图像宽度的比率
Required, Float in the range [0,1]0.735
bottomY边界框右下角的 y 坐标与图像高度的比率
Required, Float in the range [0,1]0.701
isCrowd指示边界框是否围绕对象群。 如果设置了此特殊标志,我们在计算指标时将跳过此特定边界框。
Optional, Bool0

用于对象检测的 JSONL 文件示例:

{"image_url": "azureml://subscriptions/my-subscription-id/resourcegroups/my-resource-group/workspaces/my-workspace/datastores/my-datastore/paths/image_data/Image_01.jpg", "image_details": {"format": "jpg", "width": "499px", "height": "666px"}, "label": [{"label": "can", "topX": 0.260, "topY": 0.406, "bottomX": 0.735, "bottomY": 0.701, "isCrowd": 0}]}
{"image_url": "azureml://subscriptions/my-subscription-id/resourcegroups/my-resource-group/workspaces/my-workspace/datastores/my-datastore/paths/image_data/Image_02.jpg", "image_details": {"format": "jpg", "width": "499px", "height": "666px"}, "label": [{"label": "carton", "topX": 0.172, "topY": 0.153, "bottomX": 0.432, "bottomY": 0.659, "isCrowd": 0}, {"label": "milk_bottle", "topX": 0.300, "topY": 0.566, "bottomX": 0.891, "bottomY": 0.735, "isCrowd": 0}]}
.
.
.
{"image_url": "azureml://subscriptions/my-subscription-id/resourcegroups/my-resource-group/workspaces/my-workspace/datastores/my-datastore/paths/image_data/Image_n.jpg", "image_details": {"format": "jpg", "width": "499px", "height": "666px"}, "label": [{"label": "carton", "topX": 0.0180, "topY": 0.297, "bottomX": 0.380, "bottomY": 0.836, "isCrowd": 0}, {"label": "milk_bottle", "topX": 0.454, "topY": 0.348, "bottomX": 0.613, "bottomY": 0.683, "isCrowd": 0}, {"label": "water_bottle", "topX": 0.667, "topY": 0.279, "bottomX": 0.841, "bottomY": 0.615, "isCrowd": 0}]}

file

实例分段

对于实例分段,自动化 ML 仅支持多边形作为输入和输出,不支持掩码。

下面是实例分段的示例 JSONL 文件。

{
   "image_url":"azureml://subscriptions/<my-subscription-id>/resourcegroups/<my-resource-group>/workspaces/<my-workspace>/datastores/<my-datastore>/paths/<path_to_image>",
   "image_details":{
      "format":"image_format",
      "width":"image_width",
      "height":"image_height"
   },
   "label":[
      {
         "label":"class_name",
         "isCrowd":"isCrowd",
         "polygon":[["x1", "y1", "x2", "y2", "x3", "y3", "...", "xn", "yn"]]
      }
   ]
}
密钥说明示例
image_urlAzure 机器学习数据存储中的图像位置。
my-subscription-id 需要替换为图像所在的 Azure 订阅。 若要详细了解 Azure 订阅,请单击此处。 类似地,my-resource-groupmy-workspacemy-datastore 应分别替换为资源组名称、工作区名称和数据存储名称。
path_to_image 应该是图像在数据存储上的完整路径。
Required, String"azureml://subscriptions/my-subscription-id/resourcegroups/my-resource-group/workspaces/my-workspace/datastores/my-datastore/paths/image_data/Image_01.jpg"
image_details图像详细信息
Optional, Dictionary"image_details":{"format": "jpg", "width": "400px", "height": "258px"}
format映像类型
Optional, String from {"jpg", "jpeg", "png", "jpe", "jfif", "bmp", "tif", "tiff" }"jpg" or "jpeg" or "png" or "jpe" or "jfif" or "bmp" or "tif" or "tiff"
width图像的宽度
Optional, String or Positive Integer"499px" or 499
height图像的高度
Optional, String or Positive Integer"665px" or 665
label(外部键)掩码列表,其中每个掩码都是 label, isCrowd, polygon coordinates 的字典
Required, List of dictionaries[{"label": "can", "isCrowd": 0, "polygon": [[0.577, 0.689,
0.562, 0.681,
0.559, 0.686]]}]
label(内部键)掩码中对象的类/标签
Required, String"cat"
isCrowd指示掩码是否围绕对象群
Optional, Bool0
polygon对象的多边形坐标
Required, List of list for multiple segments of the same instance. Float values in the range [0,1][[0.577, 0.689, 0.567, 0.689, 0.559, 0.686]]

实例分段的 JSONL 文件示例:

{"image_url": "azureml://subscriptions/my-subscription-id/resourcegroups/my-resource-group/workspaces/my-workspace/datastores/my-datastore/paths/image_data/Image_01.jpg", "image_details": {"format": "jpg", "width": "499px", "height": "666px"}, "label": [{"label": "can", "isCrowd": 0, "polygon": [[0.577, 0.689, 0.567, 0.689, 0.559, 0.686, 0.380, 0.593, 0.304, 0.555, 0.294, 0.545, 0.290, 0.534, 0.274, 0.512, 0.2705, 0.496, 0.270, 0.478, 0.284, 0.453, 0.308, 0.432, 0.326, 0.423, 0.356, 0.415, 0.418, 0.417, 0.635, 0.493, 0.683, 0.507, 0.701, 0.518, 0.709, 0.528, 0.713, 0.545, 0.719, 0.554, 0.719, 0.579, 0.713, 0.597, 0.697, 0.621, 0.695, 0.629, 0.631, 0.678, 0.619, 0.683, 0.595, 0.683, 0.577, 0.689]]}]}
{"image_url": "azureml://subscriptions/my-subscription-id/resourcegroups/my-resource-group/workspaces/my-workspace/datastores/my-datastore/paths/image_data/Image_02.jpg", "image_details": {"format": "jpg", "width": "499px", "height": "666px"}, "label": [{"label": "carton", "isCrowd": 0, "polygon": [[0.240, 0.65, 0.234, 0.654, 0.230, 0.647, 0.210, 0.512, 0.202, 0.403, 0.182, 0.267, 0.184, 0.243, 0.180, 0.166, 0.186, 0.159, 0.198, 0.156, 0.396, 0.162, 0.408, 0.169, 0.406, 0.217, 0.414, 0.249, 0.422, 0.262, 0.422, 0.569, 0.342, 0.569, 0.334, 0.572, 0.320, 0.585, 0.308, 0.624, 0.306, 0.648, 0.240, 0.657]]}, {"label": "milk_bottle",  "isCrowd": 0, "polygon": [[0.675, 0.732, 0.635, 0.731, 0.621, 0.725, 0.573, 0.717, 0.516, 0.717, 0.505, 0.720, 0.462, 0.722, 0.438, 0.719, 0.396, 0.719, 0.358, 0.714, 0.334, 0.714, 0.322, 0.711, 0.312, 0.701, 0.306, 0.687, 0.304, 0.663, 0.308, 0.630, 0.320, 0.596, 0.32, 0.588, 0.326, 0.579]]}]}
.
.
.
{"image_url": "azureml://subscriptions/my-subscription-id/resourcegroups/my-resource-group/workspaces/my-workspace/datastores/my-datastore/paths/image_data/Image_n.jpg", "image_details": {"format": "jpg", "width": "499px", "height": "666px"}, "label": [{"label": "water_bottle", "isCrowd": 0, "polygon": [[0.334, 0.626, 0.304, 0.621, 0.254, 0.603, 0.164, 0.605, 0.158, 0.602, 0.146, 0.602, 0.142, 0.608, 0.094, 0.612, 0.084, 0.599, 0.080, 0.585, 0.080, 0.539, 0.082, 0.536, 0.092, 0.533, 0.126, 0.530, 0.132, 0.533, 0.144, 0.533, 0.162, 0.525, 0.172, 0.525, 0.186, 0.521, 0.196, 0.521 ]]}, {"label": "milk_bottle", "isCrowd": 0, "polygon": [[0.392, 0.773, 0.380, 0.732, 0.379, 0.767, 0.367, 0.755, 0.362, 0.735, 0.362, 0.714, 0.352, 0.644, 0.352, 0.611, 0.362, 0.597, 0.40, 0.593, 0.444,  0.494, 0.588, 0.515, 0.585, 0.621, 0.588, 0.671, 0.582, 0.713, 0.572, 0.753 ]]}]}

file

二、用于联机评分的数据架构

在本部分中,我们将记录在使用部署的模型时进行预测所需的输入数据格式。

输入格式

以下 JSON 是使用特定于任务的模型终结点对任何任务生成预测所需的输入格式。

{
   "input_data": {
      "columns": [
         "image"
      ],
      "data": [
         "image_in_base64_string_format"
      ]
   }
}

此 json 为具有外部键 input_data 和内部键 columnsdata 的字典,如下表所述。 终结点接受采用上述格式的 json 字符串,并将其转换为评分脚本所需的示例的数据帧。 Json 的 request_json["input_data"]["data"] 部分中的每个输入图像都是 base64 编码字符串。

密钥说明
input_data
(外部键)它是 json 请求中的外部键。 input_data 是接受输入图像示例的字典
Required, Dictionary
columns
(内部键)用于创建数据帧的列名。 它仅接受一个列名为 image 的列。
Required, List
data
(内部键)Base64 编码图像列表
Required, List

部署 mlflow 模型后,我们可以使用以下代码段来获取所有任务的预测。

# Create request json
import base64

sample_image = os.path.join(dataset_dir, "images", "1.jpg")


def read_image(image_path):
    with open(image_path, "rb") as f:
        return f.read()


request_json = {
    "input_data": {
        "columns": ["image"],
        "data": [base64.encodebytes(read_image(sample_image)).decode("utf-8")],
    }
}
import json

request_file_name = "sample_request_data.json"

with open(request_file_name, "w") as request_file:
    json.dump(request_json, request_file)
resp = ml_client.online_endpoints.invoke(
    endpoint_name=online_endpoint_name,
    deployment_name=deployment.name,
    request_file=request_file_name,
)

输出格式

根据任务类型,对模型终结点进行的预测遵循不同的结构。 本部分将探讨多类、多标签图像分类、对象检测和实例分段任务的输出数据格式。

当输入请求包含一个图像时,以下架构适用。

图像分类(二进制/多类)

图像分类的终结点返回数据集中的所有标签及其在输入图像中的概率分数,格式如下: visualizationsattributions 与可解释性相关,并且当请求仅用于评分时,输出中将不会包括这些键。 有关图像分类的可解释性输入和输出架构的详细信息,请参阅[图像分类的可解释性部分]。

[
   {
      "probs": [
         2.098e-06,
         4.783e-08,
         0.999,
         8.637e-06
      ],
      "labels": [
         "can",
         "carton",
         "milk_bottle",
         "water_bottle"
      ]
   }
]
多标签图像分类

对于多标签图像分类,模型终结点返回标签及其概率。 visualizationsattributions 与可解释性相关,并且当请求仅用于评分时,输出中将不会包括这些键。 有关多标签分类的可解释性输入和输出架构的详细信息,请参阅[图像分类多标签的可解释性部分]。

[
   {
      "probs": [
         0.997,
         0.960,
         0.982,
         0.025
      ],
      "labels": [
         "can",
         "carton",
         "milk_bottle",
         "water_bottle"
      ]
   }
]
对象检测

对象检测模型返回多个框,其中包含缩放后的左上角和右下角坐标,以及框标签和置信度分数。

[
   {
      "boxes": [
         {
            "box": {
               "topX": 0.224,
               "topY": 0.285,
               "bottomX": 0.399,
               "bottomY": 0.620
            },
            "label": "milk_bottle",
            "score": 0.937
         },
         {
            "box": {
               "topX": 0.664,
               "topY": 0.484,
               "bottomX": 0.959,
               "bottomY": 0.812
            },
            "label": "can",
            "score": 0.891
         },
         {
            "box": {
               "topX": 0.423,
               "topY": 0.253,
               "bottomX": 0.632,
               "bottomY": 0.725
            },
            "label": "water_bottle",
            "score": 0.876
         }
      ]
   }
]
实例分段

在实例分段中,输出包含多个框,其中包含缩放后的左上角和右下角坐标、标签、置信度和多边形(非掩码)。 此处,多边形值与我们在[架构部分]中讨论的格式相同。

[
    {
       "boxes": [
          {
             "box": {
                "topX": 0.679,
                "topY": 0.491,
                "bottomX": 0.926,
                "bottomY": 0.810
             },
             "label": "can",
             "score": 0.992,
             "polygon": [
                [
                   0.82, 0.811, 0.771, 0.810, 0.758, 0.805, 0.741, 0.797, 0.735, 0.791, 0.718, 0.785, 0.715, 0.778, 0.706, 0.775, 0.696, 0.758, 0.695, 0.717, 0.698, 0.567, 0.705, 0.552, 0.706, 0.540, 0.725, 0.520, 0.735, 0.505, 0.745, 0.502, 0.755, 0.493
                ]
             ]
          },
          {
             "box": {
                "topX": 0.220,
                "topY": 0.298,
                "bottomX": 0.397,
                "bottomY": 0.601
             },
             "label": "milk_bottle",
             "score": 0.989,
             "polygon": [
                [
                   0.365, 0.602, 0.273, 0.602, 0.26, 0.595, 0.263, 0.588, 0.251, 0.546, 0.248, 0.501, 0.25, 0.485, 0.246, 0.478, 0.245, 0.463, 0.233, 0.442, 0.231, 0.43, 0.226, 0.423, 0.226, 0.408, 0.234, 0.385, 0.241, 0.371, 0.238, 0.345, 0.234, 0.335, 0.233, 0.325, 0.24, 0.305, 0.586, 0.38, 0.592, 0.375, 0.598, 0.365
                ]
             ]
          },
          {
             "box": {
                "topX": 0.433,
                "topY": 0.280,
                "bottomX": 0.621,
                "bottomY": 0.679
             },
             "label": "water_bottle",
             "score": 0.988,
             "polygon": [
                [
                   0.576, 0.680, 0.501, 0.680, 0.475, 0.675, 0.460, 0.625, 0.445, 0.630, 0.443, 0.572, 0.440, 0.560, 0.435, 0.515, 0.431, 0.501, 0.431, 0.433, 0.433, 0.426, 0.445, 0.417, 0.456, 0.407, 0.465, 0.381, 0.468, 0.327, 0.471, 0.318
                ]
             ]
          }
       ]
    }
]

在线评分和可解释性 (XAI) 的数据格式

本部分阐述了在使用部署的模型时进行预测并为预测的类生成解释所需的输入数据格式。 无需单独部署即可生成解释。 在线评分的相同终结点可用于生成解释。 我们只需要在输入架构中传递一些额外的可解释性相关参数即可获得解释和/或属性分数矩阵(像素级解释)的可视化效果。

支持的可解释性方法:

  • XRAI (xrai)
  • 集成渐变 (integrated_gradients)
  • 引导式 GradCAM (guided_gradcam)
  • 引导式反向传播 (guided_backprop)

输入格式 (XAI)

支持以下输入格式,以使用特定于任务的模型终结点生成对任何分类任务的预测和解释。 部署模型后,我们可以使用以下架构来获取预测和解释。

{
   "input_data": {
      "columns": ["image"],
      "data": [json.dumps({"image_base64": "image_in_base64_string_format", 
                           "model_explainability": True,
                           "xai_parameters": {}
                         })
      ]
   }
}

除了图像,输入架构中还需要两个额外的参数(model_explainabilityxai_parameters)才能生成解释。

密钥说明默认值
image_base64base64 格式的输入图像
Required, String-
model_explainability是生成解释还是仅生成评分
Optional, BoolFalse
xai_parameters如果 model_explainability 为 True,则 xai_parameters 是一个字典,其中包含可解释性算法相关参数,并以 xai_algorithmvisualizationsattributions 为键。
Optional, Dictionary
如果未传递 xai_parameters,则使用 xrai 可解释性算法及其默认值{"xai_algorithm": "xrai", "visualizations": True, "attributions": False}
xai_algorithm要使用的可解释性算法的名称。 支持的 XAI 算法为 {xrai, integrated_gradients, guided_gradcam, guided_backprop}
Optional, Stringxrai
visualizations是否返回解释的可视化效果。
Optional, BoolTrue
attributions是否返回特征属性。
Optional, BoolFalse
confidence_score_threshold_multilabel置信度分数阈值,用于选择顶级类以生成多标签分类中的解释。
Optional, Float0.5

下表描述了可解释性支持的架构。

类型架构
对 base64 格式的单个图像进行推理image_base64 为键和值的字典是 base64 编码的图像,
model_explainability 键具有 True 或 False,xai_parameters 字典具有 XAI 算法特定参数
Required, Json String
Works for one or more images

request_json 中的每个输入图像(在以下代码中定义)都是附加到列表 request_json["input_data"]["data"] 的 base64 编码字符串:

import base64
import json
# Get the details for online endpoint
endpoint = ml_client.online_endpoints.get(name=online_endpoint_name)

sample_image = "./test_image.jpg"

# Define explainability (XAI) parameters
model_explainability = True
xai_parameters = {"xai_algorithm": "xrai",
                  "visualizations": True,
                  "attributions": False}

def read_image(image_path):
    with open(image_path, "rb") as f:
        return f.read()

# Create request json
request_json = {

    "input_data": {
        "columns": ["image"],
        "data": [json.dumps({"image_base64": base64.encodebytes(read_image(sample_image)).decode("utf-8"),
                             "model_explainability": model_explainability,
                             "xai_parameters": xai_parameters})],
    }
}

request_file_name = "sample_request_data.json"

with open(request_file_name, "w") as request_file:
    json.dump(request_json, request_file)

resp = ml_client.online_endpoints.invoke(
    endpoint_name=online_endpoint_name,
    deployment_name=deployment.name,
    request_file=request_file_name,
)
predictions = json.loads(resp)

输出格式 (XAI)

根据任务类型,对模型终结点进行的预测遵循不同的架构。 本部分介绍多类、多标签图像分类任务的输出数据格式。

以下架构是针对两个输入图像的情况定义的。

图像分类(二进制/多类)

除包含 visualizationsattributions 键值(如果这些键在请求中设为 True)以外,输出架构[与上述架构相同]。

如果在输入请求中将 model_explainabilityvisualizationsattributions 设置为 True,则输出将具有 visualizationsattributions。 下表解释了有关这些参数的更多详细信息。 将针对概率分数最高的类生成可视化效果和属性。

输出键说明
visualizationsbase64 字符串格式的单个图像,类型为
Optional, String
attributions具有形状 [3, valid_crop_size, valid_crop_size] 像素级属性分数的多维数组
Optional, List
[
    {
       "probs": [
          0.006,
          9.345e-05,
          0.992,
          0.003
       ],
       "labels": [
          "can",
          "carton",
          "milk_bottle",
          "water_bottle"
       ],
       "visualizations": "iVBORw0KGgoAAAAN.....",
       "attributions": [[[-4.2969e-04, -1.3090e-03,  7.7791e-04,  ...,  2.6677e-04,
                          -5.5195e-03,  1.7989e-03],
                          .
                          .
                          .
                         [-5.8236e-03, -7.9108e-04, -2.6963e-03,  ...,  2.6517e-03,
                           1.2546e-03,  6.6507e-04]]]
    }
]
多标签图像分类

与多类分类相比,多标签分类的输出架构的唯一区别是,每个图像中可以有多个类,可以为每个类生成解释。 因此,visualizations 是 base64 图像字符串的列表,attributions 是基于 confidence_score_threshold_multilabel(默认值为 0.5)的每个选定类的属性分数列表。

如果在输入请求中将 model_explainabilityvisualizationsattributions 设置为 True,则输出将具有 visualizationsattributions。 下表解释了有关这些参数的更多详细信息。 针对概率分数大于或等于 confidence_score_threshold_multilabel 的所有类生成可视化和属性。

输出键说明
visualizationsbase64 字符串格式的图像列表,类型为
Optional, String
attributions多维数组列表,其中包含每个类的像素级属性分数,每个多维数组的形状为 [3, valid_crop_size, valid_crop_size]
Optional, List

警告

在联机终终结点上生成解释时,请确保仅根据置信度分数选择几个类,以避免终结点上出现超时问题,或者将终结点与 GPU 实例类型一起使用。 要生成多标签分类中大量类的说明,请参阅批量评分笔记本 (SDK v1)。

[
    {
       "probs": [
          0.994,
          0.994,
          0.843,
          0.166
       ],
       "labels": [
          "can",
          "carton",
          "milk_bottle",
          "water_bottle"
       ],
       "visualizations": ["iVBORw0KGgoAAAAN.....", "iVBORw0KGgoAAAAN......", .....],
       "attributions": [
                        [[[-4.2969e-04, -1.3090e-03,  7.7791e-04,  ...,  2.6677e-04,
                           -5.5195e-03,  1.7989e-03],
                           .
                           .
                           .
                          [-5.8236e-03, -7.9108e-04, -2.6963e-03,  ...,  2.6517e-03,
                            1.2546e-03,  6.6507e-04]]],
                        .
                        .
                        .
                       ]
    }
]
对象检测

警告

XAI 不受支持。 因此只返回分数。 有关评分示例,请参阅[在线评分部分]。

实例分段

警告

XAI 不受支持。 因此只返回分数。 有关评分示例,请参阅[在线评分部分]。

关注TechLead,分享AI全维度知识。作者拥有10+年互联网服务架构、AI产品研发经验、团队管理经验,同济本复旦硕,复旦机器人智能实验室成员,阿里云认证的资深架构师,项目管理专业人士,上亿营收AI产品研发负责人。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/130210.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

8255 boot介绍及bring up经验分享

这篇文章会简单的介绍8255的启动流程&#xff0c;然后着重介绍8255在实际项目中新硬件上的bring up工作&#xff0c;可以给大家做些参考。 8255 boot介绍 下面这些信息来自文档&#xff1a;《QAM8255P IVI Boot and CoreBSP Architecture Technical Overview》 80-42847-11 R…

ChatGPT、GPT-4 Turbo接口调用(stream模式)

接口地址 https://chat.xutongbao.top/api/light/chat/createChatCompletion 请求方式 post 请求参数 model可选值&#xff1a; “gpt-3.5-turbo-1106”、 “gpt-3.5-turbo-16k” 、 “gpt-4”、“gpt-4-1106-preview”。 默认值为&#xff1a; “gpt-3.5-turbo-1106” to…

2023最新electron 进程间通讯的几种方法

数据传递&#xff08;旧&#xff09; 渲染进程发数据到主进程 // 按钮事件 const handleWebRootPathClick () > {ipcRenderer.send(open_dir) }// main.ts中接收 ipcMain.on(open_dir, () > {console.log(recv ok) }) 主进程发数据到渲染进程 // main.ts中发送数据 …

【数据结构初阶】算法的时间复杂度和空间复杂度

各位读者老爷好&#xff01;现在鼠鼠我呀来浅谈一下数据结构初阶中的一个知识点&#xff1a;算法的时间复杂度和空间复杂度&#xff0c;希望对你有所帮助。 在浅谈时间复杂度和空间复杂度之前&#xff0c;咱们可以来了解一下一下几个概念&#xff1a; 1.什么是数据结构 数据结…

nodejs+vue+python+PHP+微信小程序-安卓-软件项目开发管理系统的设计与实现-计算机毕业设计

目 录 摘 要 I ABSTRACT II 目 录 II 第1章 绪论 1 1.1背景及意义 1 1.2 国内外研究概况 1 1.3 研究的内容 1 第2章 相关技术 3 2.1 nodejs简介 4 2.2 express框架介绍 6 2.4 MySQL数据库 4 第3章 系统分析 5 3.1 需求分析 5 3.2 系统可行性分析 5 3.2.1技术可行性&#xff1a;…

建造者模式 rust和java的实现

文章目录 建造者模式介绍优点缺点使用场景 实现javarust rust代码仓库 建造者模式 建造者模式&#xff08;Builder Pattern&#xff09;使用多个简单的对象一步一步构建成一个复杂的对象。 一个 Builder 类会一步一步构造最终的对象。该 Builder 类是独立于其他对象的。 介绍…

JVM之类加载器

文章目录 版权声明类加载器类加载器的分类启动类加载器拓展类加载器&应用程序类加载器 双亲委派机制解决三个问题 打破双亲委派机制自定义类加载器案例演示线程上下文类加载器案例梳理OSGi模块化 版权声明 本博客的内容基于我个人学习黑马程序员课程的学习笔记整理而成。我…

Angular 由一个bug说起之一:List / Grid的性能问题

在angular中&#xff0c;MatTable构建简单&#xff0c;使用范围广。但某些时候会出现卡顿 卡顿情景&#xff1a; 1&#xff1a;一次性请求太多的数据 2&#xff1a;一次性渲染太多数据&#xff0c;这会花费CPU很多时间 3&#xff1a;行内嵌套复杂的元素 4&#xff1a;使用过多的…

iOS应用加固方案解析:ipa加固安全技术全面评测

​ 在移动应用开发领域&#xff0c;iOS应用的安全性一直备受关注。ipaguard作为一款专业的iOS应用加固方案&#xff0c;采用混淆加密技术&#xff0c;旨在保护应用免受破解、逆向和篡改等风险。本文将深入探讨ipaguard的产品功能、安全技术及其在iOS应用加固领域中的核心优势和…

离线视频ocr识别

sudo apt-get install libleptonica-dev libtesseract-dev sudo apt-get install tesseract-ocr-chi-sim python -m pip install video-ocrwindows安装方法&#xff1a; 下载安装 https://digi.bib.uni-mannheim.de/tesseract/tesseract-ocr-w64-setup-5.3.3.20231005.exe 下…

Python 编码最全梳理

为什么要写这篇文章呢&#xff1f;这里就要提到某一天&#xff0c;工作的时候&#xff0c;突然发现自己在编码方面&#xff0c;一窍不通。实在惭愧 字符编码是计算机技术的基石&#xff0c;对于程序员来说尤其重要&#xff0c;字符编码的知识是必须要懂的 编码入门知识 ASCI…

Spring Boot 集成 ElasticSearch

1 加入依赖 首先创建一个项目&#xff0c;在项目中加入 ES 相关依赖&#xff0c;具体依赖如下所示&#xff1a; <dependency><groupId>org.elasticsearch</groupId><artifactId>elasticsearch</artifactId><version>7.1.0</version&g…

leetcode 62

leetcode 62 题目 解题思路 class Solution { public:int uniquePaths(int m, int n) {vector<vector<int>> f(m, vector<int>(n));for(int i0; i<m; i){f[i][0] 1;}for(int j0; j<n; j){f[0][j] 1;}for(int i1; i<m; i){for(int j1; j<n; j){…

C语言:对于宏的一些概念及技巧

一、前言 宏在C语言中是一段有名称的代码段&#xff0c;在程序编译过程中&#xff0c;会将宏的内容被这段代码进行替换&#xff0c;常常用于定义一些常量、函数、代码块等&#xff0c;由于近年来发现许多公司进行面试时对于宏的面试题尤为多&#xff0c;故本文将对C语言中的宏的…

说说React render方法的原理?在什么时候会被触发?

一、原理 首先&#xff0c;render函数在react中有两种形式&#xff1a; 在类组件中&#xff0c;指的是render方法&#xff1a; class Foo extends React.Component { render() { return <h1> Foo </h1>; } } 在函数组件中&#xff0c;指的是函…

C语言—统计从键盘输入的一行英文句子的字符个数

流程图 代码 #include <stdio.h>int main() {int count0;printf("请输入英文字符&#xff0c;回车确认&#xff1a;");while (getchar()!\n){count count 1;}printf("共输入%d个字符\n", count);system("pause");return 0; }请输入英文字…

一文入门Springboot+actuator+Prometheus+Grafana

环境介绍 技术栈 springbootmybatis-plusmysqloracleactuatorPrometheusGrafana 软件 版本 mysql 8 IDEA IntelliJ IDEA 2022.2.1 JDK 1.8 Spring Boot 2.7.13 mybatis-plus 3.5.3.2 本地主机应用 192.168.1.9:8007 PrometheusGrafana安装在同一台主机 http://…

【有限元方法】Newton-Raphson Method

Newton-Raphson Method Linear vs Nonlinear Analysis: At this point, we can conduct a linear analysis no problem ∫ ∑ i , j 1 3 σ i j ε i j ∗ d v ∫ t n ⋅ u ∗ d s ∫ ρ b ⋅ u ∗ d v ⇒ ∫ e [ B ] T [ C ] [ B ] d x ⏟ k e u e ∫ ∂ e [ N ] T t n …

CSS3 分页、框大小、弹性盒子

一、CSS3分页&#xff1a; 网站有很多个页面&#xff0c;需要使用分页来为每个页面做导航。示例&#xff1a; <style> ul.pagination { display: inline-block; padding: 0; margin: 0; } ul.pagination li {display: inline;} ul.pagination li a { color: black; f…

[工业自动化-9]:西门子S7-15xxx编程 - PLC主站 - 信号量:模拟量

目录 前言&#xff1a; 一、模拟量模块 1.1 概述 1.2 安装 1.3 模拟量链接线 二、模拟量常见问题 2.1 两线制、四线制&#xff08;电流&#xff09; 2.2 模拟量模块的参数 2.3 差分信号与单端信号 三、如何防止电磁干扰 3.1 概述 3.2 工业现场的电磁干扰源来源 3.…
最新文章