我有数百个标记图像,不想在自定义视觉标记工具中重做这项工作。有没有办法将标记的图像上传到自定义视觉?还是 Azure ML 或 Azure ML Studio?Azure 中的任何视觉服务是否提供上传带注释的图像?谢谢
问问题
71 次
1 回答
0
我使用我开发的名为 PyLabel 的包构建了一个概念验证,用于将注释上传到 Azure 自定义视觉。你可以在这里看到它https://github.com/pylabel-project/samples/blob/main/pylabel2azure_custom_vision.ipynb。
PyLabel 可以将 COCO、YOLO 或 VOC 格式的注释读取到数据帧中。一旦它们在数据框中,您就可以遍历注释的数据框并使用自定义视觉 API 上传图像和注释。
Custom Vision 使用的注释格式类似于 YOLO 格式,因为它们都使用了 0-1 之间的标准化协调。
这是上面提到的笔记本中的代码片段:
#Iterate the rows for each image in the dataframe
for img_filename, img_df in dataset.df.groupby('img_filename'):
img_path = str(PurePath(dataset.path_to_annotations, str(img_df.iloc[0].img_folder), img_filename))
assert exists(img_path), f"File does not exist: {img_path}"
#Create a region object for each bounding box in the dataset
regions = []
for index, row in img_df.iterrows():
#Normalize the boundings box coordinates between 0 and 1
x = Decimal(row.ann_bbox_xmin / row.img_width).min(1)
y = Decimal(row.ann_bbox_ymin / row.img_height).min(1)
w = Decimal(row.ann_bbox_width / row.img_width).min(1-x)
h = Decimal(row.ann_bbox_height / row.img_height).min(1-y)
regions.append(Region(
tag_id=tags[row.cat_name].id,
left=x,
top=y,
width=w,
height=h
)
)
#Create an object with the image and all of the annotations for that image
with open(img_path, mode="rb") as image_contents:
image_and_annotations = [ImageFileCreateEntry(name=img_filename, contents=image_contents.read(), regions=regions)]
#Upload the image and all annnotations for that image
upload_result = trainer.create_images_from_files(
project.id,
ImageFileCreateBatch(images=image_and_annotations)
)
#If upload is not successful, print details about that image for debugging
if not upload_result.is_batch_successful:
print("Image upload failed.")
for image in upload_result.images:
print(img_path)
print("Image status: ", image.status)
print(regions)
#This will take a few minutes
print("Upload complete")
于 2021-11-03T06:18:42.130 回答