""" Copy only the "remove all distractors" samples from eval_outputs_removeonly_old into eval_outputs_removeall_old for each model. A sample qualifies if: - command_type is "remove_only" - target_sources is ["speech"] - ALL distractors listed in metadata are named in the user_input command """ import json import os import shutil BASE = "/home/kthakka2/scratchmelhila1/karan/EMMA2_text_conditioning_contextual/experiments" MODELS = [ "TSDL_old_mixtures", "no_TSDL_old_mixtures", "combined_v1", "frequencyweighted_v1", "multiscale_v1", ] for model in MODELS: src_dir = os.path.join(BASE, model, "eval_outputs_removeonly_old", "outputs") dst_dir = os.path.join(BASE, model, "eval_outputs_removeall_old", "outputs") if not os.path.exists(src_dir): print(f"SKIP {model}: {src_dir} not found") continue os.makedirs(dst_dir, exist_ok=True) total = 0 copied = 0 for sample_dir in sorted(os.listdir(src_dir)): sample_path = os.path.join(src_dir, sample_dir) meta_path = os.path.join(sample_path, "metadata.json") if not os.path.isdir(sample_path) or not os.path.exists(meta_path): continue total += 1 with open(meta_path) as f: meta = json.load(f) cmd = meta.get("command_variant", {}) user_input = cmd.get("user_input", "") or "" target_sources = cmd.get("target_sources", []) distractors = meta.get("distractors", []) if target_sources != ["speech"]: continue if not distractors: continue # Check all distractors are named in the command all_removed = all( dist.replace("_", " ") in user_input for dist in distractors ) if not all_removed: continue # Copy the sample directory dst_sample = os.path.join(dst_dir, sample_dir) if os.path.exists(dst_sample): shutil.rmtree(dst_sample) shutil.copytree(sample_path, dst_sample) copied += 1 # Also copy the summary JSON if it exists for summary_file in ["results_summary.json", "eval_results.json"]: src_summary = os.path.join(BASE, model, "eval_outputs_removeonly_old", summary_file) if os.path.exists(src_summary): shutil.copy2(src_summary, os.path.join(BASE, model, "eval_outputs_removeall_old", summary_file)) print(f"{model}: copied {copied}/{total} samples to eval_outputs_removeall_old")