Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow numpy array passed into autothresholding function #454

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
5 changes: 4 additions & 1 deletion cyto_dl/models/im2im/utils/postprocessing/auto_thresh.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ def thresh_func(image):
self.thresh_func = thresh_func

def __call__(self, image):
image = image.detach().cpu().float().numpy()
# Only get numpy array from torch tensor if tensor is passed in
# Allows np.ndarray to be passed in directly
if not isinstance(image, np.ndarray):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Im not a fan of reassigning an arg (I know this was already happening before the change). Could you use a new local var?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(same as below) this might be better as if isinstance(image, torch.Tensor)

image = image.detach().cpu().float().numpy()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(feel free to ignore since this is out of the scope of the pr)
there's also a detach function that does the detach->cpu->numpy conversion, so this could be replaced with
img = detach(img).astype(float)

if self.thresh_func is None:
return image
return (image > self.thresh_func(image)).astype(np.uint8)
Loading