7cdce0c474
Near-static videos are the dominant GPU load: sampled into up to 64 frames, each re-runs the whole detect→CCIP→SigLIP chain on ~identical content. Add a CPU perceptual-hash frame dedup upstream of the GPU so the redundant frames are never processed at all (not just their embeds). - media.dedupe_frames() + _dhash(): 8×8 difference-hash (64-bit) per frame; greedy keep — a frame survives only if its hash differs from every kept frame by >= min_distance bits (Hamming). A static run collapses to one frame; genuinely distinct scenes all survive. Order + frame_time preserved. - Called in worker._download_decode right after sample_frames, so it runs in the decode stage on the downloader thread (CPU) — the GPU consumers only ever see deduped frames, and buffered video items shrink (less RAM too). - Env-tunable FRAME_DEDUPE_DISTANCE (default 8; higher keeps more frames for brief localized changes an 8×8 hash can miss; 0 disables). Logs `video frames N→M` when it drops any, so video load reduction is visible. Complements the spatial per-frame crop dedup (2026-07-01.2); this is the temporal axis. Build marker 2026-07-01.3. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ttrj5P7upUTueSfoJcxEqa
73 lines
4.2 KiB
Python
73 lines
4.2 KiB
Python
"""Agent config, all from env (the control container is configured at run)."""
|
|
# Lazy annotations so the `from_env(cls) -> Config` self-reference is a string,
|
|
# not evaluated at class-definition time — otherwise it NameErrors on the agent's
|
|
# Python 3.10 (CI lints on 3.14, where PEP 649 hides this).
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
from dataclasses import dataclass
|
|
|
|
|
|
@dataclass
|
|
class Config:
|
|
fc_url: str # base URL of the FabledCurator web service
|
|
token: str # the bearer token from Settings → Tagging → GPU agent
|
|
agent_id: str # identifies this agent's leases
|
|
batch_size: int # jobs a worker leases per round
|
|
concurrency: int # INITIAL parallel workers (tunable live from the UI)
|
|
ccip_model: str # imgutils CCIP model name ("" → imgutils default)
|
|
detector_level: str # imgutils person-detector level: n|s|m|x
|
|
poll_idle_seconds: float # wait between empty leases
|
|
embed_dtype: str # torch dtype for the crop embedder: float16|float32
|
|
embed_model_override: str # force a SigLIP-family model ("" → use the one
|
|
# the server announces in the lease)
|
|
auto_start: bool # start the worker pool on boot (so a container restart
|
|
# resumes processing without anyone clicking Start)
|
|
auto_scale: bool # autoscale the worker count (throughput hill-climb)
|
|
# Crop PROPOSERS (extra YOLO detectors that say where to crop). Each weight
|
|
# spec is an ultralytics name | http(s) URL | "hf_repo::file" ("" = off).
|
|
person_weights: str # general COCO person detector (Western/realistic figs)
|
|
person_conf: float
|
|
anatomy_weights: str # booru_yolo anime/furry/NSFW components
|
|
anatomy_conf: float
|
|
panel_weights: str # comic-panel detector
|
|
panel_conf: float
|
|
max_components: int # cap anatomy component crops per frame
|
|
max_panels: int # cap panel crops per frame
|
|
max_figures: int # cap figure boxes per frame (each = a CCIP call + crop)
|
|
max_regions: int # hard cap on total regions per JOB (submit-size backstop)
|
|
dedupe_iou: float # crops overlapping >= this (same kind) are near-dupes,
|
|
# dropped before the embed; >=1.0 disables it
|
|
frame_dedupe_distance: int # video frames whose dHash differs by < this many
|
|
# bits are near-duplicates, dropped before detect;
|
|
# higher keeps more frames, 0 disables
|
|
|
|
@classmethod
|
|
def from_env(cls) -> Config:
|
|
return cls(
|
|
fc_url=os.environ.get("FC_URL", "http://localhost:8000").rstrip("/"),
|
|
token=os.environ.get("FC_TOKEN", ""),
|
|
agent_id=os.environ.get("AGENT_ID", "desktop-agent"),
|
|
batch_size=int(os.environ.get("BATCH_SIZE", "4")),
|
|
concurrency=int(os.environ.get("CONCURRENCY", "1")),
|
|
ccip_model=os.environ.get("CCIP_MODEL", ""),
|
|
detector_level=os.environ.get("DETECTOR_LEVEL", "m"),
|
|
poll_idle_seconds=float(os.environ.get("POLL_IDLE_SECONDS", "10")),
|
|
embed_dtype=os.environ.get("SIGLIP_DTYPE", "float16"),
|
|
embed_model_override=os.environ.get("EMBED_MODEL_NAME", ""),
|
|
auto_start=os.environ.get("AUTO_START", "").lower() in ("1", "true", "yes"),
|
|
auto_scale=os.environ.get("AUTO_SCALE", "true").lower() in ("1", "true", "yes"),
|
|
person_weights=os.environ.get("PERSON_WEIGHTS", "yolo11n.pt"),
|
|
person_conf=float(os.environ.get("PERSON_CONF", "0.35")),
|
|
anatomy_weights=os.environ.get("ANATOMY_WEIGHTS", ""),
|
|
anatomy_conf=float(os.environ.get("ANATOMY_CONF", "0.30")),
|
|
panel_weights=os.environ.get("PANEL_WEIGHTS", ""),
|
|
panel_conf=float(os.environ.get("PANEL_CONF", "0.30")),
|
|
max_components=int(os.environ.get("MAX_COMPONENTS", "8")),
|
|
max_panels=int(os.environ.get("MAX_PANELS", "8")),
|
|
max_figures=int(os.environ.get("MAX_FIGURES", "8")),
|
|
max_regions=int(os.environ.get("MAX_REGIONS", "128")),
|
|
dedupe_iou=float(os.environ.get("DEDUPE_IOU", "0.85")),
|
|
frame_dedupe_distance=int(os.environ.get("FRAME_DEDUPE_DISTANCE", "8")),
|
|
)
|