fix: restore Apple Vision default detection thresholds (0.5 / 1px)
job_worker.rs was overriding Apple Vision defaults with 0.75/64 even when no face_settings were provided, causing fewer faces to be detected. Now detect all faces with Vision defaults (confidence 0.5, min_size 1px); filter later for display via face_filter settings.
This commit is contained in:
@@ -148,8 +148,8 @@ class FaceProcessorVision:
|
|||||||
|
|
||||||
print(f"[FACE_V2] Running: {' '.join(cmd)}")
|
print(f"[FACE_V2] Running: {' '.join(cmd)}")
|
||||||
# Log face detection settings being passed to swift_face
|
# Log face detection settings being passed to swift_face
|
||||||
min_conf = os.environ.get("FACE_MIN_CONFIDENCE", "not set (default 0.75)")
|
min_conf = os.environ.get("FACE_MIN_CONFIDENCE", "not set (default 0.5)")
|
||||||
min_size = os.environ.get("FACE_MIN_SIZE", "not set (default 64)")
|
min_size = os.environ.get("FACE_MIN_SIZE", "not set (default 1)")
|
||||||
print(f"[FACE_V2] Settings passed to swift_face: FACE_MIN_CONFIDENCE={min_conf}, FACE_MIN_SIZE={min_size}")
|
print(f"[FACE_V2] Settings passed to swift_face: FACE_MIN_CONFIDENCE={min_conf}, FACE_MIN_SIZE={min_size}")
|
||||||
t0 = time.time()
|
t0 = time.time()
|
||||||
log_path = swift_face_out + ".log"
|
log_path = swift_face_out + ".log"
|
||||||
|
|||||||
@@ -7,6 +7,25 @@ const PROFILE_VERSION: &str = "1.0";
|
|||||||
|
|
||||||
// ─── Data Types ───
|
// ─── Data Types ───
|
||||||
|
|
||||||
|
/// Per-file face detection thresholds. `min_confidence` is 0–100 (%),
|
||||||
|
/// `min_size` is px. Mirrors `videos.face_filter` DB column (same units).
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub struct FaceFilterSettings {
|
||||||
|
pub min_confidence: f64,
|
||||||
|
pub min_size: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FaceFilterSettings {
|
||||||
|
/// Mirrors Apple Vision default detection thresholds (0.5 / 1px).
|
||||||
|
/// Filter later for display; detect everything first.
|
||||||
|
pub fn defaults() -> Self {
|
||||||
|
Self {
|
||||||
|
min_confidence: 50.0,
|
||||||
|
min_size: 1,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct FileProfile {
|
pub struct FileProfile {
|
||||||
pub version: String,
|
pub version: String,
|
||||||
@@ -20,6 +39,7 @@ pub struct FileProfile {
|
|||||||
pub key_frame: Option<String>, // filename: {uuid}.key_frame.jpg, video only
|
pub key_frame: Option<String>, // filename: {uuid}.key_frame.jpg, video only
|
||||||
pub proxy_path: Option<String>, // 720p proxy path for 1080p+ videos
|
pub proxy_path: Option<String>, // 720p proxy path for 1080p+ videos
|
||||||
pub audio_track: Option<String>, // audio track classification: no_audio/silent_audio/music_only/speech_only/speech_with_music
|
pub audio_track: Option<String>, // audio track classification: no_audio/silent_audio/music_only/speech_only/speech_with_music
|
||||||
|
pub face_filter: Option<FaceFilterSettings>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
@@ -123,6 +143,7 @@ impl FileProfile {
|
|||||||
key_frame: None,
|
key_frame: None,
|
||||||
proxy_path: None,
|
proxy_path: None,
|
||||||
audio_track: None,
|
audio_track: None,
|
||||||
|
face_filter: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,6 +182,7 @@ impl FileProfile {
|
|||||||
key_frame: None,
|
key_frame: None,
|
||||||
proxy_path: None,
|
proxy_path: None,
|
||||||
audio_track: None,
|
audio_track: None,
|
||||||
|
face_filter: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -289,6 +311,7 @@ impl FileProfile {
|
|||||||
key_frame: None,
|
key_frame: None,
|
||||||
proxy_path: None,
|
proxy_path: None,
|
||||||
audio_track: None,
|
audio_track: None,
|
||||||
|
face_filter: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -562,4 +585,71 @@ mod tests {
|
|||||||
assert_eq!(restored.file_name, profile.file_name);
|
assert_eq!(restored.file_name, profile.file_name);
|
||||||
assert_eq!(restored.history.len(), 1);
|
assert_eq!(restored.history.len(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_face_filter_roundtrip() {
|
||||||
|
let mut profile = FileProfile::from_registration(
|
||||||
|
"abc123",
|
||||||
|
"test.mp4",
|
||||||
|
"video",
|
||||||
|
"aa:bb:cc:dd:ee:ff",
|
||||||
|
"2026-01-01T00:00:00Z",
|
||||||
|
"/Users/test/video.mp4",
|
||||||
|
"hash123",
|
||||||
|
120.0,
|
||||||
|
1920,
|
||||||
|
1080,
|
||||||
|
30.0,
|
||||||
|
3600,
|
||||||
|
);
|
||||||
|
assert!(profile.face_filter.is_none());
|
||||||
|
|
||||||
|
profile.face_filter = Some(FaceFilterSettings {
|
||||||
|
min_confidence: 85.0,
|
||||||
|
min_size: 96,
|
||||||
|
});
|
||||||
|
let json = serde_json::to_string(&profile).unwrap();
|
||||||
|
let restored: FileProfile = serde_json::from_str(&json).unwrap();
|
||||||
|
let ff = restored.face_filter.unwrap();
|
||||||
|
assert_eq!(ff.min_confidence, 85.0);
|
||||||
|
assert_eq!(ff.min_size, 96);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_old_profile_without_face_filter_deserializes() {
|
||||||
|
let json = r#"{
|
||||||
|
"version": "1.0",
|
||||||
|
"file_uuid": "abc123",
|
||||||
|
"file_name": "test.mp4",
|
||||||
|
"file_type": "video",
|
||||||
|
"birth": {
|
||||||
|
"mac_address": "aa:bb:cc:dd:ee:ff",
|
||||||
|
"birthday": "2026-01-01T00:00:00Z",
|
||||||
|
"original_path": "/Users/test",
|
||||||
|
"original_filename": "test.mp4",
|
||||||
|
"canonical_path": "/Users/test/video.mp4",
|
||||||
|
"content_hash": "hash123"
|
||||||
|
},
|
||||||
|
"current": {
|
||||||
|
"path": "/Users/test/video.mp4",
|
||||||
|
"file_name": "test.mp4",
|
||||||
|
"file_type": "video"
|
||||||
|
},
|
||||||
|
"history": [],
|
||||||
|
"metadata": null,
|
||||||
|
"key_frame": null,
|
||||||
|
"proxy_path": null,
|
||||||
|
"audio_track": null
|
||||||
|
}"#;
|
||||||
|
let profile: FileProfile = serde_json::from_str(json).unwrap();
|
||||||
|
assert_eq!(profile.file_uuid, "abc123");
|
||||||
|
assert!(profile.face_filter.is_none());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_face_filter_defaults_match_detection_defaults() {
|
||||||
|
let d = FaceFilterSettings::defaults();
|
||||||
|
assert_eq!(d.min_confidence, 50.0);
|
||||||
|
assert_eq!(d.min_size, 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -464,8 +464,8 @@ impl JobWorker {
|
|||||||
// Read face_settings from job and set environment variables for face processor
|
// Read face_settings from job and set environment variables for face processor
|
||||||
let mut face_settings_backup: Option<(String, String)> = None;
|
let mut face_settings_backup: Option<(String, String)> = None;
|
||||||
if let Some(ref fs) = job.face_settings {
|
if let Some(ref fs) = job.face_settings {
|
||||||
let min_confidence = fs.get("min_confidence").and_then(|v| v.as_f64()).unwrap_or(0.75);
|
let min_confidence = fs.get("min_confidence").and_then(|v| v.as_f64()).unwrap_or(0.5);
|
||||||
let min_size = fs.get("min_size").and_then(|v| v.as_i64()).unwrap_or(64) as i32;
|
let min_size = fs.get("min_size").and_then(|v| v.as_i64()).unwrap_or(1) as i32;
|
||||||
tracing::info!(
|
tracing::info!(
|
||||||
"[WORKER] Job {} face_settings: CONFIDENCE={}, SIZE={}",
|
"[WORKER] Job {} face_settings: CONFIDENCE={}, SIZE={}",
|
||||||
job.uuid,
|
job.uuid,
|
||||||
|
|||||||
Reference in New Issue
Block a user