Search before asking
Bug
Hi!! I'm using supervision for it can view the result of segment-anything following tutorial: https://blog.roboflow.com/how-to-use-segment-anything-model-sam/
The problem is when I want to draw masks on an image using provided detections with Segment-Anything (SAM).
The error is:
annotated_image = mask_annotator.annotate(scene=image_bgr.copy(), detections=detections)
File "/home/oem/.local/lib/python3.8/site-packages/supervision/annotators/core.py", line 143, in annotate
idx = resolve_color_idx(
File "/home/oem/.local/lib/python3.8/site-packages/supervision/annotators/utils.py", line 34, in resolve_color_idx
raise ValueError(
ValueError: Could not resolve color by class becauseDetections do not have class_id
Environment
- Supervision: 0.15.0
- Python: 3.8
- Ubuntu: 20.04
- python-opencv: 4.8.1.78
- Segment-Anything
Minimal Reproducible Example
import cv2
from segment_anything import sam_model_registry, SamAutomaticMaskGenerator, SamPredictor
import supervision as sv
import time
IMAGE_PATH = "image1.jpg"
if name == 'main':
sam_checkpoint = "sam_vit_h_4b8939.pth"
model_type = "default"
device = "cuda"
sam = sam_model_registry[model_type](checkpoint=sam_checkpoint)
sam.to(device=device)
mask_generator = SamAutomaticMaskGenerator(sam)
image_bgr = cv2.imread(IMAGE_PATH)
image_rgb = cv2.cvtColor(image_bgr, cv2.COLOR_BGR2RGB)
result = mask_generator.generate(image_rgb)
mask_annotator = sv.MaskAnnotator()
detections = sv.Detections.from_sam(result)
annotated_image = mask_annotator.annotate(scene=image_bgr.copy(), detections=detections)
Additional
No response
Are you willing to submit a PR?
Search before asking
Bug
Hi!! I'm using supervision for it can view the result of segment-anything following tutorial: https://blog.roboflow.com/how-to-use-segment-anything-model-sam/
The problem is when I want to draw masks on an image using provided detections with Segment-Anything (SAM).
The error is:
annotated_image = mask_annotator.annotate(scene=image_bgr.copy(), detections=detections)
File "/home/oem/.local/lib/python3.8/site-packages/supervision/annotators/core.py", line 143, in annotate
idx = resolve_color_idx(
File "/home/oem/.local/lib/python3.8/site-packages/supervision/annotators/utils.py", line 34, in resolve_color_idx
raise ValueError(
ValueError: Could not resolve color by class becauseDetections do not have class_id
Environment
Minimal Reproducible Example
import cv2
from segment_anything import sam_model_registry, SamAutomaticMaskGenerator, SamPredictor
import supervision as sv
import time
IMAGE_PATH = "image1.jpg"
if name == 'main':
sam_checkpoint = "sam_vit_h_4b8939.pth"
model_type = "default"
device = "cuda"
Additional
No response
Are you willing to submit a PR?