facebookresearch / facebookresearch/sam2

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

Open
#482 0 comments 5 reactions 0 assignees View on GitHub
Dominant language
Jupyter Notebook
Stars
19.9k
Forks
2.5k
PR merge metrics
No merged PRs in 30d

Description

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.

```bash
Traceback (most recent call last):
File "/sam2/predict-tmp.py", line 372, in
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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.