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

Potential memory leak #117

Closed
jankrepl opened this issue Feb 10, 2020 · 5 comments
Closed

Potential memory leak #117

jankrepl opened this issue Feb 10, 2020 · 5 comments

Comments

@jankrepl
Copy link

Describe the bug
When computing image similarities the memory is not cleared after computation.

To Reproduce
Run the below minimal example and have htop running at the same time.

import ants
import numpy as np

img = np.random.random((400, 400))
img_ants = ants.image_clone(ants.from_numpy(img), pixeltype='float')

for i in range(50000000000):
    ants.image_similarity(img_ants, img_ants, metric_type='Correlation')

Expected behavior
After each computation of the similarity metric the memory should be cleared. However, the higher the iteration the more memory is taken (eventually leading to out of memory errors).

Desktop

  • OS: Ubuntu 18.04.2 LTS"
  • Version: 0.1.7 (installed via your wheel in releases)
@stnava
Copy link
Member

stnava commented Feb 10, 2020

ok - I verified this. also noting:

  • gc.collect() within the loop does not help.

  • ending the loop does clean it up.

  • same thing with MeanSquares

  • does not happen in ANTsR

  • same thing in OS X - but ending the loop does not clean up the memory.

  • ants.registration does not appear to have the same (degree of?) issues ....

anyway - thanks for this - would appreciate any help with further investigation.

@stnava
Copy link
Member

stnava commented Feb 11, 2020

Fixed by 7008e73

@stnava stnava closed this as completed Feb 11, 2020
@hassaanmahmood
Copy link

I am running code to create atlas, I got full disk error. Is there any solution to this?

 `         for i in range(10):
       Nlin_reg_avg=0
 
for affines in SUBJECTS[:200]:
    


    moving_img = ants.image_read( affines )  
    mytx = ants.registration(fixed=fixed_affine_atlas , moving=moving_img, type_of_transform='SyNOnly', grad_step=0.25 ,      reg_iterations=(30,50,20 ),flow_sigma=9,total_sigma=0.2)
    warped_moving = mytx['warpedmovout']
    Nlin_reg_avg=Nlin_reg_avg+(warped_moving.numpy())
    
Nlin_reg_avg_mean=Nlin_reg_avg/200
Nlin_reg_avg_mean_norm=Nlin_reg_avg_mean/np.max(Nlin_reg_avg_mean)
img = nib.Nifti1Image(Nlin_reg_avg_mean_norm, ref.affine)
nib.save(img, '/Nlin_reg_avg_mean_norm_'+str(i)+'.nii' )
fixed_affine_atlas = ants.from_numpy(Nlin_reg_avg_mean_norm, spacing=fixed_norm_atlas.spacing,
                              origin=fixed_norm_atlas.origin, direction=fixed_norm_atlas.direction)

`
My hard disk got full, on investigation I find /tmp folder of 200G with files like these as below: e.g
/tmp/tmp1y8z1uo80GenericAffine.mat
/tmp/tmp_s4mi6ya1InverseWarp.nii.gz
/tmp/tmpeyew06150GenericAffine.mat
/tmp/tmpr2o5pl5q0GenericAffine.mat
/tmp/tmpuzkont371InverseWarp.nii.gz
/tmp/tmp0p486fke1InverseWarp.nii.gz
/tmp/tmpwegb539c0GenericAffine.mat
/tmp/tmpdctyw2ph1Warp.nii.gz
/tmp/tmp7pzvk9g01InverseWarp.nii.gz
/tmp/tmpu49tvvao1Warp.nii.gz
/tmp/tmphs2lqlh_0GenericAffine.mat
/tmp/tmpsu8n32ml1Warp.nii.gz
/tmp/tmpzna7lwiy0GenericAffine.mat
/tmp/tmptkfaptjx0GenericAffine.mat
/tmp/tmphsql8njm1InverseWarp.nii.gz
/tmp/tmpxxp5jxid1Warp.nii.gz
/tmp/tmp423nwa4l1InverseWarp.nii.gz
/tmp/tmp7c30zdvb1InverseWarp.nii.gz
/tmp/.Test-unix
/tmp/tmp5iyh4mce0GenericAffine.mat
/tmp/.font-unix
/tmp/tmp7zr5nmc91Warp.nii.gz
/tmp/tmpscurinxj0GenericAffine.mat
/tmp/tmp0p486fke1Warp.nii.gz
/tmp/tmpl22reg7q1InverseWarp.nii.gz
/tmp/tmp6olffh461InverseWarp.nii.gz
/tmp/tmpqip8xo3b1InverseWarp.nii.gz
/tmp/tmppcgfw04u.py
/tmp/tmp2303poln0GenericAffine.mat

@ntustison
Copy link
Member

Use the outprefix option in ants.registration to save to a known directory and delete the files when no longer needed.

@Jose-Verdu-Diaz
Copy link

Fixed.

@stnava I'm having a similar issue when performing image registration on batches of images. Memory usage builds up until running out. Could you expand on how this was fixed, or what was the actual problem?

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

5 participants