Skip to content

Commit

Permalink
Simplify Mask Handling When Only One Object is Detected (#352)
Browse files Browse the repository at this point in the history
* Fix empty mask overlay handling when no objects are detected.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* mask overlay corrected

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Handle case for single objects detected.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
ro-hit81 and pre-commit-ci[bot] authored Oct 22, 2024
1 parent 7d1d648 commit 28b6e46
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion samgeo/text_sam.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,10 @@ def predict(
masks = torch.tensor([])
if len(boxes) > 0:
masks = self.predict_sam(image_pil, boxes)
if 1 in masks.shape:
# If masks have 4 dimensions and the second dimension is 1 (e.g., [boxes, 1, height, width]),
# squeeze that dimension to reduce it to 3 dimensions ([boxes, height, width]).
# If boxes = 1, the mask's shape will be [1, height, width] after squeezing.
if masks.ndim == 4 and masks.shape[1] == 1:
masks = masks.squeeze(1)

if boxes.nelement() == 0: # No "object" instances found
Expand Down

0 comments on commit 28b6e46

Please sign in to comment.