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

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

Open
threeneedone opened this issue Apr 23, 2023 · 5 comments
Open

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

threeneedone opened this issue Apr 23, 2023 · 5 comments
Assignees
Labels
good first issue Good for newcomers

Comments

@threeneedone
Copy link

[]
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
Copy link

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 kadirnar self-assigned this Apr 23, 2023
@kadirnar kadirnar added the good first issue Good for newcomers label Apr 23, 2023
@kadirnar
Copy link
Owner

[] 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
Copy link
Author

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
Copy link
Owner

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

@th0mas-codes
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

4 participants