import os import json jsonl_path = "/mnt/beegfs/dzhu6/ViLaSR/eval/results/rl/SpatialEval/results.jsonl" base_dir = "/mnt/beegfs/dzhu6/ViLaSR/eval/results/rl/SpatialEval" def main(): # Read all entries with open(jsonl_path, "r") as f: lines = f.readlines() new_lines = [] for line in lines: entry = json.loads(line) # Only process if both fields exist if "sample_dir" in entry and "id" in entry: old_path = os.path.join("/mnt/beegfs/dzhu6/ViLaSR/", entry["sample_dir"]) new_path = os.path.join(base_dir, entry["id"]) # Rename folder if it exists and is not already renamed if os.path.exists(old_path) and old_path != new_path: os.rename(old_path, new_path) print(f"Renamed: {old_path} -> {new_path}") # Update the sample_dir field entry["sample_dir"] = f"./{entry['id']}" new_lines.append(json.dumps(entry, ensure_ascii=False)) # Write back the updated jsonl with open(jsonl_path, "w") as f: for l in new_lines: f.write(l + "\n") if __name__ == "__main__": main()