kadirnar / segment-anything-video

MetaSeg: Packaged version of the Segment Anything repository
Apache License 2.0
946 stars 67 forks source link

I have this problem.IndexError: list index out of range. #55

Open threeneedone opened 1 year ago

threeneedone commented 1 year ago

[] vit_b model already exists as 'vit_b.pth'. Skipping download. Traceback (most recent call last): File "e:/AIGC/segment-anything-video/test", line 17, in SahiAutoSegmentation().predict( File "e:\AIGC\segment-anything-video\metaseg\sahi_predict.py", line 87, in predict if type(input_box[0]) == list: IndexError: list index out of range how to deal it?

def predict(
    self,
    source,
    model_type,
    input_box=None,
    input_point=None,
    input_label=None,
    multimask_output=False,
    random_color=False,
    show=False,
    save=False,
):

    read_image = load_image(source)
    model = self.load_model(model_type)
    predictor = SamPredictor(model)
    predictor.set_image(read_image)

this if type(input_box[0]) == list: input_boxes, new_boxes = multi_boxes(input_box, predictor, read_image)

        masks, _, _ = predictor.predict_torch(
            point_coords=None,
            point_labels=None,
saschwarz commented 1 year ago

It looks like predict is being called with input_box set to an empty list. What does your code that calls this method look like?

kadirnar commented 1 year ago

[] vit_b model already exists as 'vit_b.pth'. Skipping download. Traceback (most recent call last): File "e:/AIGC/segment-anything-video/test", line 17, in SahiAutoSegmentation().predict( File "e:\AIGC\segment-anything-video\metaseg\sahi_predict.py", line 87, in predict if type(input_box[0]) == list: IndexError: list index out of range how to deal it?

def predict(
    self,
    source,
    model_type,
    input_box=None,
    input_point=None,
    input_label=None,
    multimask_output=False,
    random_color=False,
    show=False,
    save=False,
):

    read_image = load_image(source)
    model = self.load_model(model_type)
    predictor = SamPredictor(model)
    predictor.set_image(read_image)

this if type(input_box[0]) == list: input_boxes, new_boxes = multi_boxes(input_box, predictor, read_image)

        masks, _, _ = predictor.predict_torch(
            point_coords=None,
            point_labels=None,

Can you share your code?

threeneedone commented 1 year ago

from metaseg import sahi_sliced_predict, SahiAutoSegmentation

image_path = "A-9.bmp" boxes = sahi_sliced_predict( image_path=image_path, detection_model_type="yolov8", #yolov8, detectron2, mmdetection, torchvision detection_model_path="best.pt", conf_th=0.25, image_size=640, slice_height=256, slice_width=256, overlap_height_ratio=0.2, overlap_width_ratio=0.2, )

print(boxes) SahiAutoSegmentation().predict( source=image_path, model_type="vit_b", input_box=boxes, multimask_output=False, random_color=False, show=True, save=False, )

the source code is as follows.When I use some pictures(image_path), I report this error.

kadirnar commented 1 year ago

Can you try making the extension of the image png or jpg?

th0mas-codes commented 11 months ago

As mentioned in #67

I found that commenting out the second "result" variable right after the get_sliced_predicition properly passed the output boxes to SahiAutoSegmentation().image_predict where as before it was always an empty array.

its found in sahi_predictor.py

result = get_sliced_prediction(
    image_path,
    detection_model,
    slice_height=slice_height,
    slice_width=slice_width,
    overlap_height_ratio=overlap_height_ratio,
    overlap_width_ratio=overlap_width_ratio,
)

# result = get_prediction(image_path, detection_model) <-- comment out this line