Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug during as_coco() conversion for segmentation (+ solution) #1085

Open
2 tasks done
Youho99 opened this issue Apr 2, 2024 · 0 comments
Open
2 tasks done

Bug during as_coco() conversion for segmentation (+ solution) #1085

Youho99 opened this issue Apr 2, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@Youho99
Copy link

Youho99 commented Apr 2, 2024

Search before asking

  • I have searched the Supervision issues and found no similar bug report.

Bug

Ce problème fait suite au travail fait sur mon précédent issue #1052

results.as_coco(annotations_path="test_coco/", min_image_area_percentage=0.01,)

IndexError: list index out of range

The problem is due to the fact that in certain cases, the mask returned by GroundedSam is completely inconsistent (less than 3 pixels for example). In this specific case, the function approximate_mask_with_polygons() (as_coco() > detections_to_coco_annotations() > approximate_mask_with_polygons()) returns an empty array.

So, the line

list(approximate_mask_with_polygons(
             mask=mask,
             min_image_area_percentage=min_image_area_percentage,
             max_image_area_percentage=max_image_area_percentage,
             approximation_percentage=approximation_percentage,
         )[0].flatten()

causes my error, because there is no item '0' in an empty list.

I will propose a fix following the writing of this issue.

I changed the architecture of the as_coco() function to be the same as the as_yolo() and as_pascal_voc() architecture.

Environment

Supervision 0.19.0

Minimal Reproducible Example

from autodistill_grounded_sam import GroundedSAM
from autodistill.detection import CaptionOntology
from pathlib import Path
import supervision as sv
import os
import shutil
# Put the cat image on your input directory
# Put your input directory path
input_dir = "/home/ggiret/Téléchargements/chat"
output_dir = "test/"
if os.path.exists(output_dir):
    shutil.rmtree(output_dir)

classes = {"cat": "a cat",}

base_model = GroundedSAM(
    ontology=CaptionOntology(
        classes
    ),
    box_threshold = 0.005
)
results = base_model.label(
        input_folder=input_dir,
        extension=".png",
        output_folder=output_dir, 
        record_confidence=True)
results.as_coco(annotations_path="test_coco/", min_image_area_percentage=0.01,)

Image to use :
téléchargement (4)

Additional

In the code that I am going to propose, as_coco() will record either the BoundingBoxes coordinates or the Segmentation coordinates, but not both at the same time.

Are you willing to submit a PR?

  • Yes I'd like to help by submitting a PR!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant