了解如何設(shè)置Azure Machine Learning JSONL 文件格式,以便在訓(xùn)練和推理期間在計(jì)算機(jī)視覺任務(wù)的自動化 ML 實(shí)驗(yàn)中使用數(shù)據(jù)。
關(guān)注TechLead,分享AI全維度知識。作者擁有10+年互聯(lián)網(wǎng)服務(wù)架構(gòu)、AI產(chǎn)品研發(fā)經(jīng)驗(yàn)、團(tuán)隊(duì)管理經(jīng)驗(yàn),同濟(jì)本復(fù)旦碩,復(fù)旦機(jī)器人智能實(shí)驗(yàn)室成員,阿里云認(rèn)證的資深架構(gòu)師,項(xiàng)目管理專業(yè)人士,上億營收AI產(chǎn)品研發(fā)負(fù)責(zé)人。文章來源地址http://www.zghlxwxcb.cn/news/detail-753827.html
一、用于訓(xùn)練的數(shù)據(jù)架構(gòu)
Azure 機(jī)器學(xué)習(xí)的圖像 AutoML 要求以 JSONL(JSON 行)格式準(zhǔn)備輸入圖像數(shù)據(jù)。 本部分介紹多類圖像分類、多標(biāo)簽圖像分類、對象檢測和實(shí)例分段的輸入數(shù)據(jù)格式或架構(gòu)。 我們還將提供最終訓(xùn)練或驗(yàn)證 JSON 行文件的示例。
圖像分類(二進(jìn)制/多類)
每個 JSON 行中的輸入數(shù)據(jù)格式/架構(gòu):
{
"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_url |
Azure 機(jī)器學(xué)習(xí)數(shù)據(jù)存儲中的圖像位置。 | |
my-subscription-id 需要替換為圖像所在的 Azure 訂閱。 若要詳細(xì)了解 Azure 訂閱,請單擊此處。 類似地,my-resource-group 、my-workspace 、my-datastore 應(yīng)分別替換為資源組名稱、工作區(qū)名稱和數(shù)據(jù)存儲名稱。 |
||
path_to_image 應(yīng)該是圖像在數(shù)據(jù)存儲上的完整路徑。 |
||
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 |
圖像詳細(xì)信息 | |
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 |
圖像的類/標(biāo)簽 | |
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"}
多標(biāo)簽圖像分類
下面是每個 JSON 行中用于圖像分類的輸入數(shù)據(jù)格式/架構(gòu)示例。
{
"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_url |
Azure 機(jī)器學(xué)習(xí)數(shù)據(jù)存儲中的圖像位置。 | |
my-subscription-id 需要替換為圖像所在的 Azure 訂閱。 若要詳細(xì)了解 Azure 訂閱,請單擊此處。 類似地,my-resource-group 、my-workspace 、my-datastore 應(yīng)分別替換為資源組名稱、工作區(qū)名稱和數(shù)據(jù)存儲名稱。 |
||
path_to_image 應(yīng)該是圖像在數(shù)據(jù)存儲上的完整路徑。 |
||
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 |
圖像詳細(xì)信息 | |
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 |
圖像中的類/標(biāo)簽列表 | |
Required, List of Strings |
["cat","dog"] |
多標(biāo)簽圖像分類的 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"]}
對象檢測
下面是用于對象檢測的示例 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 坐標(biāo) -
ymin
= 邊界框左上角的 y 坐標(biāo) -
xmax
= 邊界框右下角的 x 坐標(biāo) -
ymax
= 邊界框右下角的 y 坐標(biāo)
密鑰 | 說明 | 示例 |
---|---|---|
image_url |
Azure 機(jī)器學(xué)習(xí)數(shù)據(jù)存儲中的圖像位置。 | |
my-subscription-id 需要替換為圖像所在的 Azure 訂閱。 若要詳細(xì)了解 Azure 訂閱,請單擊此處。 類似地,my-resource-group 、my-workspace 、my-datastore 應(yīng)分別替換為資源組名稱、工作區(qū)名稱和數(shù)據(jù)存儲名稱。 |
||
path_to_image 應(yīng)該是圖像在數(shù)據(jù)存儲上的完整路徑。 |
||
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 |
圖像詳細(xì)信息 | |
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 (外部鍵) |
邊界框列表,其中每個框都是其左上方和右下方坐標(biāo)的 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 (內(nèi)部鍵) |
邊界框中對象的類/標(biāo)簽 | |
Required, String |
"cat" |
|
topX |
邊界框左上角的 x 坐標(biāo)與圖像寬度的比率 | |
Required, Float in the range [0,1] |
0.260 |
|
topY |
邊界框左上角的 y 坐標(biāo)與圖像高度的比率 | |
Required, Float in the range [0,1] |
0.406 |
|
bottomX |
邊界框右下角的 x 坐標(biāo)與圖像寬度的比率 | |
Required, Float in the range [0,1] |
0.735 |
|
bottomY |
邊界框右下角的 y 坐標(biāo)與圖像高度的比率 | |
Required, Float in the range [0,1] |
0.701 |
|
isCrowd |
指示邊界框是否圍繞對象群。 如果設(shè)置了此特殊標(biāo)志,我們在計(jì)算指標(biāo)時將跳過此特定邊界框。 | |
Optional, Bool |
0 |
用于對象檢測的 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}]}
實(shí)例分段
對于實(shí)例分段,自動化 ML 僅支持多邊形作為輸入和輸出,不支持掩碼。
下面是實(shí)例分段的示例 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_url |
Azure 機(jī)器學(xué)習(xí)數(shù)據(jù)存儲中的圖像位置。 | |
my-subscription-id 需要替換為圖像所在的 Azure 訂閱。 若要詳細(xì)了解 Azure 訂閱,請單擊此處。 類似地,my-resource-group 、my-workspace 、my-datastore 應(yīng)分別替換為資源組名稱、工作區(qū)名稱和數(shù)據(jù)存儲名稱。 |
||
path_to_image 應(yīng)該是圖像在數(shù)據(jù)存儲上的完整路徑。 |
||
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 |
圖像詳細(xì)信息 | |
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 (內(nèi)部鍵) |
掩碼中對象的類/標(biāo)簽 | |
Required, String |
"cat" |
|
isCrowd |
指示掩碼是否圍繞對象群 | |
Optional, Bool |
0 |
|
polygon |
對象的多邊形坐標(biāo) | |
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]] |
實(shí)例分段的 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 ]]}]}
二、用于聯(lián)機(jī)評分的數(shù)據(jù)架構(gòu)
在本部分中,我們將記錄在使用部署的模型時進(jìn)行預(yù)測所需的輸入數(shù)據(jù)格式。
輸入格式
以下 JSON 是使用特定于任務(wù)的模型終結(jié)點(diǎn)對任何任務(wù)生成預(yù)測所需的輸入格式。
{
"input_data": {
"columns": [
"image"
],
"data": [
"image_in_base64_string_format"
]
}
}
此 json 為具有外部鍵 input_data
和內(nèi)部鍵 columns
、data
的字典,如下表所述。 終結(jié)點(diǎn)接受采用上述格式的 json 字符串,并將其轉(zhuǎn)換為評分腳本所需的示例的數(shù)據(jù)幀。 Json 的 request_json["input_data"]["data"]
部分中的每個輸入圖像都是 base64 編碼字符串。
密鑰 | 說明 |
---|---|
input_data |
|
(外部鍵) | 它是 json 請求中的外部鍵。 input_data 是接受輸入圖像示例的字典 |
Required, Dictionary |
|
columns |
|
(內(nèi)部鍵) | 用于創(chuàng)建數(shù)據(jù)幀的列名。 它僅接受一個列名為 image 的列。 |
Required, List |
|
data |
|
(內(nèi)部鍵) | Base64 編碼圖像列表 |
Required, List |
部署 mlflow 模型后,我們可以使用以下代碼段來獲取所有任務(wù)的預(yù)測。
# 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,
)
輸出格式
根據(jù)任務(wù)類型,對模型終結(jié)點(diǎn)進(jìn)行的預(yù)測遵循不同的結(jié)構(gòu)。 本部分將探討多類、多標(biāo)簽圖像分類、對象檢測和實(shí)例分段任務(wù)的輸出數(shù)據(jù)格式。
當(dāng)輸入請求包含一個圖像時,以下架構(gòu)適用。
圖像分類(二進(jìn)制/多類)
圖像分類的終結(jié)點(diǎn)返回?cái)?shù)據(jù)集中的所有標(biāo)簽及其在輸入圖像中的概率分?jǐn)?shù),格式如下: visualizations
和 attributions
與可解釋性相關(guān),并且當(dāng)請求僅用于評分時,輸出中將不會包括這些鍵。 有關(guān)圖像分類的可解釋性輸入和輸出架構(gòu)的詳細(xì)信息,請參閱[圖像分類的可解釋性部分]。
[
{
"probs": [
2.098e-06,
4.783e-08,
0.999,
8.637e-06
],
"labels": [
"can",
"carton",
"milk_bottle",
"water_bottle"
]
}
]
多標(biāo)簽圖像分類
對于多標(biāo)簽圖像分類,模型終結(jié)點(diǎn)返回標(biāo)簽及其概率。 visualizations
和 attributions
與可解釋性相關(guān),并且當(dāng)請求僅用于評分時,輸出中將不會包括這些鍵。 有關(guān)多標(biāo)簽分類的可解釋性輸入和輸出架構(gòu)的詳細(xì)信息,請參閱[圖像分類多標(biāo)簽的可解釋性部分]。
[
{
"probs": [
0.997,
0.960,
0.982,
0.025
],
"labels": [
"can",
"carton",
"milk_bottle",
"water_bottle"
]
}
]
對象檢測
對象檢測模型返回多個框,其中包含縮放后的左上角和右下角坐標(biāo),以及框標(biāo)簽和置信度分?jǐn)?shù)。
[
{
"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
}
]
}
]
實(shí)例分段
在實(shí)例分段中,輸出包含多個框,其中包含縮放后的左上角和右下角坐標(biāo)、標(biāo)簽、置信度和多邊形(非掩碼)。 此處,多邊形值與我們在[架構(gòu)部分]中討論的格式相同。
[
{
"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) 的數(shù)據(jù)格式
本部分闡述了在使用部署的模型時進(jìn)行預(yù)測并為預(yù)測的類生成解釋所需的輸入數(shù)據(jù)格式。 無需單獨(dú)部署即可生成解釋。 在線評分的相同終結(jié)點(diǎn)可用于生成解釋。 我們只需要在輸入架構(gòu)中傳遞一些額外的可解釋性相關(guān)參數(shù)即可獲得解釋和/或?qū)傩苑謹(jǐn)?shù)矩陣(像素級解釋)的可視化效果。
支持的可解釋性方法:
- XRAI (xrai)
- 集成漸變 (integrated_gradients)
- 引導(dǎo)式 GradCAM (guided_gradcam)
- 引導(dǎo)式反向傳播 (guided_backprop)
輸入格式 (XAI)
支持以下輸入格式,以使用特定于任務(wù)的模型終結(jié)點(diǎn)生成對任何分類任務(wù)的預(yù)測和解釋。 部署模型后,我們可以使用以下架構(gòu)來獲取預(yù)測和解釋。
{
"input_data": {
"columns": ["image"],
"data": [json.dumps({"image_base64": "image_in_base64_string_format",
"model_explainability": True,
"xai_parameters": {}
})
]
}
}
除了圖像,輸入架構(gòu)中還需要兩個額外的參數(shù)(model_explainability
和 xai_parameters
)才能生成解釋。
密鑰 | 說明 | 默認(rèn)值 |
---|---|---|
image_base64 |
base64 格式的輸入圖像 | |
Required, String |
- | |
model_explainability |
是生成解釋還是僅生成評分 | |
Optional, Bool |
False |
|
xai_parameters |
如果 model_explainability 為 True,則 xai_parameters 是一個字典,其中包含可解釋性算法相關(guān)參數(shù),并以 xai_algorithm 、visualizations 、attributions 為鍵。 |
|
Optional, Dictionary |
||
如果未傳遞 xai_parameters ,則使用 xrai 可解釋性算法及其默認(rèn)值 |
{"xai_algorithm": "xrai", "visualizations": True, "attributions": False} |
|
xai_algorithm |
要使用的可解釋性算法的名稱。 支持的 XAI 算法為 {xrai , integrated_gradients , guided_gradcam , guided_backprop } |
|
Optional, String |
xrai |
|
visualizations |
是否返回解釋的可視化效果。 | |
Optional, Bool |
True |
|
attributions |
是否返回特征屬性。 | |
Optional, Bool |
False |
|
confidence_score_threshold_multilabel |
置信度分?jǐn)?shù)閾值,用于選擇頂級類以生成多標(biāo)簽分類中的解釋。 | |
Optional, Float |
0.5 |
下表描述了可解釋性支持的架構(gòu)。
類型 | 架構(gòu) |
---|---|
對 base64 格式的單個圖像進(jìn)行推理 | 以 image_base64 為鍵和值的字典是 base64 編碼的圖像, |
model_explainability 鍵具有 True 或 False,xai_parameters 字典具有 XAI 算法特定參數(shù) |
|
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)
根據(jù)任務(wù)類型,對模型終結(jié)點(diǎn)進(jìn)行的預(yù)測遵循不同的架構(gòu)。 本部分介紹多類、多標(biāo)簽圖像分類任務(wù)的輸出數(shù)據(jù)格式。
以下架構(gòu)是針對兩個輸入圖像的情況定義的。
圖像分類(二進(jìn)制/多類)
除包含 visualizations
和 attributions
鍵值(如果這些鍵在請求中設(shè)為 True
)以外,輸出架構(gòu)[與上述架構(gòu)相同]。
如果在輸入請求中將 model_explainability
、visualizations
和 attributions
設(shè)置為 True
,則輸出將具有 visualizations
和 attributions
。 下表解釋了有關(guān)這些參數(shù)的更多詳細(xì)信息。 將針對概率分?jǐn)?shù)最高的類生成可視化效果和屬性。
輸出鍵 | 說明 |
---|---|
visualizations |
base64 字符串格式的單個圖像,類型為 |
Optional, String |
|
attributions |
具有形狀 [3, valid_crop_size, valid_crop_size] 像素級屬性分?jǐn)?shù)的多維數(shù)組 |
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]]]
}
]
多標(biāo)簽圖像分類
與多類分類相比,多標(biāo)簽分類的輸出架構(gòu)的唯一區(qū)別是,每個圖像中可以有多個類,可以為每個類生成解釋。 因此,visualizations
是 base64 圖像字符串的列表,attributions
是基于 confidence_score_threshold_multilabel
(默認(rèn)值為 0.5)的每個選定類的屬性分?jǐn)?shù)列表。
如果在輸入請求中將 model_explainability
、visualizations
和 attributions
設(shè)置為 True
,則輸出將具有 visualizations
和 attributions
。 下表解釋了有關(guān)這些參數(shù)的更多詳細(xì)信息。 針對概率分?jǐn)?shù)大于或等于 confidence_score_threshold_multilabel
的所有類生成可視化和屬性。
輸出鍵 | 說明 |
---|---|
visualizations |
base64 字符串格式的圖像列表,類型為 |
Optional, String |
|
attributions |
多維數(shù)組列表,其中包含每個類的像素級屬性分?jǐn)?shù),每個多維數(shù)組的形狀為 [3, valid_crop_size, valid_crop_size]
|
Optional, List |
警告
在聯(lián)機(jī)終終結(jié)點(diǎn)上生成解釋時,請確保僅根據(jù)置信度分?jǐn)?shù)選擇幾個類,以避免終結(jié)點(diǎn)上出現(xiàn)超時問題,或者將終結(jié)點(diǎn)與 GPU 實(shí)例類型一起使用。 要生成多標(biāo)簽分類中大量類的說明,請參閱批量評分筆記本 (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 不受支持。 因此只返回分?jǐn)?shù)。 有關(guān)評分示例,請參閱[在線評分部分]。文章來源:http://www.zghlxwxcb.cn/news/detail-753827.html
實(shí)例分段
警告
XAI 不受支持。 因此只返回分?jǐn)?shù)。 有關(guān)評分示例,請參閱[在線評分部分]。
關(guān)注TechLead,分享AI全維度知識。作者擁有10+年互聯(lián)網(wǎng)服務(wù)架構(gòu)、AI產(chǎn)品研發(fā)經(jīng)驗(yàn)、團(tuán)隊(duì)管理經(jīng)驗(yàn),同濟(jì)本復(fù)旦碩,復(fù)旦機(jī)器人智能實(shí)驗(yàn)室成員,阿里云認(rèn)證的資深架構(gòu)師,項(xiàng)目管理專業(yè)人士,上億營收AI產(chǎn)品研發(fā)負(fù)責(zé)人。
到了這里,關(guān)于Azure 機(jī)器學(xué)習(xí) - 使用自動化機(jī)器學(xué)習(xí)訓(xùn)練計(jì)算機(jī)視覺模型的數(shù)據(jù)架構(gòu)的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!