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

Need to clear tf session if looping through images #1

Open
jameybrowning opened this issue Apr 1, 2020 · 3 comments
Open

Need to clear tf session if looping through images #1

jameybrowning opened this issue Apr 1, 2020 · 3 comments
Labels
enhancement New feature or request

Comments

@jameybrowning
Copy link

jameybrowning commented Apr 1, 2020

Thanks for the code. Just a few notes in case anyone else runs into the same problems. I needed to add a statement to clear the session when I was using mclahe to loop through thousands of 3D images on a CPU. Otherwise, memory usage expands and code slows to a crawl. Also, the default kernel size is 1/8 of data dimensions. For a 3D image with one dimension less than 8, I got an error. I needed to change kernel size to ceiling of 1/8 image dims. These fixes are shown below.

for i, full_path in enumerate(full_paths):
    os.makedirs(paths_new[i], exist_ok = True)
    print(i)
    img_arr, meta_data = load(full_path)
    dims = np.shape(img_arr)
    img_arr_eq = mc.mclahe(img_arr, kernel_size = [int(np.ceil(dims[0]/8)), int(np.ceil(dims[1]/8)), int(np.ceil(dims[2]/8))])
    save(img_arr_eq, full_paths_new[i], meta_data)
    tf.keras.backend.clear_session()
@RealPolitiX RealPolitiX added the enhancement New feature or request label Jul 31, 2020
@pauliustumas
Copy link

Yes, saved me days! Thank you, this tf.keras.backend.clear_session() does the magic.

@SidGul
Copy link

SidGul commented Jun 8, 2021

hi,
Can we use this code for 3d volumetric images?

@RealPolitiX
Copy link
Collaborator

@SidGul, yes, it works for arbitrary dimensional images.

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

No branches or pull requests

4 participants