【问题标题】:Is there a way to upload images with annotations (labeled images) to custom vision?有没有办法将带有注释的图像(标记图像)上传到自定义视觉?
【发布时间】:2021-11-28 11:17:41
【问题描述】:

我有数百个标记图像,不想在自定义视觉标记工具中重做这项工作。有没有办法将标记的图像上传到自定义视觉?还是 Azure ML 或 Azure ML Studio? Azure 中的任何视觉服务是否提供上传带注释的图像?谢谢

【问题讨论】:

    标签: image-loading azureml microsoft-custom-vision image-annotations


    【解决方案1】:

    我使用我开发的名为 PyLabel 的包构建了一个概念验证,用于将注释上传到 Azure 自定义视觉。你可以在这里看到它https://github.com/pylabel-project/samples/blob/main/pylabel2azure_custom_vision.ipynb

    PyLabel 可以将 COCO、YOLO 或 VOC 格式的注释读取到数据框中。一旦它们在数据框中,您就可以遍历注释的数据框并使用自定义视觉 API 上传图像和注释。

    Custom Vision 使用的注解格式类似于 YOLO 格式,因为它们都使用了 0-1 之间的归一化坐标。

    这是上面提到的笔记本中的代码的sn-p:

    #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")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多