Skip to content

Commit 92f7296

Browse files
authored
Support CPU for mask_to_rle_pytorch_2 (#105)
1 parent d40f920 commit 92f7296

File tree

1 file changed

+4
-1
lines changed
  • segment_anything_fast/utils

1 file changed

+4
-1
lines changed

segment_anything_fast/utils/amg.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,10 @@ def mask_to_rle_pytorch_2(tensor: torch.Tensor) -> List[Dict[str, Any]]:
114114

115115
# Compute change indices
116116
diff = tensor[:, 1:] ^ tensor[:, :-1]
117-
a = torch.tensor([[True]]).pin_memory().cuda().expand_as(diff.narrow(1, 0, 1))
117+
a = torch.tensor([[True]])
118+
if diff.is_cuda:
119+
a = a.pin_memory().cuda()
120+
a = a.expand_as(diff.narrow(1, 0, 1))
118121
diff = torch.cat([a, diff, a], dim=1)
119122
change_indices = diff.nonzero()
120123

0 commit comments

Comments
 (0)