fix(ocr): 兼容 rapidocr 3.9.0,显式传字符串 model_root_dir 规避 omegaconf 异常 - #952
Merged
Merged
Conversation
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 显式传入字符串规避。
CI 检查报告
检查结果
导入冒烟测试
意外失败:
|
审查者指南(小型 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
防止 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]
文件级变更
提示和命令与 Sourcery 交互
自定义使用体验访问你的控制面板以:
获取帮助Original review guide in EnglishReviewer'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 fixsequenceDiagram
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
Flow diagram for preventing the OCR initialization crashflowchart 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]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
dev_frontend的uv.lock锁定rapidocr == 3.9.0。rapidocr 3.9.0 的_load_config在model_root_dir为None时,会把全局配置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。测试说明(已实测通过)
加载验证:在本机环境执行
修复前抛
UnsupportedValueType,修复后成功创建RecOnlyOCR实例,模型正常加载。运行验证:运行科研任务(领取队列余量触发 OCR),修复前触发 ALAS 自动重启,修复连续运行不再崩溃、不再重启客户端。
影响面:三处构造点(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:
Enhancements:
Original summary in English
Summary by Sourcery
兼容 rapidocr 3.9.0 的 OCR 模型加载,防止任务执行过程中因配置类型异常导致客户端崩溃重启。
Bug Fixes:
Enhancements: