mirror of
https://github.com/shinyobjectz/raea.git
synced 2026-12-01 06:53:19 -10:00
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b6ff18517f | ||
|
|
5fc64c558a | ||
|
|
07553d4b18 |
No files matched your search
Generated
+1
@@ -13919,6 +13919,7 @@ dependencies = [
|
||||
name = "raea-app-motion"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"glam 0.33.12",
|
||||
"raea-io-home",
|
||||
"raea-runtime-bundle",
|
||||
"raea-sys-kimodo",
|
||||
|
||||
@@ -7,6 +7,8 @@ publish = false
|
||||
description = "`raea motion` and `raea setup motion`: body motion made by Kimodo on this machine, on MLX on a Mac, on PyTorch elsewhere"
|
||||
|
||||
[dependencies]
|
||||
# a take's joints as vectors (score.rs)
|
||||
glam = "0.33"
|
||||
# raea's models folder, where the models and the PyTorch environment go
|
||||
raea-io-home = { path = "../../io/home" }
|
||||
serde_json = "1"
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
//! `raea motion` without the rest of the CLI, for working on this crate while the workspace's other crates are mid-change:
|
||||
//! `lane build -- cargo run --release -p raea-app-motion --example motion -- "LINE" --seeds 4 -o CLIP.json`
|
||||
fn main() {
|
||||
let args: Vec<String> = std::iter::once("motion".to_string()).chain(std::env::args().skip(1)).collect();
|
||||
match raea_app_motion::motion(&args) {
|
||||
Ok(s) => println!("{s}"),
|
||||
Err(e) => {
|
||||
eprintln!("{e}");
|
||||
std::process::exit(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
+62
-19
@@ -9,12 +9,14 @@
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
mod score;
|
||||
|
||||
use raea_runtime_bundle::flag;
|
||||
|
||||
type R<T> = Result<T, String>;
|
||||
|
||||
pub const USAGE: &str = "raea motion \"LINE\" [--keys KEYS.json] [--seconds 5 | --frames N] [--seed 1] [--steps 100] [-o CLIP.json]";
|
||||
pub const ABOUT: &str = "body motion made on this machine by Kimodo (NVIDIA): a SOMA clip from a line of words and, with --keys, Kimodo constraints (full-body keyframes, hand or foot targets, a root path, as sdk/body/tools/between.ts writes them), as the clip sdk/body/tools/fromkimodo.ts reads. On a Mac it runs on MLX (Apple silicon's GPU): the first use fetches the motion model (1.1 GB) into raea's models folder, and the first new line its text encoder (8.8 GB: Llama 3 8B in 8 bits with LLM2Vec's adapters). On Linux and Windows it runs upstream Kimodo on PyTorch, set up once by raea setup motion: on an NVIDIA GPU with CUDA (the text encoder, 16 GB in bf16, on the CPU unless the card has 18 GB or more), else on the CPU alone; reading a new line on the CPU takes about 18 GB of memory. A line's words are read once and kept. Licences: Kimodo's weights NVIDIA's Open Model License, Meta Llama 3 the Meta Llama 3 Community License, LLM2Vec's adapters MIT, Kimodo's code Apache-2.0";
|
||||
pub const USAGE: &str = "raea motion \"LINE\" [--keys KEYS.json] [--seconds 5 | --frames N] [--seed 1] [--seeds 1] [--steps 100] [-o CLIP.json]";
|
||||
pub const ABOUT: &str = "body motion made on this machine by Kimodo (NVIDIA): a SOMA clip from a line of words and, with --keys, Kimodo constraints (full-body keyframes, hand or foot targets, a root path, as sdk/body/tools/between.ts writes them), as the clip sdk/body/tools/fromkimodo.ts reads. On a Mac it runs on MLX (Apple silicon's GPU): the first use fetches the motion model (1.1 GB) into raea's models folder, and the first new line its text encoder (8.8 GB: Llama 3 8B in 8 bits with LLM2Vec's adapters). On Linux and Windows it runs upstream Kimodo on PyTorch, set up once by raea setup motion: on an NVIDIA GPU with CUDA (the text encoder, 16 GB in bf16, on the CPU unless the card has 18 GB or more), else on the CPU alone; reading a new line on the CPU takes about 18 GB of memory. A line's words are read once and kept. --seeds N makes N takes (seeds SEED to SEED+N-1) and keeps the one with the fewest faults: a foot sliding while planted, the shoulders shrugging, the hips sinking, a hand or forearm into the torso or head (a skeletal check; each take's score is printed and the kept one's written into the clip). Licences: Kimodo's weights NVIDIA's Open Model License, Meta Llama 3 the Meta Llama 3 Community License, LLM2Vec's adapters MIT, Kimodo's code Apache-2.0";
|
||||
|
||||
pub const SETUP_USAGE: &str = "raea setup motion [--check]";
|
||||
pub const SETUP_ABOUT: &str = "what raea motion runs on, made where missing (--check only says): on a Mac the MLX models in raea's models folder (the motion model 1.1 GB, the text encoder 8.8 GB); on Linux and Windows, in raea's models folder's kimodo-torch, a Python 3.11 environment made by uv (which it needs on PATH: https://docs.astral.sh/uv) with PyTorch (its CUDA build where there is an NVIDIA driver, about 8 GB, else CPU only, about 2 GB) and upstream Kimodo (nv-tlabs/kimodo at e1c219c, Apache-2.0), then the weights: Kimodo-SOMA-RP-v1 (1.1 GB, NVIDIA Open Model License), LLM2Vec's two adapters (0.3 GB, MIT) and Meta Llama 3 8B Instruct in bf16 (16 GB, Meta Llama 3 Community License, from NousResearch's ungated copy, checked file by file against Meta's SHA-256); about 26 GB in all. It says what this machine has and where each network runs: the denoiser on CUDA when there is an NVIDIA GPU, else the CPU; the text encoder beside it on a GPU of 18 GB or more, else the CPU";
|
||||
@@ -27,7 +29,7 @@ fn number(args: &[String], name: &str, default: f64) -> R<f64> {
|
||||
}
|
||||
|
||||
fn line(args: &[String]) -> String {
|
||||
const WITH_VALUE: [&str; 6] = ["--keys", "--seconds", "--frames", "--seed", "--steps", "-o"];
|
||||
const WITH_VALUE: [&str; 7] = ["--keys", "--seconds", "--frames", "--seed", "--seeds", "--steps", "-o"];
|
||||
let mut out = Vec::new();
|
||||
let mut i = 1;
|
||||
while i < args.len() {
|
||||
@@ -50,6 +52,7 @@ struct Ask {
|
||||
constraints: Option<serde_json::Value>,
|
||||
frames: usize,
|
||||
seed: u64,
|
||||
seeds: usize,
|
||||
steps: usize,
|
||||
out: Option<String>,
|
||||
}
|
||||
@@ -64,15 +67,21 @@ pub fn motion(args: &[String]) -> R<String> {
|
||||
Some(_) => number(args, "--frames", 150.0)? as usize,
|
||||
None => (number(args, "--seconds", 5.0)? * 30.0).round() as usize,
|
||||
};
|
||||
if !(2..=600).contains(&frames) {
|
||||
return Err(format!("a clip is 2 to 600 frames (20 s at 30 a second), asked {frames}"));
|
||||
// Kimodo's own limit (its docs, key_concepts/limitations.md): past 10 s a clip drifts and breaks up (11-27: a
|
||||
// 12.3 s talk clip's feet spread 47 -> 69 cm, shoulders rose 9 cm, the last half second glitched)
|
||||
if !(2..=300).contains(&frames) {
|
||||
return Err(format!(
|
||||
"a clip is 2 to 300 frames (10 s at 30 a second, Kimodo's limit: longer clips drift and break up), asked {frames}; \
|
||||
for longer, make 10 s clips one after another, each from --keys holding the last frames of the one before"
|
||||
));
|
||||
}
|
||||
let constraints = match &keys {
|
||||
Some(p) => Some(serde_json::from_str::<serde_json::Value>(&std::fs::read_to_string(p).map_err(|e| format!("{p}: {e}"))?).map_err(|e| format!("{p}: {e}"))?),
|
||||
None => None,
|
||||
};
|
||||
let (seed, steps) = (number(args, "--seed", 1.0)? as u64, (number(args, "--steps", 100.0)? as usize).max(2));
|
||||
make(Ask { words, keys, constraints, frames, seed, steps, out: flag(args, "-o") })
|
||||
let seeds = (number(args, "--seeds", 1.0)? as usize).clamp(1, 32);
|
||||
make(Ask { words, keys, constraints, frames, seed, seeds, steps, out: flag(args, "-o") })
|
||||
}
|
||||
|
||||
/// -o, else a file named by the line's words in the working folder
|
||||
@@ -83,6 +92,25 @@ fn out_path(out: Option<String>, clean: &str) -> PathBuf {
|
||||
}))
|
||||
}
|
||||
|
||||
/// the take with the lowest score of those made, its seed, and a line per take ("" for a single take)
|
||||
fn keep_best(takes: Vec<(u64, raea_sys_kimodo::decode::Motion)>, sk: &raea_sys_kimodo::skeleton::Skeleton) -> (u64, raea_sys_kimodo::decode::Motion, Option<score::Score>, String) {
|
||||
let one = takes.len() == 1;
|
||||
let mut scored: Vec<(u64, raea_sys_kimodo::decode::Motion, score::Score)> = takes.into_iter().map(|(s, m)| { let sc = score::score(&m, sk); (s, m, sc) }).collect();
|
||||
let report = if one { String::new() } else { scored.iter().map(|(s, _, sc)| format!("\n seed {s}: {}", sc.line())).collect::<String>() };
|
||||
scored.sort_by(|a, b| a.2.total.total_cmp(&b.2.total));
|
||||
let (s, m, sc) = scored.remove(0);
|
||||
(s, m, Some(sc), report)
|
||||
}
|
||||
|
||||
/// the kept take's score, written into the clip
|
||||
fn with_score(mut clip: serde_json::Value, sc: &Option<score::Score>, tried: usize) -> serde_json::Value {
|
||||
if let Some(sc) = sc {
|
||||
clip["score"] = serde_json::json!({"total": sc.total, "foot_drift_cm": sc.foot_drift_cm, "shoulder_rise_cm": sc.shoulder_rise_cm,
|
||||
"hip_drop_cm": sc.hip_drop_cm, "collision_cm": sc.collision_cm, "takes": tried});
|
||||
}
|
||||
clip
|
||||
}
|
||||
|
||||
/// how far the hips end from where they start, on the ground
|
||||
fn travel(m: &raea_sys_kimodo::decode::Motion) -> f32 {
|
||||
let r = &m.root;
|
||||
@@ -109,10 +137,17 @@ fn make(ask: Ask) -> R<String> {
|
||||
));
|
||||
}
|
||||
let keys = ask.keys.as_ref().map(std::path::Path::new);
|
||||
let job = torch::Job { line: &ask.words, frames: ask.frames, seed: ask.seed, steps: ask.steps, keys, cfg: (2.0, 2.0) };
|
||||
let made = t.make(&job).map_err(|e| format!("raea motion: {e}"))?;
|
||||
let (stats, sk) = (Stats::load(&t.checkpoint).map_err(|e| format!("raea motion: {e}"))?, Skeleton::soma().map_err(|e| format!("raea motion: {e}"))?);
|
||||
let motion = decode::decode(&made.features, &stats, &sk);
|
||||
let mut takes = Vec::new();
|
||||
let mut last = None;
|
||||
for s in ask.seed..ask.seed + ask.seeds as u64 {
|
||||
let job = torch::Job { line: &ask.words, frames: ask.frames, seed: s, steps: ask.steps, keys, cfg: (2.0, 2.0) };
|
||||
let made = t.make(&job).map_err(|e| format!("raea motion: {e}"))?;
|
||||
takes.push((s, decode::decode(&made.features, &stats, &sk)));
|
||||
last = Some(made);
|
||||
}
|
||||
let made = last.ok_or("raea motion: no take")?;
|
||||
let (seed, motion, sc, report) = keep_best(takes, &sk);
|
||||
let info = &made.info;
|
||||
let clean = info["line"].as_str().unwrap_or(&ask.words).to_string();
|
||||
let (dev, text_dev) = (info["motion"].as_str().unwrap_or("?"), info["text"].as_str().unwrap_or("?"));
|
||||
@@ -120,26 +155,28 @@ fn make(ask: Ask) -> R<String> {
|
||||
Some(g) => format!("on PyTorch {} with CUDA ({g}; the text encoder on {text_dev}), upstream nv-tlabs/kimodo {}", info["torch"].as_str().unwrap_or("?"), &torch::KIMODO[..7]),
|
||||
None => format!("on PyTorch {} on the CPU, upstream nv-tlabs/kimodo {}", info["torch"].as_str().unwrap_or("?"), &torch::KIMODO[..7]),
|
||||
};
|
||||
let clip = decode::clip_json_on(&motion, &sk, ask.seed, ask.steps, &clean, ask.constraints.is_some(), &on);
|
||||
let clip = with_score(decode::clip_json_on(&motion, &sk, seed, ask.steps, &clean, ask.constraints.is_some(), &on), &sc, ask.seeds);
|
||||
let out = out_path(ask.out, &clean);
|
||||
std::fs::write(&out, serde_json::to_string(&clip).unwrap_or_default()).map_err(|e| format!("{}: {e}", out.display()))?;
|
||||
// the hips as PyTorch decoded them against decode.rs's: the features were read as Kimodo wrote them
|
||||
let ours: Vec<[f32; 3]> = motion.joints77.iter().map(|f| f[0]).collect();
|
||||
let gap = torch::root_gap(&info["root"], &ours).map(|g| format!(", decoded here within {:.3} mm of PyTorch's own", g * 1000.0)).unwrap_or_default();
|
||||
let gap = if ask.seeds > 1 { String::new() } else { torch::root_gap(&info["root"], &ours).map(|g| format!(", decoded here within {:.3} mm of PyTorch's own", g * 1000.0)).unwrap_or_default() };
|
||||
let f = |k: &str| info[k].as_f64().unwrap_or(0.0);
|
||||
let read = if f("read_s") > 0.0 { format!(", reading the line {:.1} s after {:.1} s loading its encoder", f("read_s"), f("text_load_s")) } else { String::new() };
|
||||
Ok(format!(
|
||||
"APPLIED motion {:?}{}, {} frames ({:.1} s), seed {}, {} steps -> {} (made {on} in {:.1} s after {:.1} s loading{read}; the hips end {:.2} m from where they start{gap})",
|
||||
"APPLIED motion {:?}{}, {} frames ({:.1} s), seed {}{}, {} steps -> {} (made {on} in {:.1} s after {:.1} s loading{read}; the hips end {:.2} m from where they start{gap}; {}){report}",
|
||||
clean,
|
||||
if ask.keys.is_some() { " with keys" } else { "" },
|
||||
ask.frames,
|
||||
ask.frames as f64 / 30.0,
|
||||
ask.seed,
|
||||
seed,
|
||||
if ask.seeds > 1 { format!(", the best of {} takes", ask.seeds) } else { String::new() },
|
||||
ask.steps,
|
||||
out.display(),
|
||||
f("gen_s"),
|
||||
f("load_s"),
|
||||
travel(&motion),
|
||||
sc.as_ref().map(|s| s.line()).unwrap_or_default(),
|
||||
))
|
||||
}
|
||||
|
||||
@@ -154,23 +191,29 @@ fn make(ask: Ask) -> R<String> {
|
||||
let mut k = raea_sys_kimodo::Kimodo::fetch(&mut progress).map_err(|e| format!("raea motion: {e}"))?;
|
||||
let (clean, emb) = k.encode(&ask.words).map_err(|e| format!("raea motion: {e}"))?;
|
||||
let load_s = t0.elapsed().as_secs_f64();
|
||||
let made_from = raea_sys_kimodo::Ask { line: &ask.words, frames: ask.frames, seed: ask.seed, steps: ask.steps, constraints: ask.constraints.as_ref(), cfg: (2.0, 2.0) };
|
||||
let t1 = std::time::Instant::now();
|
||||
let made = k.make(&made_from, emb.as_deref(), None).map_err(|e| format!("raea motion: {e}"))?;
|
||||
let mut takes = Vec::new();
|
||||
for s in ask.seed..ask.seed + ask.seeds as u64 {
|
||||
let made_from = raea_sys_kimodo::Ask { line: &ask.words, frames: ask.frames, seed: s, steps: ask.steps, constraints: ask.constraints.as_ref(), cfg: (2.0, 2.0) };
|
||||
takes.push((s, k.make(&made_from, emb.as_deref(), None).map_err(|e| format!("raea motion: {e}"))?.motion));
|
||||
}
|
||||
let gen_s = t1.elapsed().as_secs_f64();
|
||||
let clip = raea_sys_kimodo::decode::clip_json(&made.motion, &k.skeleton, ask.seed, ask.steps, &clean, ask.constraints.is_some());
|
||||
let (seed, motion, sc, report) = keep_best(takes, &k.skeleton);
|
||||
let clip = with_score(raea_sys_kimodo::decode::clip_json(&motion, &k.skeleton, seed, ask.steps, &clean, ask.constraints.is_some()), &sc, ask.seeds);
|
||||
let out = out_path(ask.out, &clean);
|
||||
std::fs::write(&out, serde_json::to_string(&clip).unwrap_or_default()).map_err(|e| format!("{}: {e}", out.display()))?;
|
||||
Ok(format!(
|
||||
"APPLIED motion {:?}{}, {} frames ({:.1} s), seed {}, {} steps -> {} (made on this Mac in {gen_s:.1} s after {load_s:.1} s loading and reading the line; the hips end {:.2} m from where they start)",
|
||||
"APPLIED motion {:?}{}, {} frames ({:.1} s), seed {}{}, {} steps -> {} (made on this Mac in {gen_s:.1} s after {load_s:.1} s loading and reading the line; the hips end {:.2} m from where they start; {}){report}",
|
||||
clean,
|
||||
if ask.keys.is_some() { " with keys" } else { "" },
|
||||
ask.frames,
|
||||
ask.frames as f64 / 30.0,
|
||||
ask.seed,
|
||||
seed,
|
||||
if ask.seeds > 1 { format!(", the best of {} takes", ask.seeds) } else { String::new() },
|
||||
ask.steps,
|
||||
out.display(),
|
||||
travel(&made.motion)
|
||||
travel(&motion),
|
||||
sc.as_ref().map(|s| s.line()).unwrap_or_default(),
|
||||
))
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
//! A take scored for the faults a body shows (sheet3d plan E3), so `raea motion --seeds N` can keep the best of N:
|
||||
//! a foot sliding while it's planted, the shoulders shrugging up, the hips sinking, and a hand or forearm inside the
|
||||
//! torso or head. Read from the take's own joints (Kimodo's SOMA skeleton, metres, Y up) and its foot contacts.
|
||||
//! Collision is a skeletal proxy: capsules round the spine and a sphere for the head, sized for SOMA's average adult;
|
||||
//! the mesh check on the body a clip drives is the join's (sheet3d's join.py: head-in-body frames).
|
||||
|
||||
use raea_sys_kimodo::decode::Motion;
|
||||
use raea_sys_kimodo::skeleton::Skeleton;
|
||||
|
||||
use glam::Vec3;
|
||||
|
||||
/// each fault in centimetres (collision: the deepest a hand or forearm point goes into the torso or head), and
|
||||
/// their sum, each over its own allowance: 1 cm of drift, 3 cm of shrug, 5 cm of sinking, 1 cm into the body
|
||||
pub struct Score {
|
||||
pub foot_drift_cm: f32,
|
||||
pub shoulder_rise_cm: f32,
|
||||
pub hip_drop_cm: f32,
|
||||
pub collision_cm: f32,
|
||||
pub total: f32,
|
||||
}
|
||||
|
||||
fn idx(sk: &Skeleton, n: &str) -> usize {
|
||||
sk.names77.iter().position(|x| x == n).unwrap_or(0)
|
||||
}
|
||||
|
||||
/// how far p is inside the capsule a-b of radius r (0 outside)
|
||||
fn inside(p: [f32; 3], a: [f32; 3], b: [f32; 3], r: f32) -> f32 {
|
||||
let (p, a, b) = (Vec3::from(p), Vec3::from(a), Vec3::from(b));
|
||||
let ab = b - a;
|
||||
let t = ((p - a).dot(ab) / ab.length_squared().max(1e-9)).clamp(0.0, 1.0);
|
||||
(r - p.distance(a + t * ab)).max(0.0)
|
||||
}
|
||||
|
||||
fn median(mut v: Vec<f32>) -> f32 {
|
||||
if v.is_empty() {
|
||||
return 0.0;
|
||||
}
|
||||
v.sort_by(|a, b| a.total_cmp(b));
|
||||
v[v.len() / 2]
|
||||
}
|
||||
|
||||
pub fn score(m: &Motion, sk: &Skeleton) -> Score {
|
||||
let j = &m.joints77;
|
||||
let n = j.len();
|
||||
// a foot planted: its horizontal travel over each run of contact frames, the worst run
|
||||
let feet = [("LeftFoot", 0), ("LeftToeBase", 1), ("RightFoot", 3), ("RightToeBase", 4)];
|
||||
let mut drift = 0f32;
|
||||
for (name, c) in feet {
|
||||
let k = idx(sk, name);
|
||||
let mut start: Option<usize> = None;
|
||||
for f in 0..=n {
|
||||
let on = f < n && m.contacts[f][c];
|
||||
match (on, start) {
|
||||
(true, None) => start = Some(f),
|
||||
(false, Some(s)) => {
|
||||
let mut far = 0f32;
|
||||
for g in s..f {
|
||||
let d = Vec3::from(j[g][k]) - Vec3::from(j[s][k]);
|
||||
far = far.max(d.x.hypot(d.z));
|
||||
}
|
||||
drift = drift.max(far);
|
||||
start = None;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
// shoulders above the chest: the highest against the take's own usual, both sides
|
||||
let chest = idx(sk, "Chest");
|
||||
let mut rise = 0f32;
|
||||
for s in ["LeftShoulder", "RightShoulder"] {
|
||||
let k = idx(sk, s);
|
||||
let h: Vec<f32> = j.iter().map(|f| f[k][1] - f[chest][1]).collect();
|
||||
let med = median(h.clone());
|
||||
rise = rise.max(h.iter().fold(f32::MIN, |a, &b| a.max(b)) - med);
|
||||
}
|
||||
// hips below where they stand: the lowest against the first second's median
|
||||
let hips = idx(sk, "Hips");
|
||||
let stand = median(j.iter().take(30).map(|f| f[hips][1]).collect());
|
||||
let drop = (stand - j.iter().fold(f32::MAX, |a, f| a.min(f[hips][1]))).max(0.0);
|
||||
// hands and forearms against the torso (hips to chest, chest to neck) and the head
|
||||
let (spine1, neck, head) = (idx(sk, "Spine1"), idx(sk, "Neck1"), idx(sk, "Head"));
|
||||
let limbs: Vec<usize> = ["LeftHand", "RightHand", "LeftHandMiddle1", "RightHandMiddle1"].iter().map(|x| idx(sk, x)).collect();
|
||||
let fore = [("LeftArm", "LeftForeArm", "LeftHand"), ("RightArm", "RightForeArm", "RightHand")];
|
||||
let mut deep = 0f32;
|
||||
for f in j {
|
||||
let mut pts: Vec<[f32; 3]> = limbs.iter().map(|&k| f[k]).collect();
|
||||
for (_, e, h) in fore {
|
||||
let (a, b) = (f[idx(sk, e)], f[idx(sk, h)]);
|
||||
pts.push([(a[0] + b[0]) / 2.0, (a[1] + b[1]) / 2.0, (a[2] + b[2]) / 2.0]);
|
||||
}
|
||||
for p in pts {
|
||||
let d = inside(p, f[hips], f[spine1], 0.12)
|
||||
.max(inside(p, f[spine1], f[chest], 0.13))
|
||||
.max(inside(p, f[chest], f[neck], 0.11))
|
||||
.max(inside(p, f[head], f[head], 0.09));
|
||||
deep = deep.max(d);
|
||||
}
|
||||
}
|
||||
let (d, r, h, c) = (drift * 100.0, rise * 100.0, drop * 100.0, deep * 100.0);
|
||||
Score { foot_drift_cm: d, shoulder_rise_cm: r, hip_drop_cm: h, collision_cm: c, total: d / 1.0 + r / 3.0 + h / 5.0 + c / 1.0 }
|
||||
}
|
||||
|
||||
impl Score {
|
||||
pub fn line(&self) -> String {
|
||||
format!(
|
||||
"score {:.2} (foot drift {:.1} cm, shoulder rise {:.1} cm, hip drop {:.1} cm, hand into body {:.1} cm)",
|
||||
self.total, self.foot_drift_cm, self.shoulder_rise_cm, self.hip_drop_cm, self.collision_cm
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ Body motion made on this machine by Kimodo (NVIDIA), on MLX on a Mac and on PyTo
|
||||
## Usage
|
||||
|
||||
```sh
|
||||
raea motion "LINE" [--keys KEYS.json] [--seconds 5 | --frames N] [--seed 1] [--steps 100] [-o CLIP.json] (body motion made on this machine by Kimodo (NVIDIA): a SOMA clip from a line of words and, with --keys, Kimodo constraints (full-body keyframes, hand or foot targets, a root path, as sdk/body/tools/between.ts writes them), as the clip sdk/body/tools/fromkimodo.ts reads. On a Mac it runs on MLX (Apple silicon's GPU): the first use fetches the motion model (1.1 GB) into raea's models folder, and the first new line its text encoder (8.8 GB: Llama 3 8B in 8 bits with LLM2Vec's adapters). On Linux and Windows it runs upstream Kimodo on PyTorch, set up once by raea setup motion: on an NVIDIA GPU with CUDA (the text encoder, 16 GB in bf16, on the CPU unless the card has 18 GB or more), else on the CPU alone; reading a new line on the CPU takes about 18 GB of memory. A line's words are read once and kept. Licences: Kimodo's weights NVIDIA's Open Model License, Meta Llama 3 the Meta Llama 3 Community License, LLM2Vec's adapters MIT, Kimodo's code Apache-2.0)
|
||||
raea motion "LINE" [--keys KEYS.json] [--seconds 5 | --frames N] [--seed 1] [--seeds 1] [--steps 100] [-o CLIP.json] (body motion made on this machine by Kimodo (NVIDIA): a SOMA clip from a line of words and, with --keys, Kimodo constraints (full-body keyframes, hand or foot targets, a root path, as sdk/body/tools/between.ts writes them), as the clip sdk/body/tools/fromkimodo.ts reads. On a Mac it runs on MLX (Apple silicon's GPU): the first use fetches the motion model (1.1 GB) into raea's models folder, and the first new line its text encoder (8.8 GB: Llama 3 8B in 8 bits with LLM2Vec's adapters). On Linux and Windows it runs upstream Kimodo on PyTorch, set up once by raea setup motion: on an NVIDIA GPU with CUDA (the text encoder, 16 GB in bf16, on the CPU unless the card has 18 GB or more), else on the CPU alone; reading a new line on the CPU takes about 18 GB of memory. A line's words are read once and kept. --seeds N makes N takes (seeds SEED to SEED+N-1) and keeps the one with the fewest faults: a foot sliding while planted, the shoulders shrugging, the hips sinking, a hand or forearm into the torso or head (a skeletal check; each take's score is printed and the kept one's written into the clip). Licences: Kimodo's weights NVIDIA's Open Model License, Meta Llama 3 the Meta Llama 3 Community License, LLM2Vec's adapters MIT, Kimodo's code Apache-2.0)
|
||||
```
|
||||
|
||||
Headless: it needs nothing running and opens no window. Takes up to 1 argument besides its flags.
|
||||
@@ -21,10 +21,11 @@ Headless: it needs nothing running and opens no window. Takes up to 1 argument b
|
||||
|
||||
| Flag | Takes | What it does |
|
||||
| --- | --- | --- |
|
||||
| `--frames` | `N` | The clip's length in frames at 30 a second, 2 to 600. Instead of `--seconds`. |
|
||||
| `--frames` | `N` | The clip's length in frames at 30 a second, 2 to 300 (10 s, Kimodo's limit: longer clips drift and break up; chain 10 s clips through `--keys` instead). Instead of `--seconds`. |
|
||||
| `--keys` | `KEYS.json` | Kimodo constraints the motion must meet: full-body keyframes, a hand or foot at a place on a frame, a path for the hips. `bun sdk/body/tools/between.ts` writes them between two poses of the body library. |
|
||||
| `--seconds` | `5` | The clip's length in seconds (5 unless said). |
|
||||
| `--seed` | `1` | Which of the motions the line could be: another seed is another take of the same line. A seed on MLX is not that seed on PyTorch (the noise is drawn differently), so the same seed is a different take on a Mac and on Linux or Windows. |
|
||||
| `--seeds` | `1` | How many takes to make, seeds `--seed` up: the one with the lowest score is kept and its score written into the clip (`score`: foot drift while a foot is planted, shoulder rise above the take's usual, hip drop below standing, and how far a hand or forearm goes into the torso or head, in cm, summed over allowances of 1, 3, 5 and 1 cm). The collision is a skeletal check, capsules sized for SOMA's average adult, not the body's mesh. |
|
||||
| `--steps` | `100` | Denoising steps (Kimodo's 100). Fewer is faster and rougher. |
|
||||
| `-o` | `CLIP.json` | Where the clip goes: `{fps, names, root, turns, contacts, ...}`, Kimodo's 77 SOMA joints as each one's turn in the world from the T-pose. Without it, the line's words name the file in the working folder. |
|
||||
|
||||
@@ -40,6 +41,16 @@ bun sdk/body/tools/between.ts skeleton.json LIBDIR aMale2_A1_Stand:0 aMale2_A1_S
|
||||
raea motion "A person waves at the camera with their right hand" --keys stand.json --seconds 4 --seed 2 -o wave.clip.json
|
||||
```
|
||||
|
||||
The best of four takes of a line, by the faults a body would show:
|
||||
|
||||
```sh
|
||||
raea motion "A person stands in place and talks, gesturing with both hands" --seconds 10 --seeds 4 -o talk.clip.json
|
||||
```
|
||||
|
||||
Longer than 10 s, make 10 s clips one after another, each with `--keys` holding the last second of the one before as
|
||||
full-body keyframes, and ease each into the next over those frames: Kimodo keeps full-body keys to a few centimetres,
|
||||
not exactly, so a clip cut straight onto the next would jump.
|
||||
|
||||
A clip takes about 8 seconds on an M5 Pro. `bun sdk/body/tools/makedo.ts` does the whole of it for a stage's lines:
|
||||
three seeds a line, each checked against the captures the body hands on to, and the one that does the most kept in the
|
||||
project's made clips.
|
||||
|
||||
Reference in new issue
Block a user