M13.36: face tracking trained model — MediaPipe Face Landmarker on a pure-Rust TFLite interpreter
- effectcraft-segment: a FaceModel interface (find a face in a region, follow it; a Topology maps the model's points to the tracker's landmarks and outline), a TensorFlow Lite reader and interpreter (float ops, float16 weights folded; matches ai-edge-litert to ~1e-6), and MediaPipe Face Landmarker (Google, Apache-2.0: BlazeFace + Face Mesh V2, 3.8 MB, pinned SHA-256). The registry gains a task and authors per model; installed weights get a NOTICE. - effectcraft-track: FaceTracker::new_with uses the model, falls back to the classical fitter when it finds no face; chin and jaw come from the outline either way so measurements agree. - Engine: roto_models becomes models (both tasks); face.models / face.model.* commands, Settings ▸ Face Tracking, `wait` on select/install/download for scripts; track.mask reports faceModel. - Credits: ATTRIBUTION.md lists the optional models and the Apache-2.0 specs the code follows. - Docs: README, ROADMAP (G7), gaps, parity (TRK-3 score unchanged pending G1), agents, preferences, architecture, segment README. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
4624c00308
commit
e43bf66775
@@ -8,6 +8,7 @@
|
||||
//! `settings.cancel`, `settings.previous`, `settings.next`.
|
||||
|
||||
use effectcraft_engine::prefs::{Item, Kind, Page, pages};
|
||||
use effectcraft_engine::segment::Task;
|
||||
use egui::{Color32, RichText, vec2};
|
||||
use serde_json::{Value, json};
|
||||
|
||||
@@ -28,8 +29,8 @@ enum Act {
|
||||
Run(String, Value),
|
||||
PickFolder(String),
|
||||
PickProject(String),
|
||||
/// Install from File (a downloaded weights file).
|
||||
PickModel,
|
||||
/// Install from File (a downloaded weights file) for a task's models.
|
||||
PickModel(Task),
|
||||
}
|
||||
|
||||
fn hex(c: [u8; 3]) -> String {
|
||||
@@ -63,7 +64,7 @@ fn page_ui(app: &mut EffectcraftApp, ui: &mut egui::Ui, page: &Page, cur: &Value
|
||||
}
|
||||
Item::Labels => labels_ui(app, ui, cur, acts),
|
||||
Item::BrowserStorage => browser_storage_ui(app, ui, t, acts),
|
||||
Item::RotoModels => roto_models_ui(app, ui, t, acts),
|
||||
Item::Models(task) => models_ui(app, ui, t, acts, task),
|
||||
Item::AudioDevices { key } => {
|
||||
let devices: Vec<String> = app.hooks.audio_devices.as_ref().map(|f| f()).unwrap_or_default();
|
||||
let sel = get(key).as_str().unwrap_or("").to_string();
|
||||
@@ -210,17 +211,21 @@ pub fn human_bytes(b: u64) -> String {
|
||||
if u == 0 { format!("{b} bytes") } else { format!("{v:.1} {}", units[u]) }
|
||||
}
|
||||
|
||||
/// Settings ▸ Disk ▸ Browser Storage (the web app's storage manager, `storage.*`): where the
|
||||
/// data lives, the origin's usage and quota, persistent storage, and Clear buttons.
|
||||
/// Settings ▸ Roto Brush: the segmentation models (`roto.models`): choose one; download, install
|
||||
/// from a file or remove the trained ones; their licence, size and source.
|
||||
fn roto_models_ui(app: &mut EffectcraftApp, ui: &mut egui::Ui, t: &Tokens, acts: &mut Vec<Act>) {
|
||||
let Ok(info) = app.session.execute("roto.models", json!({})) else { return };
|
||||
/// Settings ▸ Roto Brush and Settings ▸ Face Tracking: a task's models (`roto.models`,
|
||||
/// `face.models`): choose one; download, install from a file or remove the trained ones; who made
|
||||
/// them, their licence, size and source.
|
||||
fn models_ui(app: &mut EffectcraftApp, ui: &mut egui::Ui, t: &Tokens, acts: &mut Vec<Act>, task: Task) {
|
||||
let (prefix, user) = match task {
|
||||
Task::Mask => ("roto", "Roto Brush"),
|
||||
Task::Face => ("face", "Face tracking"),
|
||||
};
|
||||
let Ok(info) = app.session.execute(&format!("{prefix}.models"), json!({})) else { return };
|
||||
let web = cfg!(target_arch = "wasm32");
|
||||
let busy = info["busy"].as_str().map(str::to_string);
|
||||
for m in info["models"].as_array().into_iter().flatten() {
|
||||
let id = m["id"].as_str().unwrap_or_default().to_string();
|
||||
let name = m["name"].as_str().unwrap_or_default();
|
||||
let classic = id == effectcraft_engine::segment::CLASSICAL;
|
||||
let (installed, selected, active) =
|
||||
(m["installed"].as_bool().unwrap_or(false), m["selected"].as_bool().unwrap_or(false), m["active"].as_bool().unwrap_or(false));
|
||||
ui.add_space(6.0);
|
||||
@@ -228,28 +233,30 @@ fn roto_models_ui(app: &mut EffectcraftApp, ui: &mut egui::Ui, t: &Tokens, acts:
|
||||
ui.set_width(ui.available_width());
|
||||
ui.horizontal(|ui| {
|
||||
let r = ui.radio(selected, RichText::new(name).font(Tokens::semibold(12.5)));
|
||||
reg(app, &format!("settings.roto.model.{id}"), &r, name);
|
||||
reg(app, &format!("settings.{prefix}.model.{id}"), &r, name);
|
||||
if r.clicked() && !selected {
|
||||
acts.push(Act::Run("roto.model.select".into(), json!({"id": id})));
|
||||
acts.push(Act::Run(format!("{prefix}.model.select"), json!({"id": id})));
|
||||
}
|
||||
let classic = id == effectcraft_engine::segment::CLASSICAL;
|
||||
let state = match (active, installed, selected) {
|
||||
(true, _, _) => "In use",
|
||||
_ if classic => "Built in",
|
||||
(false, true, true) if busy.is_some() => "Loading…",
|
||||
(false, true, _) => "Installed",
|
||||
(false, false, true) => "Not installed: Roto Brush uses the classic engine",
|
||||
_ => "Not installed",
|
||||
(true, _, _) => "In use".to_string(),
|
||||
_ if classic => "Built in".to_string(),
|
||||
(false, true, true) if busy.is_some() => "Loading…".to_string(),
|
||||
(false, true, _) => "Installed".to_string(),
|
||||
(false, false, true) => format!("Not installed: {user} uses the classic engine"),
|
||||
_ => "Not installed".to_string(),
|
||||
};
|
||||
ui.label(RichText::new(state).color(if active { t.accent } else { t.text_dim }));
|
||||
});
|
||||
ui.label(RichText::new(m["description"].as_str().unwrap_or_default()).color(t.text_dim));
|
||||
if let Some(by) = m["authors"].as_str() {
|
||||
ui.label(RichText::new(format!("By {by}")).color(t.text_dim));
|
||||
}
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.label(RichText::new(format!("Licence: {}", m["licence"].as_str().unwrap_or_default())).color(t.text_dim));
|
||||
if let Some(size) = m["size"].as_u64() {
|
||||
ui.label(RichText::new(format!("· {}", human_bytes(size))).color(t.text_dim));
|
||||
}
|
||||
for (label, key) in [("Project page", "homepage"), ("Licence text", "licenceUrl")] {
|
||||
for (label, key) in [("Project page", "homepage"), ("Licence", "licenceUrl")] {
|
||||
if let Some(url) = m[key].as_str() {
|
||||
let r = ui.link(label);
|
||||
if r.clicked() {
|
||||
@@ -258,29 +265,29 @@ fn roto_models_ui(app: &mut EffectcraftApp, ui: &mut egui::Ui, t: &Tokens, acts:
|
||||
}
|
||||
}
|
||||
});
|
||||
if id == effectcraft_engine::segment::CLASSICAL {
|
||||
if classic {
|
||||
return;
|
||||
}
|
||||
ui.horizontal(|ui| {
|
||||
if !installed && !web {
|
||||
let r = ui.add_enabled(busy.is_none(), egui::Button::new("Download"));
|
||||
reg(app, &format!("settings.roto.download.{id}"), &r, "Download");
|
||||
reg(app, &format!("settings.{prefix}.download.{id}"), &r, "Download");
|
||||
if r.clicked() {
|
||||
acts.push(Act::Run("roto.model.download".into(), json!({"id": id})));
|
||||
acts.push(Act::Run(format!("{prefix}.model.download"), json!({"id": id})));
|
||||
}
|
||||
}
|
||||
if !web {
|
||||
let r = ui.add_enabled(busy.is_none(), egui::Button::new("Install from File…"));
|
||||
reg(app, &format!("settings.roto.install.{id}"), &r, "Install from File");
|
||||
reg(app, &format!("settings.{prefix}.install.{id}"), &r, "Install from File");
|
||||
if r.clicked() {
|
||||
acts.push(Act::PickModel);
|
||||
acts.push(Act::PickModel(task));
|
||||
}
|
||||
}
|
||||
if installed {
|
||||
let r = ui.add_enabled(busy.is_none(), egui::Button::new("Remove"));
|
||||
reg(app, &format!("settings.roto.remove.{id}"), &r, "Remove");
|
||||
reg(app, &format!("settings.{prefix}.remove.{id}"), &r, "Remove");
|
||||
if r.clicked() {
|
||||
acts.push(Act::Run("roto.model.remove".into(), json!({"id": id})));
|
||||
acts.push(Act::Run(format!("{prefix}.model.remove"), json!({"id": id})));
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -303,6 +310,8 @@ fn roto_models_ui(app: &mut EffectcraftApp, ui: &mut egui::Ui, t: &Tokens, acts:
|
||||
}
|
||||
}
|
||||
|
||||
/// Settings ▸ Disk ▸ Browser Storage (the web app's storage manager, `storage.*`): where the
|
||||
/// data lives, the origin's usage and quota, persistent storage, and Clear buttons.
|
||||
fn browser_storage_ui(app: &mut EffectcraftApp, ui: &mut egui::Ui, t: &Tokens, acts: &mut Vec<Act>) {
|
||||
let Some(host) = app.session.storage.clone() else { return };
|
||||
let info = host.info();
|
||||
@@ -513,10 +522,14 @@ pub fn show(app: &mut EffectcraftApp, ctx: &egui::Context, t: &Tokens) {
|
||||
app.session.prefs_changed();
|
||||
}
|
||||
}
|
||||
Act::PickModel => {
|
||||
let picked = app.hooks.pick_files.as_ref().map(|f| f(&["pt"])).unwrap_or_default();
|
||||
Act::PickModel(task) => {
|
||||
// The registry's file types for the task (`.pt`, `.task`).
|
||||
let mut exts: Vec<&str> = effectcraft_engine::segment::models(task).filter_map(|m| m.file_name.rsplit_once('.').map(|x| x.1)).collect();
|
||||
exts.dedup();
|
||||
let picked = app.hooks.pick_files.as_ref().map(|f| f(&exts)).unwrap_or_default();
|
||||
let cmd = if task == Task::Face { "face.model.install" } else { "roto.model.install" };
|
||||
if let Some(path) = picked.into_iter().next()
|
||||
&& let Err(e) = crate::menus::invoke(app, ctx, "roto.model.install", json!({"path": path}))
|
||||
&& let Err(e) = crate::menus::invoke(app, ctx, cmd, json!({"path": path}))
|
||||
{
|
||||
app.ui.status = e;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user