Skip to content

armgit / fuobe

Public Imported from GitHub
0

The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.

Evaluation: a Character swap in 2K suite scoring identity and background change against the source, with the start noise to try

Claude55339ec6cfe2
diff --git a/scripts/eval/cases/case.schema.json b/scripts/eval/cases/case.schema.json
index 98662c7d..5ff29527 100644
--- a/scripts/eval/cases/case.schema.json
+++ b/scripts/eval/cases/case.schema.json
@@ -541,7 +541,8 @@
"temporal",
"lipsync",
"continuity",
- "palette"
+ "palette",
+ "background"
]
}
},
@@ -1285,7 +1286,8 @@
"temporal",
"lipsync",
"continuity",
- "palette"
+ "palette",
+ "background"
]
}
},
diff --git a/scripts/eval/cases/character-2k.json b/scripts/eval/cases/character-2k.json
new file mode 100644
index 00000000..ccb2eb2b
--- /dev/null
+++ b/scripts/eval/cases/character-2k.json
@@ -0,0 +1,377 @@
+{
+ "$schema": "./case.schema.json",
+ "suite": "character-2k",
+ "title": "Fuobe Character swap in 2K · the regenerate's start noise",
+ "description": "The Character swap at 1080p / 2K / 4K (package n7-4-character-swap-2k, src/lib/catalog/sharpen.ts) on Genjutsu's route (POST /api/genjutsu), on your clip and character in local/genjutsu/: person.mp4 (5–15 s, one continuous shot, at least 1080p, the person visible in its first frame) and character.png (a consenting person or a drawn character). On your GPU the 768p swap is redrawn by Open-H3 Regenerate and only the character is composited back over the footage; each case tries one start noise (character.sharpenSigma: 0.7, 0.8 or the release's 0.909) against the 768p swap. In the cloud fal's H3 makes 2K itself (no start noise), for reference. Scores: identity (the face against the character picture: does the redraw keep who they are?), background (the frame's outer ring against the source clip: does the background stay as filmed?) and temporal (flicker). Needs a GPU ComfyUI with OPEN_H3_REGEN=1 and H3_RELAY=1 for the open cases.",
+ "original": [
+ "fuobe-character-swap"
+ ],
+ "kind": "video",
+ "decides": "The default start noise of the Character swap's 2K finish on your GPU (SHARPEN_SIGMA in src/lib/catalog/sharpen.ts, now 0.8). In one open run on at least 3 clips, the sigma whose identity is highest within 0.01 of the 768p swap's, with bgDiff within 0.002 of the best, becomes the default in a reviewed change; a tie keeps 0.8. A sigma whose identity falls more than 0.03 below the 768p swap is never the default.",
+ "targets": {
+ "open": {
+ "models": [
+ "fuobe-character-swap"
+ ]
+ },
+ "cloud": {
+ "models": [
+ "fuobe-character-swap"
+ ]
+ },
+ "demo": {
+ "models": [
+ "fuobe-character-swap"
+ ]
+ }
+ },
+ "defaults": {
+ "seeds": [
+ 1001,
+ 2002
+ ],
+ "metrics": [
+ "identity",
+ "background",
+ "temporal"
+ ],
+ "timeoutSeconds": 3600,
+ "candidate": "original"
+ },
+ "variants": {
+ "original": {
+ "description": "The Character swap as Genjutsu runs it"
+ }
+ },
+ "cases": [
+ {
+ "id": "character-2k/768p",
+ "title": "The 768p swap alone: the baseline every finish is compared with",
+ "models": {
+ "open": [
+ "fuobe-character-swap"
+ ],
+ "cloud": [
+ "fuobe-character-swap"
+ ],
+ "demo": [
+ "fuobe-character-swap"
+ ]
+ },
+ "inputs": {
+ "video": "local/genjutsu/person.mp4",
+ "images": [
+ "local/genjutsu/character.png"
+ ]
+ },
+ "demoInputs": {
+ "video": "fixtures/walk-6s.mp4",
+ "images": [
+ "fixtures/character/drawn-face-2.png"
+ ]
+ },
+ "prompts": [
+ {
+ "id": "direction",
+ "text": "keep the walk and the timing; the character wears the same clothes as in the picture"
+ }
+ ],
+ "references": "local/genjutsu/character.png",
+ "metrics": [
+ "identity",
+ "background",
+ "temporal"
+ ],
+ "submit": {
+ "route": "/api/genjutsu",
+ "body": {
+ "engine": "{{engine}}",
+ "mode": "character",
+ "modelId": "{{modelId}}",
+ "prompt": "{{prompt}}",
+ "references": [
+ "{{inputs.images.0}}"
+ ],
+ "source": "{{source:inputs.video}}",
+ "range": {
+ "start": 0,
+ "end": 5
+ },
+ "quality": "768p",
+ "character": {
+ "who": "largest"
+ },
+ "seed": "{{seed}}",
+ "requestId": "{{requestId}}"
+ }
+ }
+ },
+ {
+ "id": "character-2k/sigma-07",
+ "title": "2K on your GPU at start noise 0.7 (Close: stays nearest the swap)",
+ "models": {
+ "open": [
+ "fuobe-character-swap"
+ ],
+ "cloud": [
+ "fuobe-character-swap"
+ ],
+ "demo": [
+ "fuobe-character-swap"
+ ]
+ },
+ "inputs": {
+ "video": "local/genjutsu/person.mp4",
+ "images": [
+ "local/genjutsu/character.png"
+ ]
+ },
+ "demoInputs": {
+ "video": "fixtures/walk-6s.mp4",
+ "images": [
+ "fixtures/character/drawn-face-2.png"
+ ]
+ },
+ "prompts": [
+ {
+ "id": "direction",
+ "text": "keep the walk and the timing; the character wears the same clothes as in the picture"
+ }
+ ],
+ "references": "local/genjutsu/character.png",
+ "metrics": [
+ "identity",
+ "background",
+ "temporal"
+ ],
+ "submit": {
+ "route": "/api/genjutsu",
+ "body": {
+ "engine": "{{engine}}",
+ "mode": "character",
+ "modelId": "{{modelId}}",
+ "prompt": "{{prompt}}",
+ "references": [
+ "{{inputs.images.0}}"
+ ],
+ "source": "{{source:inputs.video}}",
+ "range": {
+ "start": 0,
+ "end": 5
+ },
+ "quality": "2K",
+ "character": {
+ "who": "largest",
+ "sharpenSigma": 0.7
+ },
+ "seed": "{{seed}}",
+ "requestId": "{{requestId}}"
+ }
+ },
+ "engines": [
+ "open",
+ "demo"
+ ]
+ },
+ {
+ "id": "character-2k/sigma-08",
+ "title": "2K on your GPU at start noise 0.8 (the default)",
+ "models": {
+ "open": [
+ "fuobe-character-swap"
+ ],
+ "cloud": [
+ "fuobe-character-swap"
+ ],
+ "demo": [
+ "fuobe-character-swap"
+ ]
+ },
+ "inputs": {
+ "video": "local/genjutsu/person.mp4",
+ "images": [
+ "local/genjutsu/character.png"
+ ]
+ },
+ "demoInputs": {
+ "video": "fixtures/walk-6s.mp4",
+ "images": [
+ "fixtures/character/drawn-face-2.png"
+ ]
+ },
+ "prompts": [
+ {
+ "id": "direction",
+ "text": "keep the walk and the timing; the character wears the same clothes as in the picture"
+ }
+ ],
+ "references": "local/genjutsu/character.png",
+ "metrics": [
+ "identity",
+ "background",
+ "temporal"
+ ],
+ "submit": {
+ "route": "/api/genjutsu",
+ "body": {
+ "engine": "{{engine}}",
+ "mode": "character",
+ "modelId": "{{modelId}}",
+ "prompt": "{{prompt}}",
+ "references": [
+ "{{inputs.images.0}}"
+ ],
+ "source": "{{source:inputs.video}}",
+ "range": {
+ "start": 0,
+ "end": 5
+ },
+ "quality": "2K",
+ "character": {
+ "who": "largest",
+ "sharpenSigma": 0.8
+ },
+ "seed": "{{seed}}",
+ "requestId": "{{requestId}}"
+ }
+ },
+ "engines": [
+ "open",
+ "demo"
+ ]
+ },
+ {
+ "id": "character-2k/sigma-0909",
+ "title": "2K on your GPU at the release's start noise 0.909 (redraws the most; a face can drift)",
+ "models": {
+ "open": [
+ "fuobe-character-swap"
+ ],
+ "cloud": [
+ "fuobe-character-swap"
+ ],
+ "demo": [
+ "fuobe-character-swap"
+ ]
+ },
+ "inputs": {
+ "video": "local/genjutsu/person.mp4",
+ "images": [
+ "local/genjutsu/character.png"
+ ]
+ },
+ "demoInputs": {
+ "video": "fixtures/walk-6s.mp4",
+ "images": [
+ "fixtures/character/drawn-face-2.png"
+ ]
+ },
+ "prompts": [
+ {
+ "id": "direction",
+ "text": "keep the walk and the timing; the character wears the same clothes as in the picture"
+ }
+ ],
+ "references": "local/genjutsu/character.png",
+ "metrics": [
+ "identity",
+ "background",
+ "temporal"
+ ],
+ "submit": {
+ "route": "/api/genjutsu",
+ "body": {
+ "engine": "{{engine}}",
+ "mode": "character",
+ "modelId": "{{modelId}}",
+ "prompt": "{{prompt}}",
+ "references": [
+ "{{inputs.images.0}}"
+ ],
+ "source": "{{source:inputs.video}}",
+ "range": {
+ "start": 0,
+ "end": 5
+ },
+ "quality": "2K",
+ "character": {
+ "who": "largest",
+ "sharpenSigma": 0.909
+ },
+ "seed": "{{seed}}",
+ "requestId": "{{requestId}}"
+ }
+ },
+ "engines": [
+ "open",
+ "demo"
+ ]
+ },
+ {
+ "id": "character-2k/cloud-2k",
+ "title": "2K in the cloud: fal's H3 makes it from a 768P base (the whole frame is redrawn)",
+ "models": {
+ "open": [
+ "fuobe-character-swap"
+ ],
+ "cloud": [
+ "fuobe-character-swap"
+ ],
+ "demo": [
+ "fuobe-character-swap"
+ ]
+ },
+ "inputs": {
+ "video": "local/genjutsu/person.mp4",
+ "images": [
+ "local/genjutsu/character.png"
+ ]
+ },
+ "demoInputs": {
+ "video": "fixtures/walk-6s.mp4",
+ "images": [
+ "fixtures/character/drawn-face-2.png"
+ ]
+ },
+ "prompts": [
+ {
+ "id": "direction",
+ "text": "keep the walk and the timing; the character wears the same clothes as in the picture"
+ }
+ ],
+ "references": "local/genjutsu/character.png",
+ "metrics": [
+ "identity",
+ "background",
+ "temporal"
+ ],
+ "submit": {
+ "route": "/api/genjutsu",
+ "body": {
+ "engine": "{{engine}}",
+ "mode": "character",
+ "modelId": "{{modelId}}",
+ "prompt": "{{prompt}}",
+ "references": [
+ "{{inputs.images.0}}"
+ ],
+ "source": "{{source:inputs.video}}",
+ "range": {
+ "start": 0,
+ "end": 5
+ },
+ "quality": "2K",
+ "character": {
+ "who": "largest"
+ },
+ "seed": "{{seed}}",
+ "requestId": "{{requestId}}"
+ }
+ },
+ "engines": [
+ "cloud"
+ ],
+ "note": "The cloud has no composite: expect a higher bgDiff than your GPU's cases"
+ }
+ ]
+}
diff --git a/scripts/eval/lib/metric-info.mjs b/scripts/eval/lib/metric-info.mjs
index dfa2b320..09dab87e 100644
--- a/scripts/eval/lib/metric-info.mjs
+++ b/scripts/eval/lib/metric-info.mjs
@@ -18,6 +18,8 @@ export const METRIC_INFO = {
continuity: { label: "Shot continuity", better: "higher", unit: "cosine", tie: 0.005, digits: 3 },
paletteFit: { label: "Palette distance", better: "lower", unit: "mean ΔE76", tie: 0.5, digits: 1 },
paletteCover: { label: "Palette used", better: "higher", unit: "0–1", tie: 0.05, digits: 2 },
+ bgDiff: { label: "Background change vs the source", better: "lower", unit: "0–1", tie: 0.002, digits: 4 },
+ bgPsnr: { label: "Background PSNR vs the source", better: "higher", unit: "dB", tie: 0.3, digits: 1 },
seconds: { label: "Time", better: "lower", unit: "s (wall clock)", tie: 0.5, digits: 1 },
costUsd: { label: "Cost", better: "lower", unit: "US$", tie: 0.0005, digits: 4 },
vramGb: { label: "Peak memory", better: "lower", unit: "GB", tie: 0.1, digits: 2 },
diff --git a/scripts/eval/lib/schema.mjs b/scripts/eval/lib/schema.mjs
index 57fa0ff8..69e2e301 100644
--- a/scripts/eval/lib/schema.mjs
+++ b/scripts/eval/lib/schema.mjs
@@ -5,7 +5,7 @@
import { z } from "zod";
export const ENGINES = /** @type {const} */ (["demo", "open", "cloud"]);
-export const METRICS = /** @type {const} */ (["clip", "aesthetic", "style", "identity", "temporal", "lipsync", "continuity", "palette"]);
+export const METRICS = /** @type {const} */ (["clip", "aesthetic", "style", "identity", "temporal", "lipsync", "continuity", "palette", "background"]);
const Slug = z.string().regex(/^[a-z0-9][a-z0-9-]*$/, "lower-case letters, digits and dashes");
const CaseId = z.string().max(120).regex(/^[a-z0-9][a-z0-9._-]*(\/[a-z0-9][a-z0-9._-]*)*$/, "lower-case words joined by - . _ and /");
diff --git a/scripts/eval/metrics/fuobe_metrics/maths.py b/scripts/eval/metrics/fuobe_metrics/maths.py
index d439de8e..0d3b7ef6 100644
--- a/scripts/eval/metrics/fuobe_metrics/maths.py
+++ b/scripts/eval/metrics/fuobe_metrics/maths.py
@@ -140,6 +140,29 @@ def best_lag_correlation(a: np.ndarray, b: np.ndarray, max_lag: int) -> dict:
return best
+def ring_mask(h: int, w: int, frac: float = 0.15) -> np.ndarray:
+ """True on the frame's outer ring (`frac` of each side): where the background is, around a person in the middle."""
+ m = np.zeros((h, w), dtype=bool)
+ dy, dx = max(1, int(round(h * frac))), max(1, int(round(w * frac)))
+ m[:dy, :] = m[-dy:, :] = True
+ m[:, :dx] = m[:, -dx:] = True
+ return m
+
+
+def background_difference(out: np.ndarray, src: np.ndarray, frac: float = 0.15) -> dict:
+ """How far a clip's background moved from the source's: mean abs error (0–1) and PSNR (dB) on the outer ring of
+ each frame, over the frames both have (uint8 N×H×W×3, the same size)."""
+ n = min(len(out), len(src))
+ if n == 0:
+ return {"mae": float("nan"), "psnr": float("nan"), "frames": 0}
+ a = out[:n].astype(np.float32) / 255.0
+ b = src[:n].astype(np.float32) / 255.0
+ ring = ring_mask(a.shape[1], a.shape[2], frac)
+ diff = (a - b)[:, ring]
+ mse = float(np.mean(diff**2))
+ return {"mae": float(np.mean(np.abs(diff))), "psnr": 99.0 if mse <= 1e-10 else float(10 * np.log10(1.0 / mse)), "frames": n}
+
+
def consecutive_similarity(embs: np.ndarray) -> float:
"""Mean cosine between consecutive items (the shots of a film): how well a look and its subject carry across cuts."""
e = l2norm(np.atleast_2d(embs))
diff --git a/scripts/eval/metrics/fuobe_metrics/media.py b/scripts/eval/metrics/fuobe_metrics/media.py
index dc91cea1..856e1b18 100644
--- a/scripts/eval/metrics/fuobe_metrics/media.py
+++ b/scripts/eval/metrics/fuobe_metrics/media.py
@@ -87,6 +87,19 @@ def video_frames(path: str | pathlib.Path, fps: float = 4.0, max_frames: int = 3
return frames[: n * w * h * 3].reshape(n, h, w, 3)[:max_frames], rate
+def video_window(path: str | pathlib.Path, start: float, seconds: float, rate: float, width: int, height: int) -> np.ndarray:
+ """`seconds` of a clip from `start`, sampled at `rate` and scaled to width × height (to line it up with another clip's frames)."""
+ r = subprocess.run(
+ ["ffmpeg", "-v", "error", "-ss", f"{start:.3f}", "-t", f"{seconds:.3f}", "-i", str(path), "-vf", f"fps={rate},scale={width}:{height}", "-f", "rawvideo", "-pix_fmt", "rgb24", "-"],
+ capture_output=True,
+ )
+ if r.returncode != 0:
+ raise RuntimeError(f"ffmpeg couldn't read {pathlib.Path(path).name}: {r.stderr.decode(errors='replace').strip()[:200]}")
+ frames = np.frombuffer(r.stdout, dtype=np.uint8)
+ n = len(frames) // (width * height * 3)
+ return frames[: n * width * height * 3].reshape(n, height, width, 3)
+
+
def audio_track(path: str | pathlib.Path, sr: int = 16000) -> np.ndarray | None:
"""The sound as mono float32 at `sr` Hz, or None when there is none."""
r = subprocess.run(["ffmpeg", "-v", "error", "-i", str(path), "-vn", "-ac", "1", "-ar", str(sr), "-f", "s16le", "-"], capture_output=True)
diff --git a/scripts/eval/metrics/fuobe_metrics/registry.py b/scripts/eval/metrics/fuobe_metrics/registry.py
index 2e84cb6b..60aed3a8 100644
--- a/scripts/eval/metrics/fuobe_metrics/registry.py
+++ b/scripts/eval/metrics/fuobe_metrics/registry.py
@@ -11,6 +11,7 @@ FAMILIES = {
"lipsync": ["lipsync", "lipsyncOffset"],
"continuity": ["continuity"],
"palette": ["paletteFit", "paletteCover"],
+ "background": ["bgDiff", "bgPsnr"],
}
METRICS = {
@@ -29,6 +30,8 @@ METRICS = {
"continuity": {"label": "Shot continuity", "better": "higher", "unit": "cosine between consecutive shots"},
"paletteFit": {"label": "Palette distance", "better": "lower", "unit": "mean ΔE76 to the nearest palette colour"},
"paletteCover": {"label": "Palette used", "better": "higher", "unit": "share of the palette's colours"},
+ "bgDiff": {"label": "Background change vs the source", "better": "lower", "unit": "mean abs error 0–1 on the frame's outer ring"},
+ "bgPsnr": {"label": "Background PSNR vs the source", "better": "higher", "unit": "dB on the frame's outer ring"},
}
# Weights, each pinned to a Hugging Face revision. "commercial" says whether the model itself may be used
diff --git a/scripts/eval/metrics/fuobe_metrics/score.py b/scripts/eval/metrics/fuobe_metrics/score.py
index e335930e..edca8e01 100644
--- a/scripts/eval/metrics/fuobe_metrics/score.py
+++ b/scripts/eval/metrics/fuobe_metrics/score.py
@@ -18,7 +18,7 @@ import time
import numpy as np
from . import maths
-from .media import audio_track, have_ffmpeg, images_of, kind_of, video_frames
+from .media import audio_track, have_ffmpeg, images_of, kind_of, video_frames, video_window
from .models import MODELS, Aesthetic, Clip, Dino, Faces, Missing, device_of
from .registry import FAMILIES
@@ -227,6 +227,26 @@ class Scorer:
res["warp"] = round(float(np.mean(errs)), 5)
return res
+ def m_background(self, job, outs):
+ """The source clip's frames against the output's on the outer ring of the frame (where the background is): a
+ swap that keeps the background as filmed scores near 0 (and a high PSNR). Lined up from the source's start, so a
+ case's range starts at 0."""
+ clips = [o for o in outs if kind_of(o) == "video"]
+ src = (job.get("inputs") or {}).get("video")
+ if not clips:
+ return {"_note": "not a clip"}
+ if not src or not pathlib.Path(src).exists():
+ return {"_note": "no source clip to compare with"}
+ frames, rate = video_frames(clips[0], fps=self.args.fps, max_frames=self.args.frames, width=256)
+ if not len(frames):
+ return {"_note": "the clip has no frames"}
+ h, w = frames.shape[1:3]
+ source = video_window(src, 0.0, len(frames) / rate, rate, w, h)
+ d = maths.background_difference(frames, source)
+ if not d["frames"]:
+ return {"_note": "no source frames in the case's range"}
+ return {"bgDiff": round(d["mae"], 5), "bgPsnr": round(d["psnr"], 2)}
+
def m_lipsync(self, job, outs):
clips = [o for o in outs if kind_of(o) == "video"]
if not clips:
diff --git a/scripts/eval/metrics/tests/test_maths.py b/scripts/eval/metrics/tests/test_maths.py
index a0fd27f8..50c70480 100644
--- a/scripts/eval/metrics/tests/test_maths.py
+++ b/scripts/eval/metrics/tests/test_maths.py
@@ -134,3 +134,20 @@ def test_palette_of_reads_the_request_or_the_lock_route():
assert palette_of({"request": {"params": {"palette": ["#102030"]}}}).tolist() == [[16, 32, 48]]
assert palette_of({"request": {"route": "/api/palettes/lock", "body": {"request": {"params": {}}, "colors": ["#FFFFFF"]}}}).tolist() == [[255, 255, 255]]
assert len(palette_of({"request": {"prompt": "x"}})) == 0
+
+
+def test_background_difference_on_the_outer_ring():
+ src = np.full((3, 20, 20, 3), 100, dtype=np.uint8)
+ out = src.copy()
+ # The middle (the person) changes: the ring doesn't, so the background scores as untouched.
+ out[:, 6:14, 6:14] = 255
+ same = maths.background_difference(out, src)
+ assert same["mae"] == pytest.approx(0.0)
+ assert same["psnr"] == 99.0
+ assert same["frames"] == 3
+ # The whole frame brighter by 51 (0.2): the ring sees it.
+ moved = maths.background_difference(np.clip(src.astype(int) + 51, 0, 255).astype(np.uint8), src)
+ assert moved["mae"] == pytest.approx(0.2, abs=1e-6)
+ assert moved["psnr"] == pytest.approx(10 * math.log10(1 / 0.04), abs=1e-3)
+ assert maths.ring_mask(10, 10, 0.2).sum() == 100 - 36
+ assert maths.background_difference(out[:0], src)["frames"] == 0
diff --git a/src/lib/catalog/character-swap.ts b/src/lib/catalog/character-swap.ts
index 19748b92..7c5d8f91 100644
--- a/src/lib/catalog/character-swap.ts
+++ b/src/lib/catalog/character-swap.ts
@@ -158,6 +158,8 @@ export interface CharacterOptions {
/** Advanced: H3's window and continuation history (frames). */
windowFrames?: number;
historyFrames?: number;
+ /** 1080p / 2K / 4K on your GPU: the regenerate's start noise (sharpen.ts; for evaluations, the page leaves it). */
+ sharpenSigma?: number;
}
// ---------------------------------------------------------------------------
diff --git a/src/lib/catalog/genjutsu.ts b/src/lib/catalog/genjutsu.ts
index 95889063..75848e25 100644
--- a/src/lib/catalog/genjutsu.ts
+++ b/src/lib/catalog/genjutsu.ts
@@ -1271,6 +1271,7 @@ function openFinish(input: GenjutsuPlanInput, asked: SharpenTier, quality: strin
tier,
prompt: sharpenPrompt(prompt, c.description),
...(input.seed !== undefined ? { seed: input.seed } : {}),
+ ...(c.sharpenSigma !== undefined ? { sigma: c.sharpenSigma } : {}),
frames,
take: { after: "swap" },
source: { after: "fit", start: 0 },
diff --git a/src/lib/catalog/sharpen.ts b/src/lib/catalog/sharpen.ts
index 33694b11..cace7a7b 100644
--- a/src/lib/catalog/sharpen.ts
+++ b/src/lib/catalog/sharpen.ts
@@ -31,6 +31,9 @@ export const CLOUD_TIERS: readonly SharpenTier[] = ["2K", "4K"];
/** The regenerate's start noise for a swap (rdh: 0.8 "stays closer to the draft"; the release's 0.909 can drift a face). */
export const SHARPEN_SIGMA = 0.8;
+/** The start noises an evaluation may try (Close 0.7 … the release's 0.909). */
+export const SHARPEN_SIGMA_RANGE = { min: 0.5, max: 0.909 } as const;
+const sigmaOf = (v: number | undefined) => (v !== undefined && v >= SHARPEN_SIGMA_RANGE.min && v <= SHARPEN_SIGMA_RANGE.max ? v : SHARPEN_SIGMA);
/** fal's price per second of the LoRA route (the Character swap's), by resolution. */
export const SWAP_PER_SECOND: Record<"480P" | "768P" | "2K" | "4K", number> = { "480P": 0.0625, "768P": 0.075, ...RERENDER["fuobe-character-swap"].perSecond };
@@ -219,6 +222,8 @@ export interface SharpenStepsInput {
/** What the regenerate redraws from. */
prompt: string;
seed?: number;
+ /** The regenerate's start noise (SHARPEN_SIGMA unless an evaluation asks for another in SHARPEN_SIGMA_RANGE). */
+ sigma?: number;
/** The swap's length in frames (24 fps). */
frames: number;
/** The 768p swap. */
@@ -275,7 +280,7 @@ export function sharpenSteps(s: SharpenStepsInput): { steps: PlanStep[]; final:
sourceDuration: sec(w.frames),
...(s.seed !== undefined ? { seed: s.seed } : {}),
// An H3 draft (the 768p preset), and the start noise that keeps the swapped identity closer.
- extra: { startSigma: SHARPEN_SIGMA, draftFrom: "h3" },
+ extra: { startSigma: sigmaOf(s.sigma), draftFrom: "h3" },
},
step: { label: `${s.label} · redraw at ${s.tier}${many ? ` (${wi + 1} of ${regen.length})` : ""}`, index: wi, of: regen.length },
},
diff --git a/src/server/genjutsu.ts b/src/server/genjutsu.ts
index b689af70..6291697f 100644
--- a/src/server/genjutsu.ts
+++ b/src/server/genjutsu.ts
@@ -19,7 +19,7 @@ import {
type CharacterOptions,
} from "@/lib/catalog/character-swap";
import { ACCESS_PLACE } from "@/lib/model-access";
-import { filmSize, sharpenTierFor } from "@/lib/catalog/sharpen";
+import { filmSize, SHARPEN_SIGMA_RANGE, sharpenTierFor } from "@/lib/catalog/sharpen";
import {
chooseMaker,
cutsInPart,
@@ -118,6 +118,8 @@ const character = z.object({
useMask: z.boolean().optional(),
windowFrames: z.number().int().min(22).max(362).optional(),
historyFrames: z.number().int().min(0).max(341).optional(),
+ /** 1080p / 2K / 4K on your GPU: the regenerate's start noise (an evaluation knob; the page doesn't set it). */
+ sharpenSigma: z.number().min(SHARPEN_SIGMA_RANGE.min).max(SHARPEN_SIGMA_RANGE.max).optional(),
});
/** The body of /api/genjutsu (and /estimate). */
diff --git a/tests/character-swap-2k.test.ts b/tests/character-swap-2k.test.ts
index cc2ed772..b1fdb486 100644
--- a/tests/character-swap-2k.test.ts
+++ b/tests/character-swap-2k.test.ts
@@ -230,6 +230,16 @@ describe("Genjutsu's Character swap", () => {
expect(() => character("open", "2K", { source: { ...hd, width: 1280, height: 720 } })).toThrow(S.SHARPEN_COPY.small);
});
+ it("an evaluation may try another start noise (0.5–0.909); the page leaves it at 0.8", () => {
+ expect(step(character("open", "2K", { character: { sharpenSigma: 0.909 } }), "sharpen-regen0").request.params?.extra).toMatchObject({ startSigma: 0.909 });
+ expect(step(character("open", "2K", { character: { sharpenSigma: 0.3 } }), "sharpen-regen0").request.params?.extra).toMatchObject({ startSigma: 0.8 });
+ // It never reaches the swap's own graph settings.
+ expect(step(character("open", "2K", { character: { sharpenSigma: 0.7 } }), "swap").request.params?.extra).not.toHaveProperty("sharpenSigma");
+ const suite = JSON.parse(fs.readFileSync(path.join(ROOT, "scripts/eval/cases/character-2k.json"), "utf8"));
+ expect(suite.cases.map((c: { submit: { body: { character: { sharpenSigma?: number } } } }) => c.submit.body.character.sharpenSigma)).toEqual([undefined, 0.7, 0.8, 0.909, undefined]);
+ expect(suite.defaults.metrics).toEqual(["identity", "background", "temporal"]);
+ });
+
it("the cloud at 2K: the same pieces, fal's H3 asked for 2K (no regenerate, no composite)", () => {
const p = character("cloud", "2K");
expect(keys(p).some((k) => /regen|comp/.test(k))).toBe(false);