'OSError while calling Detectron2LayoutModel

After successfully installing Layout Parser in Windows, getting the below OS Error.

Code Used:

model = lp.Detectron2LayoutModel(config_path="lp://PubLayNet/mask_rcnn_X_101_32x8d_FPN_3x/config", 
                                 extra_config=["MODEL.ROI_HEADS.SCORE_THRESH_TEST", 0.8],
                                 label_map={0: "Text", 1: "Title", 2: "List", 3:"Table", 4:"Figure"})

Using layout parser, trying to extract the content from image. But when I try to load models in Layout parser, it fails with the below error

---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_178664\3254664512.py in <module>
      1 model = lp.Detectron2LayoutModel(config_path="lp://PubLayNet/mask_rcnn_X_101_32x8d_FPN_3x/config", 
      2                                  extra_config=["MODEL.ROI_HEADS.SCORE_THRESH_TEST", 0.8],
----> 3                                  label_map={0: "Text", 1: "Title", 2: "List", 3:"Table", 4:"Figure"})
      4     # Load the deep layout model from the layoutparser API
      5     # For all the supported model, please check the Model

~\Anaconda3\envs\layout\lib\site-packages\layoutparser\models\detectron2\layoutmodel.py in __init__(self, config_path, model_path, label_map, extra_config, enforce_cpu, device)
     89             config_path, model_path, allow_empty_path=True
     90         )
---> 91         config_path = PathManager.get_local_path(config_path)
     92 
     93         if label_map is None:

~\Anaconda3\envs\layout\lib\site-packages\iopath\common\file_io.py in get_local_path(self, path, force, **kwargs)
   1195         handler = self.__get_path_handler(path)  # type: ignore
   1196         try:
-> 1197             bret = handler._get_local_path(path, force=force, **kwargs)
   1198         except TypeError:
   1199             bret = handler._get_local_path(path, **kwargs)

~\Anaconda3\envs\layout\lib\site-packages\layoutparser\models\detectron2\catalog.py in _get_local_path(self, path, **kwargs)
    134         else:
    135             raise ValueError(f"Unknown data_type {data_type}")
--> 136         return PathManager.get_local_path(model_url, **kwargs)
    137 
    138     def _open(self, path, mode="r", **kwargs):

~\Anaconda3\envs\layout\lib\site-packages\iopath\common\file_io.py in get_local_path(self, path, force, **kwargs)
   1195         handler = self.__get_path_handler(path)  # type: ignore
   1196         try:
-> 1197             bret = handler._get_local_path(path, force=force, **kwargs)
   1198         except TypeError:
   1199             bret = handler._get_local_path(path, **kwargs)

~\Anaconda3\envs\layout\lib\site-packages\iopath\common\file_io.py in _get_local_path(self, path, force, cache_dir, **kwargs)
    792 
    793             cached = os.path.join(dirname, filename)
--> 794             with file_lock(cached):
    795                 if not os.path.isfile(cached):
    796                     logger.info("Downloading {} ...".format(path))

~\Anaconda3\envs\layout\lib\site-packages\portalocker\utils.py in __enter__(self)
    155 
    156     def __enter__(self):
--> 157         return self.acquire()
    158 
    159     def __exit__(self,

~\Anaconda3\envs\layout\lib\site-packages\portalocker\utils.py in acquire(self, timeout, check_interval, fail_when_locked)
    237 
    238         # Get a new filehandler
--> 239         fh = self._get_fh()
    240 
    241         def try_close():  # pragma: no cover

~\Anaconda3\envs\layout\lib\site-packages\portalocker\utils.py in _get_fh(self)
    287     def _get_fh(self) -> typing.IO:
    288         '''Get a new filehandle'''
--> 289         return open(self.filename, self.mode, **self.file_open_kwargs)
    290 
    291     def _get_lock(self, fh: typing.IO) -> typing.IO:

OSError: [Errno 22] Invalid argument: 'C:\\Users\\vchinna/.torch/iopath_cache\\s/nau5ut6zgthunil\\config.yaml?dl=1.lock'

Not sure whether it is a kind of lock or something.

Please help



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source