I am trying out layout-parser api from
https://layout-parser.readthedocs.io/en/latest/notes/modelzoo.html#example-usage
My detectron2 installation is quite successful as evident from running python -m detectron2.utils.collect_env
So is my torch installation by running pip3 show torch
I have created a first sample as below
import layoutparser as lp
import cv2
image = cv2.imread("data/test-image.jpeg")
image = image[..., ::-1]
model = lp.models.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)
Running the above with python3 sample-first.py
throws an error
Traceback (most recent call last):
File "/Users/_dga/ml-git/layout-parser-trial/sample-first.py", line 6, in <module>
model = lp.models.Detectron2LayoutModel(
File "/Users/_dga/Library/Python/3.9/lib/python/site-packages/layoutparser/models/layoutmodel.py", line 124, in __init__
self._create_model()
File "/Users/_dga/Library/Python/3.9/lib/python/site-packages/layoutparser/models/layoutmodel.py", line 149, in _create_model
self.model = self._engine.DefaultPredictor(self.cfg)
File "/Users/_dga/ml-git/detectron2/detectron2/engine/defaults.py", line 288, in __init__
checkpointer.load(cfg.MODEL.WEIGHTS)
File "/Users/_dga/ml-git/detectron2/detectron2/checkpoint/detection_checkpoint.py", line 62, in load
ret = super().load(path, *args, **kwargs)
File "/Users/_dga/Library/Python/3.9/lib/python/site-packages/fvcore/common/checkpoint.py", line 155, in load
checkpoint = self._load_file(path)
File "/Users/_dga/ml-git/detectron2/detectron2/checkpoint/detection_checkpoint.py", line 99, in _load_file
loaded = self._torch_load(filename)
File "/Users/_dga/ml-git/detectron2/detectron2/checkpoint/detection_checkpoint.py", line 114, in _torch_load
return super()._load_file(f)
File "/Users/_dga/Library/Python/3.9/lib/python/site-packages/fvcore/common/checkpoint.py", line 252, in _load_file
return torch.load(f, map_location=torch.device("cpu"))
File "/Users/_dga/Library/Python/3.9/lib/python/site-packages/torch/serialization.py", line 815, in load
return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args)
File "/Users/_dga/Library/Python/3.9/lib/python/site-packages/torch/serialization.py", line 1033, in _legacy_load
magic_number = pickle_module.load(f, **pickle_load_args)
_pickle.UnpicklingError: invalid load key, '<'.
It seems to be coming from torch and I am guessing its unable to load the model in question.
I am using MAC M2 with python3.9 for the whole exercise.
After some research on chatgpt and google, I downgraded my detectron2 to 0.5 from 0.6 and have a new issue
Traceback (most recent call last):
File "/Users/_dga/ml-git/layout-parser-trial/sample-first.py", line 6, in <module>
model = lp.models.Detectron2LayoutModel(
File "/Users/_dga/Library/Python/3.9/lib/python/site-packages/layoutparser/models/layoutmodel.py", line 52, in __new__
cls._import_module()
File "/Users/_dga/Library/Python/3.9/lib/python/site-packages/layoutparser/models/layoutmodel.py", line 40, in _import_module
cls, m["import_name"], importlib.import_module(m["module_path"])
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 850, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "/Users/_dga/Library/Python/3.9/lib/python/site-packages/detectron2/engine/__init__.py", line 11, in <module>
from .hooks import *
File "/Users/_dga/Library/Python/3.9/lib/python/site-packages/detectron2/engine/hooks.py", line 19, in <module>
from detectron2.evaluation.testing import flatten_results_dict
File "/Users/_dga/Library/Python/3.9/lib/python/site-packages/detectron2/evaluation/__init__.py", line 2, in <module>
from .cityscapes_evaluation import CityscapesInstanceEvaluator, CityscapesSemSegEvaluator
File "/Users/_dga/Library/Python/3.9/lib/python/site-packages/detectron2/evaluation/cityscapes_evaluation.py", line 11, in <module>
from detectron2.data import MetadataCatalog
File "/Users/_dga/Library/Python/3.9/lib/python/site-packages/detectron2/data/__init__.py", line 2, in <module>
from . import transforms # isort:skip
File "/Users/_dga/Library/Python/3.9/lib/python/site-packages/detectron2/data/transforms/__init__.py", line 4, in <module>
from .transform import *
File "/Users/_dga/Library/Python/3.9/lib/python/site-packages/detectron2/data/transforms/transform.py", line 36, in <module>
class ExtentTransform(Transform):
File "/Users/_dga/Library/Python/3.9/lib/python/site-packages/detectron2/data/transforms/transform.py", line 46, in ExtentTransform
def __init__(self, src_rect, output_size, interp=Image.LINEAR, fill=0):
AttributeError: module 'PIL.Image' has no attribute 'LINEAR'