我对 azure custom vision 有疑问。我有一个用于对象检测的自定义视觉项目。我使用 python SDK 创建项目(参见:https ://docs.microsoft.com/en-us/azure/cognitive-services/custom-vision-service/python-tutorial-od )。但是我在上传的过程中发现了一些错误。例如,有一张图片在这张图片中有 3 个人。所以我在这张照片中标记了 3 个相同班级的“人”。但上传后,我在自定义视觉网站上发现这张图片中标记了 1 个“人”。但是其他类也可以,比如这张图片也可以有“人”、“车”和“踏板车”。看起来图片上只能有一个相同的班级。
我尝试使用 python SDK(参见:https ://docs.microsoft.com/en-us/azure/cognitive-services/custom-vision-service/python-tutorial-od )上传我的图片和标签信息。
A0_tag = trainer.create_tag(project.id, "A0")
A1_tag = trainer.create_tag(project.id, "A1")
A2_tag = trainer.create_tag(project.id, "A2")
A0_image_regions={
"0001.jpg":[0.432291667,0.28125,0.080729167,0.09765625],
"0001.jpg":[0.34765625,0.385742188,0.131510417,0.135742188],
"0001.jpg":[0.479166667,0.385742188,0.130208333,0.135742188],
"0003.jpg":[0.19921875,0.158203125,0.083333333,0.099609375]
}
上面的代码可以看到我在0001.jpg中上传了三个“A0”类。但是在网站的GUI界面中,我最终只能看到0001.jpg上面存在一个“A0”类。有什么办法可以解决这个问题吗?
基于 cthrash 代码。我对代码进行了一些更改以使其正常工作。这是修改后的代码:
A0_tag = trainer.create_tag(project.id, "TestA")
A1_tag = trainer.create_tag(project.id, "TestB")
A2_tag = trainer.create_tag(project.id, "TestC")
A0_image_regions = {
A0_tag.id : [
("2300.png",[0.787109375,0.079681275,0.068359375,0.876494024]),
("0920.png",[0.2109375,0.065737052,0.059570313,0.892430279]),
("0920.png",[0.291015625,0.061752988,0.05859375,0.894422311]),
]
}
A1_image_regions = {
A1_tag.id : [
("2000.png",[0.067382813,0.073705179,0.030273438,0.878486056]),
("2000.png",[0.126953125,0.075697211,0.030273438,0.878486056]),
("2000.png",[0.184570313,0.079681275,0.030273438,0.878486056]),
("2000.png",[0.232421875,0.079681275,0.030273438,0.878486056]),
],
}
A2_image_regions = {
A2_tag.id : [
("1400.png",[0.649414063,0.065737052,0.104492188,0.894422311]),
("2300.png",[0.602539063,0.061752988,0.106445313,0.892430279]),
("0920.png",[0.634765625,0.067729084,0.124023438,0.88247012]),
("0800.png",[0.579101563,0.06374502,0.04296875,0.888446215]),
],
}
regions_map = {}
for tag_id in A0_image_regions:
for filename,[x,y,w,h] in A0_image_regions[tag_id]:
regions = regions_map.get(filename,[])
regions.append(Region(tag_id=A0_tag.id, left=x, top=y, width=w, height=h))
regions_map[filename] = regions
for tag_id in A1_image_regions:
for filename,[x,y,w,h] in A1_image_regions[tag_id]:
regions = regions_map.get(filename,[])
regions.append(Region(tag_id=A1_tag.id, left=x, top=y, width=w, height=h))
regions_map[filename] = regions
for tag_id in A2_image_regions:
for filename,[x,y,w,h] in A2_image_regions[tag_id]:
regions = regions_map.get(filename,[])
regions.append(Region(tag_id=A2_tag.id, left=x, top=y, width=w, height=h))
regions_map[filename] = regions
tagged_images_with_regions = []
for filename in regions_map:
regions = regions_map[filename]
with open("<your path>" + filename, mode="rb") as image_contents:
tagged_images_with_regions.append(ImageFileCreateEntry(name=filename, contents=image_contents.read(), regions=regions))
upload_result = trainer.create_images_from_files(project.id, images=tagged_images_with_regions)