Skip to content

Minimum image size? #70

Open
Open
@neilkale

Description

I am trying to run grounded_sam2_local_demo.py on the image below, but I am finding the following stack trace. Is there a minimum image size for SAM2, or is some other issue at play?

Traceback (most recent call last): File "/home/nkale/ml_projects/Grounded-SAM-2/grounded_sam2_local_demo.py", line 80, in <module> masks, scores, logits = sam2_predictor.predict( File "/home/nkale/ml_projects/Grounded-SAM-2/sam2/sam2_image_predictor.py", line 291, in predict masks, iou_predictions, low_res_masks = self._predict( File "/home/nkale/miniconda3/envs/gsam2env/lib/python3.10/site-packages/torch/utils/_contextlib.py", line 116, in decorate_context return func(*args, **kwargs) File "/home/nkale/ml_projects/Grounded-SAM-2/sam2/sam2_image_predictor.py", line 420, in _predict low_res_masks, iou_predictions, _, _ = self.model.sam_mask_decoder( File "/home/nkale/miniconda3/envs/gsam2env/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1736, in _wrapped_call_impl return self._call_impl(*args, **kwargs) File "/home/nkale/miniconda3/envs/gsam2env/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1747, in _call_impl return forward_call(*args, **kwargs) File "/home/nkale/ml_projects/Grounded-SAM-2/sam2/modeling/sam/mask_decoder.py", line 136, in forward masks, iou_pred, mask_tokens_out, object_score_logits = self.predict_masks( File "/home/nkale/ml_projects/Grounded-SAM-2/sam2/modeling/sam/mask_decoder.py", line 203, in predict_masks assert image_embeddings.shape[0] == tokens.shape[0] AssertionError

image

Activity

changed the title minimum image size? Minimum image size? on Nov 16, 2024
ShuoShenDe

ShuoShenDe commented on Dec 10, 2024

@ShuoShenDe
Contributor

Hi~Dear,

To help us debug the issue more effectively, could you please provide the following additional information:

Input details:
How are you loading and preprocessing the image before passing it to the model?

Environment details:
Could you share your system configuration, such as the version of Python, PyTorch, and any relevant libraries you're using?

Additional runtime information:
Please output and share the shapes of image_embeddings and tokens just before the assertion error occurs. This will help us understand the source of the mismatch.

Shuo Shen

sunjian2015

sunjian2015 commented on Feb 14, 2025

@sunjian2015

I am trying to run grounded_sam2_local_demo.py on the image below, but I am finding the following stack trace. Is there a minimum image size for SAM2, or is some other issue at play?

Traceback (most recent call last): File "/home/nkale/ml_projects/Grounded-SAM-2/grounded_sam2_local_demo.py", line 80, in <module> masks, scores, logits = sam2_predictor.predict( File "/home/nkale/ml_projects/Grounded-SAM-2/sam2/sam2_image_predictor.py", line 291, in predict masks, iou_predictions, low_res_masks = self._predict( File "/home/nkale/miniconda3/envs/gsam2env/lib/python3.10/site-packages/torch/utils/_contextlib.py", line 116, in decorate_context return func(*args, **kwargs) File "/home/nkale/ml_projects/Grounded-SAM-2/sam2/sam2_image_predictor.py", line 420, in _predict low_res_masks, iou_predictions, _, _ = self.model.sam_mask_decoder( File "/home/nkale/miniconda3/envs/gsam2env/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1736, in _wrapped_call_impl return self._call_impl(*args, **kwargs) File "/home/nkale/miniconda3/envs/gsam2env/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1747, in _call_impl return forward_call(*args, **kwargs) File "/home/nkale/ml_projects/Grounded-SAM-2/sam2/modeling/sam/mask_decoder.py", line 136, in forward masks, iou_pred, mask_tokens_out, object_score_logits = self.predict_masks( File "/home/nkale/ml_projects/Grounded-SAM-2/sam2/modeling/sam/mask_decoder.py", line 203, in predict_masks assert image_embeddings.shape[0] == tokens.shape[0] AssertionError

image

Have you solve it? I meet the same question...

ShuoShenDe

ShuoShenDe commented on Feb 14, 2025

@ShuoShenDe
Contributor

I am trying to run grounded_sam2_local_demo.py on the image below, but I am finding the following stack trace. Is there a minimum image size for SAM2, or is some other issue at play?
Traceback (most recent call last): File "/home/nkale/ml_projects/Grounded-SAM-2/grounded_sam2_local_demo.py", line 80, in <module> masks, scores, logits = sam2_predictor.predict( File "/home/nkale/ml_projects/Grounded-SAM-2/sam2/sam2_image_predictor.py", line 291, in predict masks, iou_predictions, low_res_masks = self._predict( File "/home/nkale/miniconda3/envs/gsam2env/lib/python3.10/site-packages/torch/utils/_contextlib.py", line 116, in decorate_context return func(*args, **kwargs) File "/home/nkale/ml_projects/Grounded-SAM-2/sam2/sam2_image_predictor.py", line 420, in _predict low_res_masks, iou_predictions, _, _ = self.model.sam_mask_decoder( File "/home/nkale/miniconda3/envs/gsam2env/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1736, in _wrapped_call_impl return self._call_impl(*args, **kwargs) File "/home/nkale/miniconda3/envs/gsam2env/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1747, in _call_impl return forward_call(*args, **kwargs) File "/home/nkale/ml_projects/Grounded-SAM-2/sam2/modeling/sam/mask_decoder.py", line 136, in forward masks, iou_pred, mask_tokens_out, object_score_logits = self.predict_masks( File "/home/nkale/ml_projects/Grounded-SAM-2/sam2/modeling/sam/mask_decoder.py", line 203, in predict_masks assert image_embeddings.shape[0] == tokens.shape[0] AssertionError
image

Have you solve it? I meet the same question...

hi dear, I think the error occurs because the model detect zero target object from the image. So just pass this situation, we have solve it in the grounded_sam2_tracking_demo_with_continuous_id_gd1.5.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Minimum image size? · Issue #70 · IDEA-Research/Grounded-SAM-2