AttributeError: module 'PIL.Image' has no attribute 'Resampling'

4.1k views Asked by At

While implementing "layoutparser" I get this error. What is wrong with this?

model = lp.Detectron2LayoutModel('lp://PubLayNet/mask_rcnn_X_101_32x8d_FPN_3x/config',
                                 extra_config=["MODEL.ROI_HEADS.SCORE_THRESH_TEST", 0.5],
                                 label_map={0: "Text", 1: "Title", 2: "List", 3:"Table", 4:"Figure"})
AttributeError                            Traceback (most recent call last)
<ipython-input-8-d8a245fa8739> in <module>()
----> 1 model = lp.Detectron2LayoutModel('lp://PubLayNet/mask_rcnn_X_101_32x8d_FPN_3x/config',
      2                                  extra_config=["MODEL.ROI_HEADS.SCORE_THRESH_TEST", 0.5],
      3                                  label_map={0: "Text", 1: "Title", 2: "List", 3:"Table", 4:"Figure"}) 34 frames /usr/local/lib/python3.7/dist-packages/PIL/Image.py in
__getattr__(name)
     63             stacklevel=2,
     64         )
---> 65         return categories[name]
     66     elif name in ("NEAREST", "NONE"):
     67         warnings.warn( AttributeError: module 'PIL.Image' has no attribute 'Resampling'
2

There are 2 answers

0
YScharf On

Convert image to numpy array.

import numpy as np

image = np.asarray(image)

model.detect(image)
0
Rohan Mahale On

If you are using Colab tool then this error might occur if your code is using GPU but your Colab is configured with CPU version.

Runtime --> Change Runtime Type --> Select "GPU"