The repository provides code for running inference with the SegmentAnything Model (SAM), links for downloading the trained model checkpoints, and example notebooks that show how to use the model.
Apache License 2.0
46.57k
stars
5.52k
forks
source link
TypeError issue while Running MobileSAM and EdgeSAM #687
Hi @Celebio @nlutsenko @colesbury @pdollar @calebrob6
Thanks for the great work.I was trying to run Grounded MobileSAM and EdgeSAM which is of course importing functions from SAM.Following issue I was facing from predict_masks function in SAM code.Can you pls help me in fixing this ?
/opt/conda/lib/python3.10/site-packages/torch/functional.py:504: UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument. (Triggered internally at ../aten/src/ATen/native/TensorShape.cpp:3526.)
return _VF.meshgrid(tensors, kwargs) # type: ignore[attr-defined]
final text_encoder_type: bert-base-uncased
/opt/conda/lib/python3.10/site-packages/transformers/modeling_utils.py:942: FutureWarning: The device argument is deprecated and will be removed in v5 of Transformers.
warnings.warn(
/opt/conda/lib/python3.10/site-packages/torch/utils/checkpoint.py:429: UserWarning: torch.utils.checkpoint: please pass in use_reentrant=True or use_reentrant=False explicitly. The default value of use_reentrant will be updated to be False in the future. To maintain current behavior, pass use_reentrant=True. It is recommended that you use use_reentrant=False. Refer to docs for more details on the differences between the two variants.
warnings.warn(
/opt/conda/lib/python3.10/site-packages/torch/utils/checkpoint.py:61: UserWarning: None of the inputs have requires_grad=True. Gradients will be None
warnings.warn(
Detections(xyxy=array([[ 74.942444, 82.034515, 936.3782 , 920.2074 ]], dtype=float32), mask=None, confidence=array([0.9357401], dtype=float32), class_id=array([0]), tracker_id=None, data={})
Before NMS: 1 boxes
After NMS: 1 boxes
Traceback (most recent call last):
File "/home/ubuntu/slime/Grounded-Segment-Anything/EfficientSAM/grounded_edge_sam.py", line 94, in
detections.mask = segment(
File "/home/ubuntu/slime/Grounded-Segment-Anything/EfficientSAM/grounded_edge_sam.py", line 82, in segment
masks, scores, logits = sam_predictor.predict(
File "/opt/conda/lib/python3.10/site-packages/segment_anything/predictor.py", line 154, in predict
masks, iou_predictions, low_res_masks = self.predict_torch(
File "/opt/conda/lib/python3.10/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
return func(*args, *kwargs)
File "/opt/conda/lib/python3.10/site-packages/segment_anything/predictor.py", line 229, in predict_torch
low_res_masks, iou_predictions = self.model.mask_decoder(
File "/opt/conda/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1518, in _wrapped_call_impl
return self._call_impl(args, kwargs)
File "/opt/conda/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl
return forward_call(*args, **kwargs)
File "/opt/conda/lib/python3.10/site-packages/segment_anything/modeling/mask_decoder.py", line 94, in forward
masks, iou_pred = self.predict_masks(
File "/opt/conda/lib/python3.10/site-packages/segment_anything/modeling/mask_decoder.py", line 127, in predict_masks
src = torch.repeat_interleave(image_embeddings, tokens.shape[0], dim=0)
TypeError: repeat_interleave() received an invalid combination of arguments - got (tuple, int, dim=int), but expected one of:
(Tensor input, Tensor repeats, int dim, *, int output_size)
(Tensor repeats, *, int output_size)
didn't match because some of the keywords were incorrect: dim
(Tensor input, int repeats, int dim, *, int output_size)
Hi @Celebio @nlutsenko @colesbury @pdollar @calebrob6 Thanks for the great work.I was trying to run Grounded MobileSAM and EdgeSAM which is of course importing functions from SAM.Following issue I was facing from predict_masks function in SAM code.Can you pls help me in fixing this ?
/opt/conda/lib/python3.10/site-packages/torch/functional.py:504: UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument. (Triggered internally at ../aten/src/ATen/native/TensorShape.cpp:3526.) return _VF.meshgrid(tensors, kwargs) # type: ignore[attr-defined] final text_encoder_type: bert-base-uncased /opt/conda/lib/python3.10/site-packages/transformers/modeling_utils.py:942: FutureWarning: The
detections.mask = segment(
File "/home/ubuntu/slime/Grounded-Segment-Anything/EfficientSAM/grounded_edge_sam.py", line 82, in segment
masks, scores, logits = sam_predictor.predict(
File "/opt/conda/lib/python3.10/site-packages/segment_anything/predictor.py", line 154, in predict
masks, iou_predictions, low_res_masks = self.predict_torch(
File "/opt/conda/lib/python3.10/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
return func(*args, *kwargs)
File "/opt/conda/lib/python3.10/site-packages/segment_anything/predictor.py", line 229, in predict_torch
low_res_masks, iou_predictions = self.model.mask_decoder(
File "/opt/conda/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1518, in _wrapped_call_impl
return self._call_impl(args, kwargs)
File "/opt/conda/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl
return forward_call(*args, **kwargs)
File "/opt/conda/lib/python3.10/site-packages/segment_anything/modeling/mask_decoder.py", line 94, in forward
masks, iou_pred = self.predict_masks(
File "/opt/conda/lib/python3.10/site-packages/segment_anything/modeling/mask_decoder.py", line 127, in predict_masks
src = torch.repeat_interleave(image_embeddings, tokens.shape[0], dim=0)
TypeError: repeat_interleave() received an invalid combination of arguments - got (tuple, int, dim=int), but expected one of:
device
argument is deprecated and will be removed in v5 of Transformers. warnings.warn( /opt/conda/lib/python3.10/site-packages/torch/utils/checkpoint.py:429: UserWarning: torch.utils.checkpoint: please pass in use_reentrant=True or use_reentrant=False explicitly. The default value of use_reentrant will be updated to be False in the future. To maintain current behavior, pass use_reentrant=True. It is recommended that you use use_reentrant=False. Refer to docs for more details on the differences between the two variants. warnings.warn( /opt/conda/lib/python3.10/site-packages/torch/utils/checkpoint.py:61: UserWarning: None of the inputs have requires_grad=True. Gradients will be None warnings.warn( Detections(xyxy=array([[ 74.942444, 82.034515, 936.3782 , 920.2074 ]], dtype=float32), mask=None, confidence=array([0.9357401], dtype=float32), class_id=array([0]), tracker_id=None, data={}) Before NMS: 1 boxes After NMS: 1 boxes Traceback (most recent call last): File "/home/ubuntu/slime/Grounded-Segment-Anything/EfficientSAM/grounded_edge_sam.py", line 94, in