Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

perf(rust): use f32 transport for ml indexing bridge outputs

laurenspriem46c815b6bcda
diff --git a/mobile/apps/photos/rust/src/api/ml_indexing_api.rs b/mobile/apps/photos/rust/src/api/ml_indexing_api.rs
index 26ac56846a..1331bd01f5 100644
--- a/mobile/apps/photos/rust/src/api/ml_indexing_api.rs
+++ b/mobile/apps/photos/rust/src/api/ml_indexing_api.rs
@@ -56,31 +56,31 @@ pub struct RustDimensions {
#[derive(Clone, Debug)]
pub struct RustDetection {
- pub score: f64,
- pub box_xyxy: Vec<f64>,
- pub all_keypoints: Vec<Vec<f64>>,
+ pub score: f32,
+ pub box_xyxy: Vec<f32>,
+ pub all_keypoints: Vec<Vec<f32>>,
}
#[derive(Clone, Debug)]
pub struct RustAlignmentResult {
- pub affine_matrix: Vec<Vec<f64>>,
- pub center: Vec<f64>,
- pub size: f64,
- pub rotation: f64,
+ pub affine_matrix: Vec<Vec<f32>>,
+ pub center: Vec<f32>,
+ pub size: f32,
+ pub rotation: f32,
}
#[derive(Clone, Debug)]
pub struct RustFaceResult {
pub detection: RustDetection,
- pub blur_value: f64,
+ pub blur_value: f32,
pub alignment: RustAlignmentResult,
- pub embedding: Vec<f64>,
+ pub embedding: Vec<f32>,
pub face_id: String,
}
#[derive(Clone, Debug)]
pub struct RustClipResult {
- pub embedding: Vec<f64>,
+ pub embedding: Vec<f32>,
}
#[derive(Clone, Debug)]
@@ -140,7 +140,7 @@ fn analyze_image_rust_inner(req: AnalyzeImageRequest) -> MlResult<AnalyzeImageRe
run_clip_image(runtime, &decoded)
})?;
Some(RustClipResult {
- embedding: clip.embedding.into_iter().map(|v| v as f64).collect(),
+ embedding: clip.embedding,
})
} else {
None
@@ -204,38 +204,28 @@ fn to_provider_policy(policy: &RustExecutionProviderPolicy) -> ExecutionProvider
fn to_api_face_result(result: crate::ml::types::FaceResult) -> RustFaceResult {
RustFaceResult {
detection: RustDetection {
- score: result.detection.score as f64,
- box_xyxy: result
- .detection
- .box_xyxy
- .into_iter()
- .map(|v| v as f64)
- .collect(),
+ score: result.detection.score,
+ box_xyxy: result.detection.box_xyxy.into_iter().collect(),
all_keypoints: result
.detection
.keypoints
.into_iter()
- .map(|point| point.into_iter().map(|v| v as f64).collect())
+ .map(|point| point.into_iter().collect())
.collect(),
},
- blur_value: result.blur_value as f64,
+ blur_value: result.blur_value,
alignment: RustAlignmentResult {
affine_matrix: result
.alignment
.affine_matrix
.into_iter()
- .map(|row| row.into_iter().map(|v| v as f64).collect())
- .collect(),
- center: result
- .alignment
- .center
- .into_iter()
- .map(|v| v as f64)
+ .map(|row| row.into_iter().collect())
.collect(),
- size: result.alignment.size as f64,
- rotation: result.alignment.rotation as f64,
+ center: result.alignment.center.into_iter().collect(),
+ size: result.alignment.size,
+ rotation: result.alignment.rotation,
},
- embedding: result.embedding.into_iter().map(|v| v as f64).collect(),
+ embedding: result.embedding,
face_id: result.face_id,
}
}