PyTorch 在 Detectron2LayoutModel() 上抛出 OSError

PyTorch throws OSError on Detectron2LayoutModel()

为了提取目的,我一直在尝试将 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 文件。不幸的是,问题仍然存在。

如果有解决方案或替代建议(如果存在),我将不胜感激。

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

您要找的人 mask_rcnn_X_101_32x8d_FPN_3xPubLayNet 上接受过培训。下载 yaml 文件后,您可以使用相同的代码片段,只是更改路径。

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

我发现解决方案是将 tesseract.exe 的 congif 路径添加到 pytesseract_cmd for 运行 CLI behind on jupyter:

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

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

参考了这个话题