fix(ocr): clear ncnn inference allocator caches - #3
Conversation
Reviewer's GuideAdds explicit ncnn pool allocators for OCR detection/recognition networks and clears their blob/workspace caches after each OCR run to prevent inference memory from growing over repeated calls while keeping model weights resident. Sequence diagram for OCR analyze clearing ncnn allocatorssequenceDiagram
actor Client
participant PaddleOCRApp
participant detBlobAllocator
participant detWorkspaceAllocator
participant recBlobAllocator
participant recWorkspaceAllocator
Client->>PaddleOCRApp: analyze()
alt [no textBoxes]
PaddleOCRApp-->>Client: return false
else [textBoxes not empty]
PaddleOCRApp-->>Client: return true
end
note over PaddleOCRApp: At end of analyze()
PaddleOCRApp->>PaddleOCRApp: clearInferenceAllocators()
PaddleOCRApp->>detBlobAllocator: clear()
PaddleOCRApp->>detWorkspaceAllocator: clear()
PaddleOCRApp->>recBlobAllocator: clear()
PaddleOCRApp->>recWorkspaceAllocator: clear()
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
deepin pr auto review★ 总体评分:100分■ 【总体评价】
■ 【详细分析】
■ 【改进建议代码示例】 // 考虑使用 RAII 或确保所有退出路径调用清理逻辑
bool PaddleOCRApp::analyze()
{
// 使用 scope guard 确保清理
auto guard = finally([this] {
clearInferenceAllocators();
});
// ... 前置推理逻辑 ...
if (needBreak) {
allResult.clear();
boxesResult.clear();
needBreak = false;
return false;
} else {
//对识别结果进行最后清理,将未识别到文字的检测框排除掉
// ...
return !textBoxes.empty();
}
} |
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- Consider also clearing the pool allocators in
resetNet()so that any cached inference memory is released when the networks are torn down or reinitialized, not only afteranalyze()completes. - If
analyze()has or gains additional early-return code paths in the future, it might be safer to ensureclearInferenceAllocators()is called via a small RAII helper or at a single exit point to avoid missing cache clears.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider also clearing the pool allocators in `resetNet()` so that any cached inference memory is released when the networks are torn down or reinitialized, not only after `analyze()` completes.
- If `analyze()` has or gains additional early-return code paths in the future, it might be safer to ensure `clearInferenceAllocators()` is called via a small RAII helper or at a single exit point to avoid missing cache clears.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: wyu71 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Clear ncnn blob and workspace pools after OCR completes. OCR 完成后清理 ncnn blob 和 workspace 缓存。
Log: 清理OCR推理缓存,避免重复识别内存持续增长
Influence: 保留模型权重,释放推理临时缓存;不改变公共接口。
Summary by Sourcery
Clear OCR inference memory pools after each analysis run to prevent temporary ncnn allocator caches from accumulating.
Bug Fixes:
Enhancements: