π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mob][photos] Use CPU for Rust OCR inference
laurensprieme269f21d29c5
diff --git a/rust/crates/ml/src/ocr/classify.rs b/rust/crates/ml/src/ocr/classify.rsindex 6c8ec05d81..de07e72444 100644--- a/rust/crates/ml/src/ocr/classify.rs+++ b/rust/crates/ml/src/ocr/classify.rs@@ -38,10 +38,11 @@ pub(crate) struct AngleClassifier {impl AngleClassifier {pub(crate) fn new(model_path: &str) -> Self {Self {- session: Mutex::new(- OnnxSession::new(model_path, MODEL_NAMESPACE, ExecutionMode::CpuAccelerated)- .with_unvalidated_acceleration(),- ),+ session: Mutex::new(OnnxSession::new(+ model_path,+ MODEL_NAMESPACE,+ ExecutionMode::CpuOnly,+ )),}}diff --git a/rust/crates/ml/src/ocr/detect.rs b/rust/crates/ml/src/ocr/detect.rsindex 0c8bfda640..10f1216234 100644--- a/rust/crates/ml/src/ocr/detect.rs+++ b/rust/crates/ml/src/ocr/detect.rs@@ -46,10 +46,11 @@ pub(crate) struct TextDetector {impl TextDetector {pub(crate) fn new(model_path: &str) -> Self {Self {- session: Mutex::new(- OnnxSession::new(model_path, MODEL_NAMESPACE, ExecutionMode::CpuAccelerated)- .with_unvalidated_acceleration(),- ),+ session: Mutex::new(OnnxSession::new(+ model_path,+ MODEL_NAMESPACE,+ ExecutionMode::CpuOnly,+ )),}}diff --git a/rust/crates/ml/src/ocr/recognize.rs b/rust/crates/ml/src/ocr/recognize.rsindex a9f7591b2f..33ff2ae47d 100644--- a/rust/crates/ml/src/ocr/recognize.rs+++ b/rust/crates/ml/src/ocr/recognize.rs@@ -63,10 +63,11 @@ pub(crate) struct TextRecognizer {impl TextRecognizer {pub(crate) fn new(model_path: &str, dictionary_path: &str) -> Self {Self {- session: Mutex::new(- OnnxSession::new(model_path, MODEL_NAMESPACE, ExecutionMode::CpuAccelerated)- .with_unvalidated_acceleration(),- ),+ session: Mutex::new(OnnxSession::new(+ model_path,+ MODEL_NAMESPACE,+ ExecutionMode::CpuOnly,+ )),dictionary: LazyDictionary::new(dictionary_path),}}diff --git a/rust/crates/ml/src/onnx/providers.rs b/rust/crates/ml/src/onnx/providers.rsindex c6434c6429..96a4536afd 100644--- a/rust/crates/ml/src/onnx/providers.rs+++ b/rust/crates/ml/src/onnx/providers.rs@@ -48,7 +48,6 @@ const ENABLE_PERSISTENT_COREML_CACHE: bool = true;#[derive(Clone, Copy, Debug, PartialEq, Eq)]pub(crate) enum ExecutionMode {PlatformDefault,- CpuAccelerated,CpuOnly,}@@ -78,7 +77,6 @@ impl ProviderPlan {) -> Self {let providers = match mode {ExecutionMode::PlatformDefault => platform_default_providers(model_path, validation),- ExecutionMode::CpuAccelerated => cpu_accelerated_providers(),ExecutionMode::CpuOnly => vec![ExecutionProvider::Cpu],};Self::from_providers(providers)@@ -273,16 +271,6 @@ fn platform_default_providers(vec![ExecutionProvider::Cpu]}-#[cfg(target_os = "android")]-fn cpu_accelerated_providers() -> Vec<ExecutionProvider> {- vec![ExecutionProvider::Xnnpack, ExecutionProvider::Cpu]-}--#[cfg(not(target_os = "android"))]-fn cpu_accelerated_providers() -> Vec<ExecutionProvider> {- vec![ExecutionProvider::Cpu]-}-// Missing goldens fail closed, usually indicating they were not regenerated// after an update.#[cfg(any(@@ -490,21 +478,6 @@ mod tests {assert!(!plan.has_fallback());}- #[test]- fn cpu_accelerated_plan_ends_with_cpu_and_never_uses_gpu_providers() {- let plan = ProviderPlan::new(- ExecutionMode::CpuAccelerated,- "model.onnx",- AccelerationValidation::Unvalidated,- );-- assert_eq!(plan.providers.last(), Some(&ExecutionProvider::Cpu));- assert!(!plan.providers.iter().any(|provider| matches!(- provider,- ExecutionProvider::WebGpu | ExecutionProvider::CoreMl- )));- }-fn accelerated_provider_plan() -> ProviderPlan {ProviderPlan::from_providers(vec![ExecutionProvider::WebGpu,