refactor: 抽象解耦推理引擎并重构为多Crate工作空间架构
- 移除 核心层与 tract/Tensor 的强耦合,前/后处理全线转用标准 ndarray - 针对 OCR 与目标检测(Det)分别设计独立的强类型输出小枚举(OcrOutput/DetOutput) - 利用 Trait 关联类型(Associated Type)InferenceEngine,OcrEngine,DetEngine 统一接口,实现多后端解耦 - 引入 thiserror 库,建立完备的强类型错误处理机制(DdddError/Result) - 完成项目结构初拆,剥离为 ddddocr-core 和 ddddocr-tract
This commit is contained in:
48
ddddocr-core/src/error.rs
Normal file
48
ddddocr-core/src/error.rs
Normal file
@@ -0,0 +1,48 @@
|
||||
pub(crate) const MODEL_DOWNLOAD_HELP: &str = "\
|
||||
================================================================================
|
||||
[ddddocr-rust] 错误:未找到默认的模型文件!
|
||||
--------------------------------------------------------------------------------
|
||||
由于打包体积限制,本库未内置 ONNX 模型。请按照以下步骤操作:
|
||||
|
||||
1. 前往官方 GitHub 下载对应的模型权重:
|
||||
- OCR 模型: https://github.com/sml2h3/ddddocr/raw/master/ddddocr/common_sml2h3_f32.onnx
|
||||
- DET 模型: https://github.com/sml2h3/ddddocr/raw/master/ddddocr/common_det.onnx
|
||||
|
||||
2. 配置加载方式(二选一):
|
||||
A. 【推荐】设置环境变量指向您下载的文件:
|
||||
Linux/macOS: export DDDD_OCR_MODEL=\"/path/to/common_sml2h3_f32.onnx\"
|
||||
Windows (CMD): set DDDD_OCR_MODEL=C:\\path\\to\\common_sml2h3_f32.onnx
|
||||
Windows (PowerShell): $env:DDDD_OCR_MODEL=\"C:\\path\\to\\common_sml2h3_f32.onnx\"
|
||||
|
||||
B. 或者直接将模型文件重命名并放置在您运行程序的“当前工作目录”或“可执行文件同级目录”下。
|
||||
================================================================================";
|
||||
|
||||
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum DdddError {
|
||||
#[error("图像预处理失败: {0}")]
|
||||
PreprocessError(String),
|
||||
|
||||
#[error("模型推理引擎内部发生异常: {0}")]
|
||||
EngineError(#[from] anyhow::Error),
|
||||
|
||||
#[error("CTC 解码错误: {0}")]
|
||||
DecodeError(String),
|
||||
|
||||
#[error("维度转换失败,预期维度 {expected},实际形状为 {actual:?}")]
|
||||
DimensionMismatch {
|
||||
expected: String,
|
||||
actual: Vec<usize>,
|
||||
},
|
||||
|
||||
#[error("内存不连续,无法执行零拷贝操作")]
|
||||
NonContiguousMemory,
|
||||
|
||||
#[error("未知的模型输出格式")]
|
||||
UnknownOutputFormat,
|
||||
}
|
||||
|
||||
/// 统一用我们自己的 DdddError 包装 Result
|
||||
pub type Result<T> = std::result::Result<T, DdddError>;
|
||||
Reference in New Issue
Block a user