|
1 | 1 | import json |
2 | 2 |
|
3 | | -# Load benchmark results |
4 | | -with open('._datasets_voidful_codec-superb-tiny_synth_evaluation_results_20251218_204458.json', 'r') as f: |
| 3 | +import glob |
| 4 | +import os |
| 5 | + |
| 6 | +# Load latest benchmark results |
| 7 | +json_files = glob.glob('*codec-superb-tiny_synth_evaluation_results*.json') |
| 8 | +if not json_files: |
| 9 | + raise FileNotFoundError("No benchmark results found.") |
| 10 | +latest_file = max(json_files, key=os.path.getmtime) |
| 11 | +print(f"Loading results from {latest_file}") |
| 12 | +with open(latest_file, 'r') as f: |
5 | 13 | benchmark_results = json.load(f) |
6 | 14 |
|
7 | 15 | # Hardcoded BPS mapping (bitrate in kbps or as used in data.js) |
|
47 | 55 |
|
48 | 56 | new_results = {} |
49 | 57 |
|
50 | | -for model_name, metrics in benchmark_results.items(): |
| 58 | +new_results = {} |
| 59 | + |
| 60 | +for model_name, metrics_data in benchmark_results.items(): |
51 | 61 | entry = { |
52 | 62 | 'bps': bps_mapping.get(model_name, 0) |
53 | 63 | } |
54 | | - for m in metrics_to_include: |
55 | | - val = metrics.get(m, 0) |
56 | | - # Handle NaN |
57 | | - if val != val: # NaN check |
58 | | - val = 0 |
59 | | - entry[m] = round(float(val), 3) |
| 64 | + |
| 65 | + # Check if nested by category |
| 66 | + is_nested = any(isinstance(v, dict) for v in metrics_data.values()) |
| 67 | + |
| 68 | + if is_nested: |
| 69 | + for category, metrics in metrics_data.items(): |
| 70 | + for m in metrics_to_include: |
| 71 | + val = metrics.get(m, 0) |
| 72 | + if val != val: # NaN check |
| 73 | + val = 0 |
| 74 | + entry[f"{category.lower()}_{m}"] = round(float(val), 3) |
| 75 | + else: |
| 76 | + # Legacy format: metrics_data is {metric: value} |
| 77 | + # Map to 'overall' category by default |
| 78 | + for m in metrics_to_include: |
| 79 | + val = metrics_data.get(m, 0) |
| 80 | + if val != val: # NaN check |
| 81 | + val = 0 |
| 82 | + entry[f"overall_{m}"] = round(float(val), 3) |
| 83 | + |
60 | 84 | new_results[model_name] = entry |
61 | 85 |
|
62 | 86 | # Format as JavaScript |
|
0 commit comments