YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context
Rust agentsagiaiai-memoryaudio-recordingcomputer-visionhermeshermes-agentllmlocal-ailocal-firstmachine-learningmcpmultimodalopenclawprivacyrewindscreen-recordingspeech-to-textycombinator
feat(redact): ship rfdetr_v34, and correct the benchmark numbers
Louis Beaumont1f5023ecca68
diff --git a/crates/screenpipe-redact/src/adapters/rfdetr.rs b/crates/screenpipe-redact/src/adapters/rfdetr.rsindex ab3bfad9f..4ce7988c3 100644--- a/crates/screenpipe-redact/src/adapters/rfdetr.rs+++ b/crates/screenpipe-redact/src/adapters/rfdetr.rs@@ -20,24 +20,39 @@//!//! ## Reference benchmark numbers//!-//! `rfdetr_v27` (512×512 input, FP16 ONNX with fp32 I/O wrapper, ~60 MB,-//! ~118 ms/frame CPU). Held-out evals, production decode (sigmoid,-//! conf 0.50), [email protected], head-to-head vs the previous shipped-//! model (v19):+//! `rfdetr_v34` (512×512 input, FP16 ONNX with fp32 I/O wrapper, ~60 MB,+//! ~118 ms/frame CPU). Production decode (sigmoid, conf 0.50),+//! [email protected] on a 150-state real-app suite of planted PII that no+//! model here trained on://!-//! 150-state real-app suite (planted PII, unseen by both):-//! v19: recall 60.1 %, secrets 66/76, 0 decoy false fires-//! v27: recall 60.6 %, secrets 74/76, 0 decoy false fires-//! 900-page held-out app/web-layout suite (exact ground truth):-//! v19: recall 1.3 % (near-blind on standard layouts)-//! v27: recall 93.1 %, 0 false fires on its 222 zero-PII pages-//! Real captured frames: recall 17.6 % vs 13.4 %, ~1.2 boxes/frame,-//! real-email recall 143/376 vs 3/376.+//! v27 (previous): recall 92.9 %, secrets 74/76, 1.04 strays/shot+//! v34 (this): recall 95.3 %, secrets 75/76, 1.03 strays/shot+//! Both: 0 decoy false fires. For scale, an RFDETR-**Large** trained on+//! the same data scores 95.7 % — i.e. +0.4 over this nano model, so+//! accuracy here is data-limited, not capacity-limited.//!-//! False-fire status: 0 fires on the 300-page zero-PII decoy suite,-//! 0 fires on 3,000 fresh zero-PII app/web pages (v19: 152 fires),-//! 0 decoy hits on both real-app suites. Known remaining FP mode:-//! occasional brand wordmark boxed as person on real screens.+//! NOTE: numbers previously recorded in this file (~60 % recall, person+//! 0/109) were produced by a scorer that compared tight detections+//! against whole-OCR-line gold boxes while normalising by the gold+//! area, so any PII short relative to its line scored as a miss. The+//! weights were never that bad; the measurement was. Figures above use+//! substring-tight gold boxes.+//!+//! False-fire status: 0 fires on the 300-page zero-PII decoy suite and+//! 0 decoy hits on the real-app suites. On 240 real captured frames+//! v34 produces roughly half the pattern-identifiable false positives+//! of v27 (39 vs 80) — the class this targets is hyphenated lowercase+//! slugs (`tmpclaude-8ab0-cwd`, `v0-autoehr-landing-page`) that earlier+//! models boxed as EMAIL in terminal listings.+//!+//! KNOWN LIMITATION, read before trusting these numbers: on those same+//! real frames neither v27 nor v34 produced a single detection whose+//! cropped pixels OCR to a well-formed email/phone/url/secret. The+//! suites above are planted-PII harnesses rendered by our own+//! generator; they are held out, but they are not real screens. Treat+//! real-world behaviour as unmeasured until a verified real-frame eval+//! exists. Other observed FP modes: brand wordmarks as person, and+//! ordinary prose as email.//!//! FP16 re-export recipe: torch half() at ONNX export from the FINAL//! training weights (`last.ckpt` — NOT `checkpoint_best_ema.pth`,@@ -54,7 +69,7 @@ use crate::RedactError;use crate::SpanLabel;const RFDETR_NAME: &str = "rfdetr";-const RFDETR_VERSION: u32 = 27; // matches the rfdetr_v27 ONNX (fp16, 512px, real-app trained)+const RFDETR_VERSION: u32 = 34; // matches the rfdetr_v34 ONNX (fp16, 512px, real-app trained)#[cfg(feature = "onnx-cpu")]const NUM_CLASSES: usize = 12;@@ -80,7 +95,7 @@ const CLASSES: [SpanLabel; NUM_CLASSES] = [];/// Per-class score floors applied on top of `conf_threshold` (the higher-/// wins). All zero since v19, and v27 keeps them zero: genuine secret+/// wins). All zero since v19, and v34 keeps them zero: genuine secret/// detections score ~0.5–0.7 while zero secret false fires were/// observed at conf 0.50 across every zero-PII suite — a high floor/// would suppress real catches for no precision gain. Mechanism kept@@ -92,7 +107,7 @@ const CLASS_MIN_SCORE: [f32; NUM_CLASSES] =/// Configuration for [`RfdetrRedactor`].#[derive(Debug, Clone)]pub struct RfdetrConfig {- /// Path to `rfdetr_vN.onnx`. We default to `~/.screenpipe/models/rfdetr_v27.onnx`+ /// Path to `rfdetr_vN.onnx`. We default to `~/.screenpipe/models/rfdetr_v34.onnx`/// in [`Self::default_model_path`] but callers may override (e.g./// for an INT8-quantized variant in the future).pub model_path: PathBuf,@@ -123,14 +138,14 @@ impl Default for RfdetrConfig {}impl RfdetrConfig {- /// `~/.screenpipe/models/rfdetr_v27.onnx`. Created lazily by+ /// `~/.screenpipe/models/rfdetr_v34.onnx`. Created lazily by/// [`Self::ensure_model_present`] on first run.pub fn default_model_path() -> PathBuf {dirs::home_dir().unwrap_or_else(|| PathBuf::from(".")).join(".screenpipe").join("models")- .join("rfdetr_v27.onnx")+ .join("rfdetr_v34.onnx")}/// HuggingFace download URL for the canonical ONNX. Pinned to@@ -138,16 +153,16 @@ impl RfdetrConfig {/// (URL + expected SHA-256 + [`RFDETR_VERSION`] all bumped/// together).pub const HF_DOWNLOAD_URL: &'static str =- "https://huggingface.co/screenpipe/pii-image-redactor/resolve/main/rfdetr_v27.onnx";+ "https://huggingface.co/screenpipe/pii-image-redactor/resolve/main/rfdetr_v34.onnx";- /// Expected SHA-256 of the canonical `rfdetr_v27.onnx`. Verified+ /// Expected SHA-256 of the canonical `rfdetr_v34.onnx`. Verified/// after every download. If a future training run produces a new/// best, bump [`RFDETR_VERSION`], re-publish to HF, update this/// constant. Note: the worker is destructive-only and does NOT/// re-redact already-processed frames, so a model-version bump/// only takes effect for newly-captured frames going forward.pub const EXPECTED_SHA256: &'static str =- "904f6d0f745a4b07cd77a96ab443f7c19633f0c1ccee18c46dc622c64d065a84";+ "02ffb5e9b25b83a36e105d3fa6d198b739b86c31c585d545ebcab3899c7d889b";/// Make sure the ONNX is present on disk. Idempotent — does/// nothing if [`Self::model_path`] already exists with the@@ -176,7 +191,7 @@ impl RfdetrConfig {tracing::info!(url = Self::HF_DOWNLOAD_URL,target = %self.model_path.display(),- "downloading rfdetr_v27.onnx (~60 MB) — first-run only"+ "downloading rfdetr_v34.onnx (~60 MB) — first-run only");let resp = reqwest::Client::new().get(Self::HF_DOWNLOAD_URL)@@ -213,7 +228,7 @@ impl RfdetrConfig {tracing::info!(target = %self.model_path.display(),bytes = bytes.len(),- "rfdetr_v27.onnx ready"+ "rfdetr_v34.onnx ready");Ok(())}@@ -560,7 +575,7 @@ mod tests {let p = RfdetrConfig::default_model_path();let expected_suffix = Path::new(".screenpipe").join("models")- .join("rfdetr_v27.onnx");+ .join("rfdetr_v34.onnx");assert!(p.ends_with(&expected_suffix),"default path {} should end with {}",@@ -626,7 +641,7 @@ mod tests {// (Real download path is exercised by integration tests off// the unit-test harness.)let d = tempdir().unwrap();- let p = d.path().join("models").join("rfdetr_v27.onnx");+ let p = d.path().join("models").join("rfdetr_v34.onnx");std::fs::create_dir_all(p.parent().unwrap()).unwrap();std::fs::write(&p, b"not the real model").unwrap();let cfg = RfdetrConfig {