Skip to content

How to manually release memory of Image after data was loaded? #525

Answered by fepegar
alabamagan asked this question in Q&A
Discussion options

You must be logged in to vote

Hi, @alabamagan.

This is probably because instances in a and b are repeated, so even if you delete them with del, you will still be keeping a pointer to them in one of the lists and memory will not be released. A possible solution is iterating over SubjectsDataset, which makes copies of the subjects. Then, maybe you can use the path of the image or the tensor data to compare two images.

import torchio as tio
subjects = [tio.Subject(im=im) for im in im_list]
dataset = tio.SubjectsDataset(subjects)
for sub1 in dataset:
    for sub2 in dataset:
        if compare(sub1.im, sub2.im):
            do_sth()

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@alabamagan
Comment options

Answer selected by fepegar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants