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

GroundingDINO autodistill inference troubleshooting #143

Open
1 task
SCAlex91 opened this issue Mar 15, 2024 · 1 comment
Open
1 task

GroundingDINO autodistill inference troubleshooting #143

SCAlex91 opened this issue Mar 15, 2024 · 1 comment
Labels
question Further information is requested

Comments

@SCAlex91
Copy link

SCAlex91 commented Mar 15, 2024

Search before asking

  • I have searched the Autodistill issues and found no similar feature requests.

Question

I am trying to create some annotations using GroundingDINO using "inference" and "autodistill" libraries, and visualize the detections and annotations that were applied to the images. I can't use plot function because I am using the terminal to access the arch linux node, and I am trying to write the annotations to each image using "cv2". The following code works, but when I inspect the images, the detections are not showing at all on the images. Any ideas on what might be going wrong?

`from autodistill_grounding_dino import GroundingDINO
from autodistill.detection import CaptionOntology
from autodistill.utils import plot
import supervision as sv
import cv2
import os

images = ["../Images/batch_12/000062.jpg", "../Images/batch_1/000014.jpg", "../Images/batch_12/000061.jpg", "../Images/batch_12/000043.jpg", "../Images/batch_12/000084.jpg"]

for image in images:

image_dir, image_file = os.path.split(image)
image_filename, image_extension = os.path.splitext(image_file)

image = cv2.imread(image)

ontology = CaptionOntology(
    {
        "garbage": "garbage",
    }
)

model = GroundingDINO(ontology=ontology)

result = model.predict(image)

detections = sv.Detections.from_inference(result)

bounding_box_annotator = sv.BoundingBoxAnnotator(thickness=8, color=sv.ColorPalette.DEFAULT.by_idx(12))
label_annotator = sv.LabelAnnotator(text_thickness=3, text_scale=1.5, text_color=sv.Color.WHITE, color=sv.Color.ROBOFLOW)

labels = [
f"{model.ontology.classes()[class_id]} {confidence:0.2f}"
for _, _, confidence, class_id, _ in detections
]

annotated_image = bounding_box_annotator.annotate(
	scene=image.copy(), detections=detections
)

annotated_image = label_annotator.annotate(
scene=annotated_image, detections=detections, labels=labels
)

cv2.imwrite(f'./predictions/{image_filename}_groundingDINO_autodistill.jpg', annotated_image)`

Additional

No response

@SCAlex91 SCAlex91 added the question Further information is requested label Mar 15, 2024
@capjamesg
Copy link
Member

Hello there! If you run print(detections), what do you get?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants