mindee / doctr

docTR (Document Text Recognition) - a seamless, high-performing & accessible library for OCR-related tasks powered by Deep Learning.
https://mindee.github.io/doctr/
Apache License 2.0
3.31k stars 397 forks source link

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

Closed helpmefindaname closed 1 month ago

helpmefindaname commented 1 month ago

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.

felixdittrich92 commented 1 month ago

Hi @helpmefindaname :wave:,

Tanks for the fix good catch :+1:

felixdittrich92 commented 1 month ago

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

codecov[bot] commented 1 month ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

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

Additional details and impacted files ```diff @@ 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](https://app.codecov.io/gh/mindee/doctr/pull/1598/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mindee) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/mindee/doctr/pull/1598/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mindee) | `96.30% <100.00%> (+0.01%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mindee#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.