Wired SCNet into global power settings.
This commit is contained in:
1 parent
a877061aab
commit
c5f8c62a90
2 files changed
+34
-10
No files matched your search
@@ -259,10 +259,23 @@ class SCNetSeparator:
|
||||
# Public API
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
def separate_into_parts(self, input_path: str, output_dir: str) -> Dict[str, str]:
|
||||
def separate_into_parts(
|
||||
self,
|
||||
input_path: str,
|
||||
output_dir: str,
|
||||
chunk_size_override: Optional[int] = None,
|
||||
num_overlap_override: Optional[int] = None,
|
||||
) -> Dict[str, str]:
|
||||
"""
|
||||
Separate audio into stems.
|
||||
|
||||
Args:
|
||||
chunk_size_override: Override the model-config chunk size (samples).
|
||||
Smaller values reduce VRAM; larger improve context.
|
||||
num_overlap_override: Override the model-config num_overlap.
|
||||
Higher values improve boundary quality at the cost
|
||||
of more computation.
|
||||
|
||||
Returns:
|
||||
Dict mapping stem name → output file path.
|
||||
"""
|
||||
@@ -271,8 +284,8 @@ class SCNetSeparator:
|
||||
|
||||
sample_rate: int = cfg.get("audio", {}).get("sample_rate", 44100)
|
||||
inf_cfg: dict = cfg.get("inference", {})
|
||||
chunk_size: int = inf_cfg.get("chunk_size", 485100)
|
||||
num_overlap: int = inf_cfg.get("num_overlap", 2)
|
||||
chunk_size: int = chunk_size_override if chunk_size_override is not None else inf_cfg.get("chunk_size", 485100)
|
||||
num_overlap: int = num_overlap_override if num_overlap_override is not None else inf_cfg.get("num_overlap", 2)
|
||||
|
||||
# Stem order from training config; fall back to model attribute
|
||||
instruments = cfg.get("training", {}).get("instruments") or list(model.sources)
|
||||
|
||||
@@ -115,18 +115,21 @@ _SEP_POWER_PRESETS: Dict[str, Dict] = {
|
||||
'demucs': {'segment': 5, 'overlap': 0.1},
|
||||
'sepacap': {'chunk_samples': 24_000}, # 1 s @ 24 kHz
|
||||
'sepreformer': {'chunk_samples': 24_000}, # 3 s @ 8 kHz
|
||||
'scnet': {'chunk_size': 132_300, 'num_overlap': 2}, # ~3 s @ 44.1 kHz
|
||||
},
|
||||
'standard': {
|
||||
'roformer': {'batch_size': None, 'num_overlap': None},
|
||||
'demucs': {'segment': None, 'overlap': None},
|
||||
'sepacap': {'chunk_samples': 48_000}, # 2 s @ 24 kHz
|
||||
'sepreformer': {'chunk_samples': 48_000}, # 6 s @ 8 kHz
|
||||
'scnet': {'chunk_size': None, 'num_overlap': None}, # model config defaults
|
||||
},
|
||||
'performance': {
|
||||
'roformer': {'batch_size': 8, 'num_overlap': 4},
|
||||
'demucs': {'segment': 20, 'overlap': 0.5},
|
||||
'sepacap': {'chunk_samples': 96_000}, # 4 s @ 24 kHz
|
||||
'sepreformer': {'chunk_samples': 96_000}, # 12 s @ 8 kHz
|
||||
'scnet': {'chunk_size': None, 'num_overlap': 4}, # larger overlap for quality
|
||||
},
|
||||
}
|
||||
|
||||
@@ -396,6 +399,8 @@ def run_separation(
|
||||
job_id, input_path, model, normalised_format, stems_dir,
|
||||
mp3_bitrate=mp3_bitrate, metadata=metadata,
|
||||
stem_prefix=proj_name,
|
||||
chunk_size_override=_power['scnet'].get('chunk_size'),
|
||||
num_overlap_override=_power['scnet'].get('num_overlap'),
|
||||
)
|
||||
elif model in BSR_SW_MODEL_IDS:
|
||||
stem_files = _run_bsroformer_sw(
|
||||
@@ -1381,32 +1386,38 @@ def _run_scnet(
|
||||
mp3_bitrate: str = '256k',
|
||||
metadata: Optional[Dict] = None,
|
||||
stem_prefix: Optional[str] = None,
|
||||
chunk_size_override: Optional[int] = None,
|
||||
num_overlap_override: Optional[int] = None,
|
||||
) -> Dict[str, str]:
|
||||
"""Run SCNet XL separation (state-of-the-art 2024-2025)."""
|
||||
from .scnet_separator import SCNetSeparator
|
||||
|
||||
|
||||
jm.update_job(
|
||||
job_id, status=jm.JobStatus.RUNNING,
|
||||
progress=f"Loading SCNet model ({model})...",
|
||||
)
|
||||
|
||||
|
||||
if jm.should_cancel(job_id):
|
||||
raise RuntimeError("Cancelled by user")
|
||||
|
||||
|
||||
sep = SCNetSeparator(
|
||||
model_id=model,
|
||||
cpu_separation=CPU_SEPARATION,
|
||||
output_format=output_format,
|
||||
mp3_bitrate=mp3_bitrate,
|
||||
)
|
||||
|
||||
|
||||
jm.update_job(job_id, progress="Separating with SCNet... (this may take a while)")
|
||||
|
||||
|
||||
temp_out = JOBS_DIR / job_id / "scnet_out"
|
||||
temp_out.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
|
||||
try:
|
||||
stem_paths = sep.separate_into_parts(input_path, str(temp_out))
|
||||
stem_paths = sep.separate_into_parts(
|
||||
input_path, str(temp_out),
|
||||
chunk_size_override=chunk_size_override,
|
||||
num_overlap_override=num_overlap_override,
|
||||
)
|
||||
|
||||
if jm.should_cancel(job_id):
|
||||
raise RuntimeError("Cancelled by user")
|
||||
|
||||
Reference in new issue
Block a user