supervision icon indicating copy to clipboard operation
supervision copied to clipboard

InferenceSlicer error: all the input array dimensions except for the concatenation axis must match exactly

Open zouxiaodong opened this issue 2 years ago • 0 comments

Search before asking

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

Bug

i want to use segemt anything with a high resolution image, slicer error : all the input array dimensions except for the concatenation axis must match exactly

image = cv2.imread("./pest.jpg")
slicer = sv.InferenceSlicer(slice_wh=(1024,1024),thread_workers=4,callback=callback)
sliced_detections = slicer(image=image)

pest.jpg resoultion:5472x3648 pest

error info as follow:

ValueError                                Traceback (most recent call last)
Cell In[2], line 4
      1 image = cv2.imread("./pest.jpg")
      3 slicer = sv.InferenceSlicer(slice_wh=(1024,1024),thread_workers=4,callback=callback)
----> 4 sliced_detections = slicer(image=image)

File ~/anaconda3/envs/sam/lib/python3.10/site-packages/supervision/detection/tools/inference_slicer.py:112, in InferenceSlicer.__call__(self, image)
    109     for future in as_completed(futures):
    110         detections_list.append(future.result())
--> 112 return Detections.merge(detections_list=detections_list).with_nms(
    113     threshold=self.iou_threshold
    114 )

File ~/anaconda3/envs/sam/lib/python3.10/site-packages/supervision/detection/core.py:590, in Detections.merge(cls, detections_list)
    587     return all(x is not None for x in item_list)
    589 xyxy = np.vstack(xyxy)
--> 590 mask = np.vstack(mask) if __all_not_none(mask) else None
    591 confidence = np.hstack(confidence) if __all_not_none(confidence) else None
    592 class_id = np.hstack(class_id) if __all_not_none(class_id) else None

File <__array_function__ internals>:200, in vstack(*args, **kwargs)

File ~/anaconda3/envs/sam/lib/python3.10/site-packages/numpy/core/shape_base.py:296, in vstack(tup, dtype, casting)
    294 if not isinstance(arrs, list):
    295     arrs = [arrs]
--> 296 return _nx.concatenate(arrs, 0, dtype=dtype, casting=casting)

File <__array_function__ internals>:200, in concatenate(*args, **kwargs)

ValueError: all the input array dimensions except for the concatenation axis must match exactly, but along dimension 2, the array at index 0 has size 1024 and the array at index 8 has size 552

Environment

  • supervision:0.16.0

Minimal Reproducible Example

import supervision as sv
import numpy as np
import cv2


def callback(x: np.ndarray) -> sv.Detections:
    from segment_anything import (
    sam_model_registry,
    SamAutomaticMaskGenerator
    )
    sam_model_reg = sam_model_registry['vit_b']
    sam = sam_model_reg(checkpoint='vit_b.pth').to(device='cuda:0')
    mask_generator = SamAutomaticMaskGenerator(sam)
    sam_result = mask_generator.generate(x)
    detections = sv.Detections.from_sam(sam_result=sam_result)
    return detections

image = cv2.imread("./pest.jpg")

slicer = sv.InferenceSlicer(slice_wh=(1024,1024),thread_workers=4,callback=callback)
sliced_detections = slicer(image=image)

Additional

No response

Are you willing to submit a PR?

  • [ ] Yes I'd like to help by submitting a PR!

zouxiaodong avatar Nov 20 '23 05:11 zouxiaodong