foley.eval.external_toolkit#
A reference toolkit run in its own interpreter: the part every adapter shares (#48, #262).
Several evaluation toolkits cannot share foley’s environment: fadtk and kadtk
pin numpy<2 and an old torch, audiobox_aesthetics pulls a recent torch foley
does not need. Each runs the way foley.external runs MFA and aeneas: clips are
written as mono 16-bit WAVs to a temporary directory, the toolkit’s interpreter runs
foley.eval.toolkit_driver on a JSON spec, and the JSON it writes back is the
answer. ExternalToolkit is that mechanism (the interpreter and its install
hint, the failure hints, the run); what is computed over the files is the subclass’s:
a set-level distance (foley.eval.external_fidelity.ExternalFidelity) or a
per-clip score (foley.eval.aesthetics.AudioboxAesthetics). Nothing from any
toolkit is imported here.
Module Attributes
The script run inside a toolkit's interpreter. |
|
The most channels a clip may have. |
|
scored (no floor), above ( |
|
scored (no floor), above ( |
|
scored (no floor), above ( |
|
scored (no floor), above ( |
|
The longest reason an |
Functions
|
|
|
Score one clip with |
|
|
|
Write each waveform in |
Classes
|
A toolkit run by |
- foley.eval.external_toolkit.DRIVER = PosixPath('/home/runner/work/foley/foley/foley/eval/toolkit_driver.py')#
The script run inside a toolkit’s interpreter.
- class foley.eval.external_toolkit.ExternalToolkit(*, python=None, env=None, timeout=None, runner=<function run>)[source]#
Bases:
objectA toolkit run by
DRIVERin a separate interpreter.Subclasses set
toolkit,python_env,install,isolation_reason(and optionallyfailure_hints), and callrun_driver().- Parameters:
python (
Optional[str]) – An interpreter with the toolkit installed, usually in its own venv (default:$<python_env>; neither set raises with the install line).env (
Optional[Mapping[str,str]]) – Variables added to this process’s environment for the program, e.g.{"TORCH_HOME": ...}or{"HF_HOME": ...}to choose where weights go.timeout (
Optional[float]) – Seconds before the run is abandoned (default: none).runner (
Callable[...,CompletedProcess]) – Runs the command (defaultsubprocess.run).
- isolation_reason: str#
Why the toolkit cannot live in foley’s environment (said when no interpreter).
- local_paths()[source]#
The interpreter as given and resolved, and its venv root: paths to keep out of anything published (
foley.obs.redact.redact_paths()). Never raises.
- resolve_python()[source]#
The toolkit’s interpreter as an executable path; raise with the install line if none.
Cheap (no program runs), so a caller can fail before anything is paid for.
- Return type:
- run_driver(spec, *, out, cwd, what, python=None)[source]#
Run
DRIVERonspec(plustoolkitandout); return its JSON.pythonis the already-resolved interpreter (default: resolve it now); a caller resolves it first to fail before writing any file.- Raises:
FileNotFoundError – If no interpreter is given or found.
RuntimeError – If the toolkit fails (its output tail, and any matching
failure_hints, are in the message).
- Return type:
- foley.eval.external_toolkit.LOW = 'low'#
scored (no floor), above (
ok) or below (low) a floor, orunchecked(it could not be had: the reason says why).- Type:
A per-clip verdict’s status
- foley.eval.external_toolkit.MAX_CHANNELS = 8#
The most channels a clip may have. A 2-D array with at most this many rows and more columns than that is channel-first, and is refused (
as_frames_channels()).
- foley.eval.external_toolkit.OK = 'ok'#
scored (no floor), above (
ok) or below (low) a floor, orunchecked(it could not be had: the reason says why).- Type:
A per-clip verdict’s status
- foley.eval.external_toolkit.REASON_MAX_CHARS = 200#
The longest reason an
uncheckedverdict stores.
- foley.eval.external_toolkit.SCORED = 'scored'#
scored (no floor), above (
ok) or below (low) a floor, orunchecked(it could not be had: the reason says why).- Type:
A per-clip verdict’s status
- foley.eval.external_toolkit.UNCHECKED = 'unchecked'#
scored (no floor), above (
ok) or below (low) a floor, orunchecked(it could not be had: the reason says why).- Type:
A per-clip verdict’s status
- foley.eval.external_toolkit.as_frames_channels(wav)[source]#
wavas foley’s(frames,)/(frames, channels); refuse other layouts.A channel-first
(2, N)array would otherwise be read as two-sample clips.- Return type:
ndarray
- foley.eval.external_toolkit.clip_verdict(audio_bytes, *, scorer, scored)[source]#
Score one clip with
scorer((wavs, *, sr) -> [score]) and turn its one score into a verdict withscored(score, scorer); never raises.Anything that keeps a score from being had (no interpreter, a clip the scorer refuses, a timeout, a crash, a scorer answering anything but one well-formed score) gives
{"status": "unchecked", "reason": ...}(publishable_reason()).- Return type:
- foley.eval.external_toolkit.publishable_reason(exc, *, prefixes=(), max_chars=200)[source]#
excas a short, publishable reason: its type, first and last line, no absolute path.A failed run’s message carries the program’s output tail and local paths, and the reason is stored on the record, so only its first line (what failed) and last line (the program’s error, or foley’s hint about it) are kept, cut, and scrubbed of paths by
foley.obs.redact.redact_paths()(prefixes: the interpreter and its venv, replaced whole first).- Return type:
- foley.eval.external_toolkit.write_set(wavs, sr, folder, *, prefix, check=None)[source]#
Write each waveform in
wavsas a mono 16-bit WAV infolder; return the count.Files are named
<prefix><n:05d>.wavfrom 1, so sorting them keeps the input order.check(clip, sr=, name=), if given, sees each(frames[, channels])clip first and raises to refuse it.- Return type: