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

[Fix] close PIL images when loading images to tensor/numpy #1598

Merged

Conversation

helpmefindaname
Copy link
Contributor

The previous behavior opened PIL images, but didn't release their memory, causing a huge memory leak on our training pipeline.
With this PR, the PIL images will be closed immediately after the copy as numpy array or torch tensor is created.

@helpmefindaname helpmefindaname changed the title close PIL images when loading images to tensor/numpy [FIX] close PIL images when loading images to tensor/numpy May 15, 2024
@helpmefindaname helpmefindaname changed the title [FIX] close PIL images when loading images to tensor/numpy [Fix] close PIL images when loading images to tensor/numpy May 15, 2024
@felixdittrich92
Copy link
Contributor

Hi @helpmefindaname 👋,

Tanks for the fix good catch 👍

@felixdittrich92 felixdittrich92 added this to the 0.9.0 milestone May 15, 2024
@felixdittrich92 felixdittrich92 added type: bug Something isn't working module: io Related to doctr.io labels May 15, 2024
@felixdittrich92
Copy link
Contributor

failing build / script jobs are expected atm so don't wonder 😅

@felixdittrich92 felixdittrich92 self-requested a review May 15, 2024 15:44
@felixdittrich92 felixdittrich92 self-assigned this May 15, 2024
Copy link

codecov bot commented May 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.30%. Comparing base (3f116ad) to head (4dd46c2).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1598      +/-   ##
==========================================
+ Coverage   96.28%   96.30%   +0.01%     
==========================================
  Files         163      163              
  Lines        7706     7707       +1     
==========================================
+ Hits         7420     7422       +2     
+ Misses        286      285       -1     
Flag Coverage Δ
unittests 96.30% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@felixdittrich92 felixdittrich92 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix lgtm 👍

@odulcy-mindee odulcy-mindee merged commit 45c2df3 into mindee:main May 15, 2024
74 of 81 checks passed
@helpmefindaname helpmefindaname deleted the fix-memory-leak-on-pil-loading branch May 16, 2024 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module: io Related to doctr.io type: bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants