Layout-Parser / layout-parser

A Unified Toolkit for Deep Learning Based Document Image Analysis
https://layout-parser.github.io/
Apache License 2.0
4.67k stars 449 forks source link

ImportError: cannot import name 'is_directory' from 'PIL._util' (/usr/local/lib/python3.7/dist-packages/PIL/_util.py) #154

Closed arhamshah closed 1 year ago

arhamshah commented 1 year ago

While using this code, I get this error of Pillow. I tried re-installing pillow but still struggling with this issue. Any help to make this code run?

import layoutparser as lp
model = lp.Detectron2LayoutModel(
            config_path ='lp://PubLayNet/faster_rcnn_R_50_FPN_3x/config', # In model catalog
            label_map   ={0: "Text", 1: "Title", 2: "List", 3:"Table", 4:"Figure"}, # In model`label_map`
            extra_config=["MODEL.ROI_HEADS.SCORE_THRESH_TEST", 0.8] # Optional
        )
model.detect(image)

Getting this error:

ImportError                               Traceback (most recent call last)
[<ipython-input-6-59f0fb07b7e3>](https://localhost:8080/#) in <module>
      1 import layoutparser as lp
----> 2 model = lp.Detectron2LayoutModel(
      3             config_path ='lp://PubLayNet/faster_rcnn_R_50_FPN_3x/config', # In model catalog
      4             label_map   ={0: "Text", 1: "Title", 2: "List", 3:"Table", 4:"Figure"}, # In model`label_map`
      5             extra_config=["MODEL.ROI_HEADS.SCORE_THRESH_TEST", 0.8] # Optional

31 frames
[/usr/local/lib/python3.7/dist-packages/PIL/ImageFont.py](https://localhost:8080/#) in <module>
     35 from . import Image
     36 from ._deprecate import deprecate
---> 37 from ._util import is_directory, is_path
     38 
     39 

ImportError: cannot import name 'is_directory' from 'PIL._util' (/usr/local/lib/python3.7/dist-packages/PIL/_util.py)
MarouaneZ1 commented 1 year ago

i got the same problem while using Detectron2LayoutModel on google collab, did you fix it yet ?

arhamshah commented 1 year ago

I solved by uninstalling the latest pillow version and instead installed pillow of version 7.1.2 !pip install pillow==7.1.2

MarouaneZ1 commented 1 year ago

I solved by uninstalling the latest pillow version and instead installed pillow of version 7.1.2 !pip install pillow==7.1.2

i just did what you told me and it worked thank you very much brother

NUSTHR commented 3 months ago

It works. Thank you a lot