【问题标题】:OSError while calling Detectron2LayoutModel调用 Detectron2LayoutModel 时出现 OSError
【发布时间】:2022-06-21 17:16:39
【问题描述】:

在 Windows 中成功安装 Layout Parser 后,出现以下操作系统错误。

使用的代码:

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"})

使用布局解析器,尝试从图像中提取内容。但是当我尝试在布局解析器中加载模型时,它会失败并出现以下错误

---------------------------------------------------------------------------
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'

不确定是锁还是什么的。

请帮忙

【问题讨论】:

  • 你能找到解决办法吗?

标签: python deep-learning pytorch oserror


【解决方案1】:

即使我也遇到了类似的错误。我在 Windows 中手动尝试了一些解决方法。

我以您的情况为例:OSError: [Errno 22] Invalid argument: 'C:\Users\vchinna/.torch/iopath_cache\s/nau5ut6zgthunil\config.yaml?dl=1.lock'

请遵循以下流程。

  1. 导航到 C:\Users\vchinna/.torch/iopath_cache\s/nau5ut6zgthunil\config.yaml 打开那个 config.yaml 文件

  2. 向下滚动到权重:https://www.dropbox.com/s/h7th27jfv19rxiy/model_final.pth?dl=1 应该在 265 行左右。

  3. 复制该链接并将其粘贴到浏览器中,将下载“model_final.pth”。将此文件复制到所需的文件夹。

  4. 现在替换 WEIGHTS 的路径:your_desired_folder/model_final.pth

  5. 保存并运行代码!

但是在你这样做之前我认为有一个小工作(如果你还没有这样做的话) iopath work around

https://github.com/Layout-Parser/layout-parser/issues/15(问题的 Github 链接)

希望这会有所帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-20
    • 1970-01-01
    • 2016-02-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多