Vision Transformer
Nobody has claimed this yet.
- Dominant language
- Jupyter Notebook
- Stars
- 9.7k
- Forks
- 1.5k
- PR merge metrics
- No merged PRs in 30d
Description
Search before asking
- I have searched the Roboflow Notebooks issues and found no similar bug report.
Notebook name
GOOGLE COLLAB
Bug
I am getting the 'Key Error'='annotations'
And Type of Error: Detections._Getitem not supported for index of type <class 'numpy.ndarray'>....
Please Do guide me with the following error how can i come up with it.
Will really appreciate it.
Environment
Google Colab
Minimal Reproducible Example
import random
import cv2
import numpy as np
import pandas as pd
utils
categories = TEST_DATASET.coco.cats
id2label = {k: v['name'] for k,v in categories.items()}
box_annotator = sv.BoxAnnotator()
select random image
image_ids = TEST_DATASET.coco.getImgIds()
image_id = random.choice(image_ids)
print('Image #{}'.format(image_id))
load image and annotatons
image = TEST_DATASET.coco.loadImgs(image_id)[0]
annotations = TEST_DATASET.coco.imgToAnns[image_id]
image_path = os.path.join(TEST_DATASET.root, image['file_name'])
image = cv2.imread(image_path)
annotate
detections = sv.Detections.from_coco_annotations(coco_annotation=annotations)
labels = [f"{id2label[class_id]}" for _, _, class_id, _ in detections]
frame = box_annotator.annotate(scene=image.copy(), detections=detections, labels=labels)
print('ground truth')
%matplotlib inline
sv.show_frame_in_notebook(frame, (16, 16))
inference
with torch.no_grad():
# load image and predict
inputs = image_processor(images=image, return_tensors='pt').to(DEVICE)
outputs = model(**inputs)
# post-process
target_sizes = torch.tensor([image.shape[:2]]).to(DEVICE)
results = image_processor.post_process_object_detection(
outputs=outputs,
threshold=CONFIDENCE_TRESHOLD,
target_sizes=target_sizes
)[0]
annotate
detections_obj = sv.Detections.from_transformers(transformers_results=results).with_nms(threshold=0.5)
detections = detections_obj.get_data()
labels = [f"{id2label[class_id]} {confidence:.2f}" for _, confidence, class_id, _ in detections]
frame = box_annotator.annotate(scene=image.copy(), detections=detections_obj, labels=labels)
print(type(detections))
%matplotlib inline
sv.show_frame_in_notebook(frame, (16, 16))
Additional
No response
Are you willing to submit a PR?
- Yes I'd like to help by submitting a PR!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Google Colab minimal reproducible example, especially the Detections.from_coco_annotations, Detections.from_transformers, and get_data entry points. Re-run the ground-truth and inference annotation sections and compare the reported errors; done means the notebook completes both paths and displays the annotated output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- jupyter-notebook, opencv, python, pytorch
- Domain
- computer-vision, machine-learning
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100