Skip to content

Commit ebd8eea

Browse files
authored
load model onto cpu if cuda isn't available (#25)
1 parent cf72405 commit ebd8eea

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

segment_anything/build_sam.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ def _build_sam(
157157
sam.eval()
158158
if checkpoint is not None:
159159
with open(checkpoint, "rb") as f:
160-
state_dict = torch.load(f)
160+
device = "cuda" if torch.cuda.is_available() else "cpu"
161+
state_dict = torch.load(f, map_location=device)
161162
info = sam.load_state_dict(state_dict, strict=False)
162163
print(info)
163164
for n, p in sam.named_parameters():

0 commit comments

Comments
 (0)