From f7aae32caf9e185ba6f791f6c5fd3ed5f00ea559 Mon Sep 17 00:00:00 2001 From: uttarayan21 Date: Tue, 5 Aug 2025 19:17:31 +0530 Subject: [PATCH] broken: Remove the FaceDetectionConfig --- src/facedet/retinaface.rs | 116 +------------------------------------- 1 file changed, 3 insertions(+), 113 deletions(-) diff --git a/src/facedet/retinaface.rs b/src/facedet/retinaface.rs index 69b8f52..b10c040 100644 --- a/src/facedet/retinaface.rs +++ b/src/facedet/retinaface.rs @@ -6,50 +6,13 @@ use nalgebra::{Point2, Vector2}; use ndarray_resize::NdFir; use std::path::Path; -pub struct FaceDetectionConfig { - anchor_sizes: Vec>, - steps: Vec, - variance: Vec, - threshold: f32, - nms_threshold: f32, -} +pub struct FaceDetectionConfig {} -impl FaceDetectionConfig { - pub fn with_min_sizes(mut self, min_sizes: Vec>) -> Self { - self.anchor_sizes = min_sizes; - self - } - pub fn with_steps(mut self, steps: Vec) -> Self { - self.steps = steps; - self - } - pub fn with_variance(mut self, variance: Vec) -> Self { - self.variance = variance; - self - } - pub fn with_threshold(mut self, threshold: f32) -> Self { - self.threshold = threshold; - self - } - pub fn with_nms_threshold(mut self, nms_threshold: f32) -> Self { - self.nms_threshold = nms_threshold; - self - } -} +impl FaceDetectionConfig {} impl Default for FaceDetectionConfig { fn default() -> Self { - FaceDetectionConfig { - anchor_sizes: vec![ - Vector2::new(16, 32), - Vector2::new(64, 128), - Vector2::new(256, 512), - ], - steps: vec![8, 16, 32], - variance: vec![0.1, 0.2], - threshold: 0.8, - nms_threshold: 0.4, - } + FaceDetectionConfig {} } } pub struct FaceDetection { @@ -89,79 +52,6 @@ pub struct FaceDetectionOutput { impl FaceDetectionModelOutput { pub fn postprocess(self, config: &FaceDetectionConfig) -> Result { - let mut anchors = Vec::new(); - for (k, &step) in config.steps.iter().enumerate() { - let feature_size = 1024 / step; - let min_sizes = config.anchor_sizes[k]; - let sizes = [min_sizes.x, min_sizes.y]; - for i in 0..feature_size { - for j in 0..feature_size { - for &size in &sizes { - let cx = (j as f32 + 0.5) * step as f32 / 1024.0; - let cy = (i as f32 + 0.5) * step as f32 / 1024.0; - let s_k = size as f32 / 1024.0; - anchors.push((cx, cy, s_k, s_k)); - } - } - } - } - let mut boxes = Vec::new(); - let mut scores = Vec::new(); - let mut landmarks = Vec::new(); - let var0 = config.variance[0]; - let var1 = config.variance[1]; - let bbox_data = self.bbox; - let conf_data = self.confidence; - let landmark_data = self.landmark; - let num_priors = bbox_data.shape()[1]; - for idx in 0..num_priors { - let dx = bbox_data[[0, idx, 0]]; - let dy = bbox_data[[0, idx, 1]]; - let dw = bbox_data[[0, idx, 2]]; - let dh = bbox_data[[0, idx, 3]]; - let (anchor_cx, anchor_cy, anchor_w, anchor_h) = anchors[idx]; - let pred_cx = anchor_cx + dx * var0 * anchor_w; - let pred_cy = anchor_cy + dy * var0 * anchor_h; - let pred_w = anchor_w * (dw * var1).exp(); - let pred_h = anchor_h * (dh * var1).exp(); - let x_min = pred_cx - pred_w / 2.0; - let y_min = pred_cy - pred_h / 2.0; - let x_max = pred_cx + pred_w / 2.0; - let y_max = pred_cy + pred_h / 2.0; - let score = conf_data[[0, idx, 1]]; - if score > config.threshold { - boxes.push(Aabb2::from_x1y1x2y2(x_min, y_min, x_max, y_max)); - scores.push(score); - - let left_eye_x = landmark_data[[0, idx, 0]] * anchor_w * var0 + anchor_cx; - let left_eye_y = landmark_data[[0, idx, 1]] * anchor_h * var0 + anchor_cy; - - let right_eye_x = landmark_data[[0, idx, 2]] * anchor_w * var0 + anchor_cx; - let right_eye_y = landmark_data[[0, idx, 3]] * anchor_h * var0 + anchor_cy; - - let nose_x = landmark_data[[0, idx, 4]] * anchor_w * var0 + anchor_cx; - let nose_y = landmark_data[[0, idx, 5]] * anchor_h * var0 + anchor_cy; - - let left_mouth_x = landmark_data[[0, idx, 6]] * anchor_w * var0 + anchor_cx; - let left_mouth_y = landmark_data[[0, idx, 7]] * anchor_h * var0 + anchor_cy; - - let right_mouth_x = landmark_data[[0, idx, 8]] * anchor_w * var0 + anchor_cx; - let right_mouth_y = landmark_data[[0, idx, 9]] * anchor_h * var0 + anchor_cy; - - landmarks.push(FaceLandmarks { - left_eye: Point2::new(left_eye_x, left_eye_y), - right_eye: Point2::new(right_eye_x, right_eye_y), - nose: Point2::new(nose_x, nose_y), - left_mouth: Point2::new(left_mouth_x, left_mouth_y), - right_mouth: Point2::new(right_mouth_x, right_mouth_y), - }); - } - } - Ok(FaceDetectionProcessedOutput { - bbox: boxes, - confidence: scores, - landmarks, - }) } }