【问题标题】:PyTorch throws OSError on Detectron2LayoutModel()PyTorch 在 Detectron2LayoutModel() 上抛出 OSError
【发布时间】:2021-06-23 06:54:05
【问题描述】:

出于提取目的,我一直在尝试将 pdf 页面作为图像读取。

我发现 layoutparser 通过识别文本块来达到这个目的。但是,当我尝试Create a Detectron2-based Layout Detection Model 时,遇到以下错误:

代码块:

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

错误:

OSError                                   Traceback (most recent call last)
<ipython-input-16-893fdc4d537c> in <module>
      2             config_path ='lp://PubLayNet/mask_rcnn_X_101_32x8d_FPN_3x/config', 
      3             label_map   = {0: "Text", 1: "Title", 2: "List", 3:"Table", 4:"Figure"}, 
----> 4             extra_config=["MODEL.ROI_HEADS.SCORE_THRESH_TEST", 0.8] 
      5         )
      6 
.
.
.
d:\softwares\python3\lib\site-packages\portalocker\utils.py in _get_fh(self)
    269     def _get_fh(self) -> typing.IO:
    270         '''Get a new filehandle'''
--> 271         return open(self.filename, self.mode, **self.file_open_kwargs)
    272 
    273     def _get_lock(self, fh: typing.IO) -> typing.IO:

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

我检查了目标路径文件夹,令人惊讶的是,没有config.yaml 文件,这可能是出现错误的原因。我尝试卸载并重新安装 PyTorch,希望 .yaml 文件能够正确安装。不幸的是,问题仍然存在。

如果有此问题的解决方案或替代建议,我将不胜感激。

【问题讨论】:

    标签: python python-3.x opencv deep-learning pytorch


    【解决方案1】:

    config.yaml 基本上只有模型的配置以及下载模型权重的 URL。我不知道为什么它没有自动为你下载,但你也可以从模型动物园页面下载它们:https://layout-parser.readthedocs.io/en/latest/notes/modelzoo.html

    您正在寻找的是在 PubLayNet 上训练的 mask_rcnn_X_101_32x8d_FPN_3x。一旦你下载了yaml文件,你就可以使用相同的代码sn-p,只是改变路径。

    model = lp.Detectron2LayoutModel(config_path='path/to/config.yaml', ...)
    

    【讨论】:

      【解决方案2】:

      我找到了解决方案,将 tesseract.exe 的 congif 路径添加到 pytesseract_cmd 以在 jupyter 上运行 CLI:

      pytesseract.pytesseract.tesseract_cmd = r'path\to\folder\Tesseract_OCR\tesseract.exe'
      

      然后调用 Detectron2Model 没有抛出错误。

      参考了这个话题Pytesseract : “TesseractNotFound Error: tesseract is not installed or it's not in your path”, how do I fix this?

      【讨论】:

        猜你喜欢
        • 2022-06-21
        • 2020-11-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-05-04
        • 1970-01-01
        • 2021-05-23
        相关资源
        最近更新 更多