You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Detectron2LayoutModel遇model_final.pth缺失错误,求解决建议

解决Detectron2LayoutModel的两类报错问题

第一类报错:PIL.Image.LINEAR no longer exists

该错误源于detectron2 v0.5版本与新版PIL库不兼容——PIL.Image.LINEAR已被重命名为PIL.Image.Resampling.LINEAR。你更换指定commit的思路可行,但后续出现了模型文件缺失问题,以下重点解决第二类报错。

第二类报错:AssertionError: Checkpoint /root/.torch/iopath_cache/s/6icw6at8m28a2ho/model_final.pth not found!

此错误是因为lp://HJDataset/faster_rcnn_R_50_FPN_3x/config对应的预训练权重未成功下载到本地缓存目录,或缓存路径存在权限/结构问题,可按以下方案解决:

  • 手动下载并放置模型权重
    获取HJDataset对应faster_rcnn_R_50_FPN_3x的预训练权重文件model_final.pth,将其放到错误提示的路径/root/.torch/iopath_cache/s/6icw6at8m28a2ho/中。若该路径不存在,手动创建完整目录结构。

  • 修复缓存目录权限
    确保缓存目录具备读写权限,执行命令:

    chmod -R 755 /root/.torch/iopath_cache/
    
  • 直接指定本地模型路径初始化
    若自动加载远程模型始终失败,跳过远程加载流程,直接用本地文件初始化模型:

    import layoutparser as lp
    model = lp.Detectron2LayoutModel(
        config_path="/path/to/your/config.yaml",
        model_path="/path/to/your/model_final.pth",
        label_map={0: "text", 1: "title", 2: "list", 3: "table", 4: "figure"} # HJDataset标准标签映射
    )
    
  • 验证detectron2版本兼容性
    尝试切换到detectron2 v0.6版本,该版本已修复PIL API兼容问题,同时可能更好适配HJDataset模型:

    pip uninstall -y detectron2
    pip install 'detectron2@git+https://github.com/facebookresearch/detectron2.git@v0.6'
    

内容的提问来源于stack exchange,提问作者Zachary Burton

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 17:38:36