CustomVision upload own labelled images

mrcday 6 Reputation points
2020-12-16T11:51:55.03+00:00

Hi,

On the Custom Vision homepage it says you can bring your "own labelled images" however there doesn't appear to be a way to upload the annotations?

There also does not appear to be any instructions anywhere on how to do this.

How is this done?

Thanks Chris

Azure AI Custom Vision
Azure AI Custom Vision
An Azure artificial intelligence service and end-to-end platform for applying computer vision to specific domains.
222 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. mrcday 6 Reputation points
    2020-12-16T17:26:33.677+00:00

    Thanks for the answer.

    I already have over 10,000 images and 25,000 tags so CustomVision may not be the right system for me sadly.

    Real shame there isn't a simple way to import tagged images and annotation files because the rest of the system looks good

    If there are any other methods please advise

    thanks

    1 person found this answer helpful.
    0 comments No comments

  2. GiftA-MSFT 11,151 Reputation points
    2020-12-16T14:50:34.387+00:00

    Thanks for reaching out. The portal doesn’t allow uploading tagged images, you have to use our APIs/SDKs. Also, there's a limit on number of images you can upload at a time ( 64 images and 20 tags). You can upload tagged images using the following APIs (CreateImagesFromFiles or CreateImagesFromData or CreateImagesFromUrls). Here's an example using SDK. Hope this helps.

    0 comments No comments

  3. alexheat 6 Reputation points Microsoft Employee
    2021-12-26T23:01:58.807+00:00

    @mrcday , I have built a Python package called PyLabel that can be used to import pre-labelled images to Azure Custom Vision. You can see a proof of concept in this notebook https://github.com/pylabel-project/samples/blob/main/pylabel2azure_custom_vision.ipynb.

    PyLabel can read annotations from COCO, YOLO, or VOC format into a dataframe. Once they are in the data frame you can loop through the dataframe of annotations and use the Custom Vision APIs to upload the images and annotations.

    Here is a snippet of the code from the notebook mentioned above:

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

    Note, I am a Microsoft employee but I am not a member of the Azure Custom Vision team. But I think PyLabel can help with this task so I wanted to share this with you.

    0 comments No comments