python - 调用 Detectron2LayoutModel 时出现 OSError

标签 python deep-learning pytorch oserror

在 Windows 中成功安装布局解析器后,出现以下操作系统错误。

使用的代码:

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'

不确定它是一种锁还是什么。

请帮忙

最佳答案

即使我也遇到了类似的错误。我在 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 解决方法][1]

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

关于python - 调用 Detectron2LayoutModel 时出现 OSError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71483333/

相关文章:

python - 导入 Google 联系人库时出错?

python GIL : is django save() blocking?

python - Keras 2 上具有自定义(无)损失的三元组嵌入层

python - 应使用 `device` 或将字符串作为参数传递来设置 `torch.device` 参数

machine-learning - pytorch 中的梯度裁剪没有效果(梯度爆炸仍然发生)

python - 如何在 Pipfile 中指定操作系统特定的 wheel 文件

python - 如果我的 JSON 数据被读取为列表而不是 Python 字典,可以吗?

python - 有人在他们的生产工具中使用 DjVu 文件吗?

python - 是否可以在 keras 中实现动态类权重?

python - 使用 Python 3 卡住 TensorFlow 中 Inception V3 的部分层