Skip to content

Commit

Permalink
infer on CPU if no GPU available
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldoucet committed Jun 12, 2024
1 parent dbc5a45 commit f6e4f2e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/hest/segmentation/segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ def segment_tissue_deep(img: Union[np.ndarray, openslide.OpenSlide, 'CuImage', W
new_state_dict[new_key] = checkpoint['state_dict'][key]
model.load_state_dict(new_state_dict)

model.cuda()
if torch.cuda.is_available():
model.cuda()

model.eval()

Expand All @@ -108,7 +109,8 @@ def segment_tissue_deep(img: Union[np.ndarray, openslide.OpenSlide, 'CuImage', W

# coords are top left coords of patch
imgs, coords = batch
imgs = imgs.cuda()
if torch.cuda.is_available():
imgs = imgs.cuda()
masks = model(imgs)['out']
preds = masks.argmax(1)

Expand Down

0 comments on commit f6e4f2e

Please sign in to comment.