refactor(core): 提炼公共类型
- 将 AxisDim、TensorInfo 等公共类型下沉至 ddddocr_core::types - 项目结构优化
This commit is contained in:
42
ddddocr-core/src/traits.rs
Normal file
42
ddddocr-core/src/traits.rs
Normal file
@@ -0,0 +1,42 @@
|
||||
use crate::error::TensorError;
|
||||
use crate::types::{ModelInfo, TensorInfo};
|
||||
use crate::{DetOutput, ModelMetadata, OcrOutput};
|
||||
use std::path::Path;
|
||||
|
||||
|
||||
pub trait Info {
|
||||
fn input_info(&self) -> crate::error::Result<Vec<TensorInfo>>;
|
||||
fn output_info(&self) -> crate::error::Result<Vec<TensorInfo>>;
|
||||
fn model_info(&self) -> crate::error::Result<ModelInfo>;
|
||||
}
|
||||
|
||||
/// 核心层定义的统一推理引擎接口。
|
||||
/// 未来的 ddddocr-tract 和 ddddocr-ort 都必须实现这个 Trait
|
||||
pub trait InferenceEngine {
|
||||
/// 关联类型:具体的 Session 需要声明自己到底产出什么枚举
|
||||
type Output;
|
||||
fn inference(
|
||||
&self,
|
||||
input_array: ndarray::Array4<f32>,
|
||||
) -> crate::error::Result<Self::Output, TensorError>;
|
||||
}
|
||||
|
||||
pub trait OcrEngine: InferenceEngine<Output = OcrOutput> + Info {
|
||||
fn metadata(&self) -> &ModelMetadata;
|
||||
}
|
||||
|
||||
pub trait DetEngine: InferenceEngine<Output = DetOutput> {}
|
||||
|
||||
pub trait Loader {
|
||||
type Session;
|
||||
type Error;
|
||||
fn build_for_path<P: AsRef<Path>>(
|
||||
&self,
|
||||
model_path: P,
|
||||
) -> crate::error::Result<Self::Session, Self::Error>;
|
||||
|
||||
fn build_from_bytes(
|
||||
&self,
|
||||
model_bytes: &[u8],
|
||||
) -> crate::error::Result<Self::Session, Self::Error>;
|
||||
}
|
||||
Reference in New Issue
Block a user