Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cellSAM/sam_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ def predict_transforms(self, imgs):

return imgs

def sam_preprocess(self, x: torch.Tensor, return_paddings=False):
def sam_preprocess(self, x: torch.Tensor, return_paddings=False, device=None):
"""Normalize pixel values and pad to a square input."""
x = (x - self.model.pixel_mean) / self.model.pixel_std
x = (x - self.model.pixel_mean.to(device)) / self.model.pixel_std.to(device)

h, w = x.shape[-2:]
padh = self.model.image_encoder.img_size - h
Expand All @@ -140,7 +140,7 @@ def sam_bbox_preprocessing(self, x, device=None):
x = [
torch.from_numpy(img).permute(2, 0, 1).contiguous().to(device) for img in x
]
x = [self.sam_preprocess(img, return_paddings=True) for img in x]
x = [self.sam_preprocess(img, return_paddings=True, device=device) for img in x]
x, paddings = zip(*x)
preprocessed_img = torch.stack(x, dim=0)
return preprocessed_img, paddings
Expand Down