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

Image array normalization uses significant amounts of memory #510

Open
Quantico-Bullet opened this issue Aug 2, 2024 · 1 comment
Open

Comments

@Quantico-Bullet
Copy link

Quantico-Bullet commented Aug 2, 2024

Description of the bug
Normalization of image arrays using the normalize function in the array_utils.py (line: 57) uses a significant amount of memory due to conversion of the initial array dtype from np.int16 to np.float64 for the returned array.

To Reproduce/Check
Simply amend the code to be as follows:

@validate(array=array_not_empty)
def normalize(array: np.ndarray, value: float | None = None) -> np.ndarray:
    """Normalize an array to the passed value. If not value is passed, normalize to the maximum value"""
    print("dtype before: ", array.dtype)
    if value is None:
        val = array.max()
    else:
        val = value
    array = array / val
    print("dtype after: ", array.dtype)
    return array

Possible solution
Return the array with dtype np.float16 using:

return array.astype(np.float16)
@jrkerns
Copy link
Owner

jrkerns commented Sep 4, 2024

I can add a parameter for the desired datatype to the call.

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

No branches or pull requests

2 participants