doctr icon indicating copy to clipboard operation
doctr copied to clipboard

-> Cannot close object, library is destroyed. This may cause a memory leak!

Open marcobornstein opened this issue 11 months ago • 3 comments

Bug description

I'm trying to run an example of doctr on my M1 Mac. Code is shown farther below.

Code snippet to reproduce the bug

from doctr.io import DocumentFile
from doctr.models import ocr_predictor
import os
# Let's pick the desired backend
os.environ['USE_TORCH'] = '1'

if __name__ == "__main__":

    model = ocr_predictor(pretrained=True)

    # PDF
    doc = DocumentFile.from_pdf("marco-test-2.pdf")

    # Analyze
    result = model(doc)
    # result.show(doc)

Error traceback

`-> Cannot close object, library is destroyed. This may cause a memory leak!`

Environment

DocTR version: v0.7.0 TensorFlow version: N/A PyTorch version: 2.2.0 (torchvision 0.17.0) OpenCV version: 4.9.0 OS: Mac OSX 14.3 Python version: 3.11.8 Is CUDA available (TensorFlow): N/A Is CUDA available (PyTorch): No CUDA runtime version: Could not collect GPU models and configuration: Could not collect Nvidia driver version: Could not collect cuDNN version: Could not collect

Deep Learning backend

print(f"is_tf_available: {is_tf_available()}") is_tf_available: False print(f"is_torch_available: {is_torch_available()}") is_torch_available: True

marcobornstein avatar Feb 28 '24 03:02 marcobornstein

Hi @marcobornstein :wave:,

Could you please check if this also happens with images ?

felixdittrich92 avatar Feb 28 '24 09:02 felixdittrich92

Yes, it was not working still for images. However I found that result.synthesize() worked as expected. For example, this code snippet worked:

model = ocr_predictor(pretrained=True)

# PDF
doc = DocumentFile.from_pdf("marco-test-2.pdf")

# Analyze
result = model(doc)
synthetic_pages = result.synthesize()
plt.imshow(synthetic_pages[0]);
plt.axis('off');
plt.show()

marcobornstein avatar Feb 28 '24 15:02 marcobornstein

@marcobornstein Mh the error disappeared ?

BTW: .show(doc) is now .show()

felixdittrich92 avatar Feb 28 '24 15:02 felixdittrich92

Seems to be solved -> Feel free to reopen if not :)

felixdittrich92 avatar Mar 16 '24 18:03 felixdittrich92