Skip to content

fix(ocr): 兼容 rapidocr 3.9.0,显式传字符串 model_root_dir 规避 omegaconf 异常 - #952

Merged
wess09 merged 1 commit into
wess09:dev_frontendfrom
lightment:pr-ocr-390
Sep 16, 2026
Merged

wess09 merged 1 commit into
wess09:dev_frontendfrom
lightment:pr-ocr-390

Conversation

@lightment

@lightment lightment commented Sep 16, 2026

Copy link
Copy Markdown

背景

dev_frontenduv.lock 锁定 rapidocr == 3.9.0。rapidocr 3.9.0 的 _load_configmodel_root_dirNone 时,会把全局配置 Global.model_root_dir 赋值为一个 Path 对象,而 omegaconf 不支持 Path 类型,抛 UnsupportedValueType 异常,导致 OCR 模型首次加载即崩溃。

在 AzurPilot 中,任意任务触发 OCR(如科研余量识别、奖励领取等)都会走到 ALAS 的重启流程,表现为任务反复自动重启客户端。

修复

module/ocr/al_ocr.py 的三处参数入口显式传入字符串 Global.model_root_dir: os.getcwd(),绕过 rapidocr 3.9.0 在 model_root_dir=None 时写入 Path 的分支:

  • _create_ocr()(RecOnlyOCR,识别用)
  • _create_det_ocr_for_onnx()(DetOnlyOCR,onnx 后端)
  • _create_det_ocr_for_ncnn()(DetOnlyOCR,ncnn 后端)

这样 omegaconf 只会收到字符串,不会再触发 UnsupportedValueType

测试说明(已实测通过)

  1. 加载验证:在本机环境执行

    from module.ocr.al_ocr import _create_ocr
    ocr = _create_ocr('azur_lane')

    修复前抛 UnsupportedValueType,修复后成功创建 RecOnlyOCR 实例,模型正常加载。

  2. 运行验证:运行科研任务(领取队列余量触发 OCR),修复前触发 ALAS 自动重启,修复连续运行不再崩溃、不再重启客户端。

  3. 影响面:三处构造点(RecOnlyOCR / DetOnlyOCR onnx / ncnn)统一规避;改为字符串不会改变模型路径解析行为,仅阻止 rapidocr 把 Path 塞进 omegaconf。

备注

rapidocr 3.9.2 已从上游改写为缓存路径(不再写 Path),但本仓库锁定的是 3.9.0,因此在现有锁定版本下该补丁是必要的。

Summary by Sourcery

兼容 rapidocr 3.9.0 的 OCR 模型加载,防止任务执行过程中因配置类型异常导致客户端崩溃重启。

Bug Fixes:

  • 修复 rapidocr 3.9.0 加载 OCR 模型时因路径类型不兼容导致的初始化崩溃,避免相关任务触发客户端反复重启。

Enhancements:

  • 统一为识别及 ONNX、NCNN 检测 OCR 构造流程提供兼容的模型根目录配置。
Original summary in English

Summary by Sourcery

兼容 rapidocr 3.9.0 的 OCR 模型加载,防止任务执行过程中因配置类型异常导致客户端崩溃重启。

Bug Fixes:

  • 修复 rapidocr 3.9.0 加载 OCR 模型时因路径类型不兼容导致的初始化崩溃,避免相关任务触发客户端反复重启。

Enhancements:

  • 统一为识别及 ONNX、NCNN 检测 OCR 构造流程提供兼容的模型根目录配置。

rapidocr 3.9.0 的 _load_config 在 model_root_dir 为 None 时会写入 Path
对象,omegaconf 不支持而抛 UnsupportedValueType,导致 OCR 模型加载失败、
任务反复自动重启游戏。在 _create_ocr/_create_det_ocr_for_onnx/
_create_det_ocr_for_ncnn 三处 params 显式传入字符串规避。
@github-actions

github-actions Bot commented Sep 16, 2026

Copy link
Copy Markdown

CI 检查报告

检查结果

检查 结果 耗时
Post PR report ➖ unknown -

导入冒烟测试

  • 结果:❌
  • 扫描模块:506(通过 450,已知失败 3,意外失败 53,过期白名单 0)

意外失败:

  • module.auto_equip.auto_equip:ModuleNotFoundError: No module named 'pkg_resources'
  • module.awaken.awaken:ModuleNotFoundError: No module named 'pkg_resources'
  • module.base.debug_clip:ModuleNotFoundError: No module named 'pkg_resources'
  • module.device.app_control:ModuleNotFoundError: No module named 'pkg_resources'
  • module.device.connection:ModuleNotFoundError: No module named 'pkg_resources'
  • module.device.connection_attr:ModuleNotFoundError: No module named 'pkg_resources'
  • module.device.control:ModuleNotFoundError: No module named 'pkg_resources'
  • module.device.input:ModuleNotFoundError: No module named 'pkg_resources'
  • module.device.method.adb:ModuleNotFoundError: No module named 'pkg_resources'
  • module.device.method.ascreencap:ModuleNotFoundError: No module named 'pkg_resources'

@sourcery-ai

sourcery-ai Bot commented Sep 16, 2026

Copy link
Copy Markdown
审查者指南(小型 PR 中折叠显示)

审查者指南

针对锁定的 rapidocr 3.9.0,在三个 OCR 实例化入口显式传入字符串模型根目录,避免其默认写入 Path 导致 OmegaConf 抛出 UnsupportedValueType,从而修复 OCR 首次加载崩溃及相关任务触发客户端反复重启的问题。

OCR 模型初始化兼容性修复时序图

sequenceDiagram
    participant Task as OCRTask
    participant Factory as al_ocr
    participant RapidOCR as rapidocr_3_9_0
    participant OmegaConf as OmegaConf

    Task->>Factory: _create_ocr(name)
    Factory->>RapidOCR: Create OCR with Global.model_root_dir=os.getcwd()
    RapidOCR->>OmegaConf: _load_config(model_root_dir=string)
    OmegaConf-->>RapidOCR: Configuration accepted
    RapidOCR-->>Factory: RecOnlyOCR instance
    Factory-->>Task: OCR ready

    alt DetOnlyOCR backend
        Task->>Factory: _create_det_ocr_for_onnx(name) or _create_det_ocr_for_ncnn()
        Factory->>RapidOCR: Create detector with Global.model_root_dir=os.getcwd()
        RapidOCR->>OmegaConf: _load_config(model_root_dir=string)
        OmegaConf-->>RapidOCR: Configuration accepted
        RapidOCR-->>Factory: DetOnlyOCR instance
    end
Loading

防止 OCR 初始化崩溃流程图

flowchart LR
    A[OCR instance creation] --> B["Pass Global.model_root_dir=os.getcwd()"]
    B --> C[rapidocr 3.9.0 _load_config]
    C --> D[OmegaConf receives a string]
    D --> E[Model loads successfully]
    E --> F[OCR task continues without client restart]
Loading

文件级变更

变更 详细信息 文件
为所有 RapidOCR 构造入口显式设置字符串形式的模型根目录,规避 rapidocr 3.9.0 与 OmegaConf 的 Path 类型兼容性问题。
  • 在识别 OCR 构造参数中加入 Global.model_root_dir: os.getcwd()
  • 在 ONNX 和 NCNN 检测 OCR 构造参数中统一加入相同配置。
  • 覆盖 RecOnlyOCR 及两种后端的 DetOnlyOCR,保持原有模型路径解析行为不变。
module/ocr/al_ocr.py

提示和命令

与 Sourcery 交互

  • 触发新的审查: 在拉取请求中评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审查评论。
  • 根据审查评论生成 GitHub issue: 回复审查评论,请 Sourcery 根据该评论创建 issue。你也可以使用 @sourcery-ai issue 回复审查评论,以根据该评论创建 issue。
  • 生成拉取请求标题: 在拉取请求标题的任意位置写入 @sourcery-ai,即可随时生成标题。你也可以在拉取请求中评论 @sourcery-ai title,以随时生成或重新生成标题。
  • 生成拉取请求摘要: 在拉取请求正文中你希望摘要出现的位置写入 @sourcery-ai summary,即可随时在指定位置生成 PR 摘要。你也可以在拉取请求中评论 @sourcery-ai summary,以随时生成或重新生成摘要。
  • 生成审查者指南: 在拉取请求中评论 @sourcery-ai guide,即可随时生成或重新生成审查者指南。
  • 解决所有 Sourcery 评论: 在拉取请求中评论 @sourcery-ai resolve,以解决所有 Sourcery 评论。如果你已经处理完所有评论且不想再看到它们,这会很有用。
  • 忽略所有 Sourcery 审查: 在拉取请求中评论 @sourcery-ai dismiss,以忽略所有现有的 Sourcery 审查。如果你想从新的审查开始,这尤其有用——别忘了评论 @sourcery-ai review 来触发新的审查!

自定义使用体验

访问你的控制面板以:

  • 启用或禁用审查功能,例如 Sourcery 生成的拉取请求摘要、审查者指南等。
  • 更改审查语言。
  • 添加、删除或编辑自定义审查说明。
  • 调整其他审查设置。

获取帮助

Original review guide in English
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

针对锁定的 rapidocr 3.9.0,在三个 OCR 实例化入口显式传入字符串模型根目录,避免其默认写入 Path 导致 OmegaConf 抛出 UnsupportedValueType,从而修复 OCR 首次加载崩溃及相关任务触发客户端反复重启的问题。

Sequence diagram for OCR model initialization compatibility fix

sequenceDiagram
    participant Task as OCRTask
    participant Factory as al_ocr
    participant RapidOCR as rapidocr_3_9_0
    participant OmegaConf as OmegaConf

    Task->>Factory: _create_ocr(name)
    Factory->>RapidOCR: Create OCR with Global.model_root_dir=os.getcwd()
    RapidOCR->>OmegaConf: _load_config(model_root_dir=string)
    OmegaConf-->>RapidOCR: Configuration accepted
    RapidOCR-->>Factory: RecOnlyOCR instance
    Factory-->>Task: OCR ready

    alt DetOnlyOCR backend
        Task->>Factory: _create_det_ocr_for_onnx(name) or _create_det_ocr_for_ncnn()
        Factory->>RapidOCR: Create detector with Global.model_root_dir=os.getcwd()
        RapidOCR->>OmegaConf: _load_config(model_root_dir=string)
        OmegaConf-->>RapidOCR: Configuration accepted
        RapidOCR-->>Factory: DetOnlyOCR instance
    end
Loading

Flow diagram for preventing the OCR initialization crash

flowchart LR
    A[OCR instance creation] --> B["Pass Global.model_root_dir=os.getcwd()"]
    B --> C[rapidocr 3.9.0 _load_config]
    C --> D[OmegaConf receives a string]
    D --> E[Model loads successfully]
    E --> F[OCR task continues without client restart]
Loading

File-Level Changes

Change Details Files
为所有 RapidOCR 构造入口显式设置字符串形式的模型根目录,规避 rapidocr 3.9.0 与 OmegaConf 的 Path 类型兼容性问题。
  • 在识别 OCR 构造参数中加入 Global.model_root_dir: os.getcwd()
  • 在 ONNX 和 NCNN 检测 OCR 构造参数中统一加入相同配置。
  • 覆盖 RecOnlyOCR 及两种后端的 DetOnlyOCR,保持原有模型路径解析行为不变。
module/ocr/al_ocr.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你好——我已经审阅了你的更改,看起来很棒!


Sourcery 对开源项目免费——如果你喜欢我们的评审,欢迎考虑分享 ✨
Original comment in English

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@wess09
wess09 merged commit 9fb8704 into wess09:dev_frontend Sep 16, 2026
4 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants