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

AttributeError: 'numpy.ndarray' object has no attribute 'clone' (when using image coordinates for box prompt) #196

Open
barakhurwitz opened this issue Sep 12, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@barakhurwitz
Copy link

barakhurwitz commented Sep 12, 2023

Environment Information

  • samgeo version: v0.10.1
  • Python version: 3.10.12
  • Operating System: running in colab

Description

Describe what you were trying to get done.
Tell us what happened, what went wrong, and what you expected to happen.

What I Did

Trying to segment using box prompt
( boxes defined without CRS , i want to use image coordinates )
based on this box prompt example: , :https://samgeo.gishub.org/examples/box_prompts/
trying to run without CRS

boxes_2 = [
        [0, 0, 162, 56],
        [227, 0, 310, 24],  
    ]

sam.predict(boxes=boxes_2 , output="mask.tif", dtype="uint8")

Error:
AttributeError: 'numpy.ndarray' object has no attribute 'clone'

traceback :
/usr/local/lib/python3.10/dist-packages/samgeo/samgeo.py in predict(self, point_coords, point_labels, boxes, point_crs, mask_input, multimask_output, return_logits, output, index, mask_multiplier, dtype, return_results, **kwargs)
583 )
584 else:
--> 585 masks, scores, logits = predictor.predict_torch(
586 point_coords=point_coords,
587 point_labels=point_coords,

/usr/local/lib/python3.10/dist-packages/torch/utils/_contextlib.py in decorate_context(*args, **kwargs)
113 def decorate_context(*args, **kwargs):
114 with ctx_factory():
--> 115 return func(*args, **kwargs)
116
117 return decorate_context

/usr/local/lib/python3.10/dist-packages/segment_anything/predictor.py in predict_torch(self, point_coords, point_labels, boxes, mask_input, multimask_output, return_logits)
220
221 # Embed prompts
--> 222 sparse_embeddings, dense_embeddings = self.model.prompt_encoder(
223 points=points,
224 boxes=boxes,

/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py in _call_impl(self, *args, **kwargs)
1499 or _global_backward_pre_hooks or _global_backward_hooks
1500 or _global_forward_hooks or _global_forward_pre_hooks):
-> 1501 return forward_call(*args, **kwargs)
1502 # Do not call functions when jit is used
1503 full_backward_hooks, non_full_backward_hooks = [], []

/usr/local/lib/python3.10/dist-packages/segment_anything/modeling/prompt_encoder.py in forward(self, points, boxes, masks)
156 sparse_embeddings = torch.cat([sparse_embeddings, point_embeddings], dim=1)
157 if boxes is not None:
--> 158 box_embeddings = self._embed_boxes(boxes)
159 sparse_embeddings = torch.cat([sparse_embeddings, box_embeddings], dim=1)
160

/usr/local/lib/python3.10/dist-packages/segment_anything/modeling/prompt_encoder.py in _embed_boxes(self, boxes)
95 boxes = boxes + 0.5 # Shift to center of pixel
96 coords = boxes.reshape(-1, 2, 2)
---> 97 corner_embedding = self.pe_layer.forward_with_coords(coords, self.input_image_size)
98 corner_embedding[:, 0, :] += self.point_embeddings[2].weight
99 corner_embedding[:, 1, :] += self.point_embeddings[3].weight

/usr/local/lib/python3.10/dist-packages/segment_anything/modeling/prompt_encoder.py in forward_with_coords(self, coords_input, image_size)
209 ) -> torch.Tensor:
210 """Positionally encode points that are not normalized to [0,1]."""
--> 211 coords = coords_input.clone()
212 coords[:, :, 0] = coords[:, :, 0] / image_size[1]
213 coords[:, :, 1] = coords[:, :, 1] / image_size[0]

AttributeError: 'numpy.ndarray' object has no attribute 'clone'

@barakhurwitz barakhurwitz added the bug Something isn't working label Sep 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant