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

Conversation

yrkim98
Copy link
Contributor

@yrkim98 yrkim98 commented Dec 9, 2024

What does this PR do?

Allows numpy arrays to be passed into the auththresholding function in AutoThresh.py while still allowing torch tensors as before.

Allows thresholding to work properly

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?

# 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):
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)

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):
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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants