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

'IndexError: too many indices for tensor of dimension 1' in sam2.automatic_mask_generator.SAM2AutomaticMaskGenerator._generate_masks #482

Open
darkstar1227 opened this issue Dec 9, 2024 · 0 comments

Comments

@darkstar1227
Copy link

darkstar1227 commented Dec 9, 2024

I am generating the mask by SAM2AutomaticMaskGenerator. I use the code that I wrote before and it works well. The only change is that it is the new model that I train it with differnt resolusion(the default is 1024, and I cahge it to 512). Then, there is a image that always shows the error (error messege bellow). And I find out, after the function '_generate_masks' done the for loop (232:235, automatic_mask_generator.py) makes the variable data["crop_boxes"] to the shape equal to zero and it crash the program.

Traceback (most recent call last):
  File "/sam2/predict-tmp.py", line 372, in <module>
    main()
  File "/sam2/predict-tmp.py", line 342, in main
    masks = mask_generator.generate(image)
  File "/opt/conda/lib/python3.10/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
    return func(*args, **kwargs)
  File "/sam2/sam2/automatic_mask_generator.py", line 196, in generate
    mask_data = self._generate_masks(image)
  File "/sam2/sam2/automatic_mask_generator.py", line 242, in _generate_masks
    scores = 1 / box_area(data["crop_boxes"])
  File "/opt/conda/lib/python3.10/site-packages/torchvision/ops/boxes.py", line 251, in box_area
    return (boxes[:, 2] - boxes[:, 0]) * (boxes[:, 3] - boxes[:, 1])
IndexError: too many indices for tensor of dimension 1

I am wondering why is that happening. Before I change the resolusion to 512, the code run perfectly.

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

No branches or pull requests

1 participant