feat(model): 新增 ModelLoader 链式构建 API 及 ORT GPU/Tract 多线程配置
- 在 ddddocr-core 中定义 ModelBuilder Trait 及其错误类型 - ddddocr-ort 支持 use_gpu、device_id 及 num_threads 链式配置与 CUDA 硬件加速 - ddddocr-tract 基于 multithread-mm 特性支持 CPU 线程数控制 - 支持基于 tract-linalg 配置推理线程数,显式引入 tract-linalg 的 multithread-mm 特性,控制 GEMM 算子并发 - 优化线程池加载策略,适配 Tokio 异步及 CLI 等多场景
This commit is contained in:
@@ -2,7 +2,8 @@ use crate::types::Session;
|
||||
use ddddocr_core::error::{Result, TensorError};
|
||||
use ddddocr_core::{DetEngine, DetOutput, InferenceEngine};
|
||||
use ndarray::Ix3;
|
||||
use tract_onnx::prelude::{tvec, IntoTensor, Tensor};
|
||||
// use tract_onnx::prelude::{tvec, IntoTensor, Tensor};
|
||||
use tract_onnx::prelude::*;
|
||||
#[derive(Debug)]
|
||||
pub struct DetSession {
|
||||
pub session: Session,
|
||||
@@ -29,7 +30,8 @@ impl InferenceEngine for DetSession {
|
||||
println!("模型输出原始数据: {:?}", result);
|
||||
// Ok(result.swap_remove(0).into_tensor())
|
||||
let raw_tensor = result.swap_remove(0).into_tensor();
|
||||
let array_d = raw_tensor.into_array::<f32>().map_err(|_| {
|
||||
// raw_tensor.into_plain_array()?
|
||||
let array_d = raw_tensor.into_plain_array::<f32>().map_err(|_| {
|
||||
TensorError::Engine("Tract 实体张量无法转换为 ndarray::ArrayD".to_string())
|
||||
})?;
|
||||
// 提前利用克隆(Clone)备份好当前未转维度前的真实 shape (Vec<usize>)
|
||||
|
||||
Reference in New Issue
Block a user