| import numpy as np |
| import json |
| import torch |
|
|
| |
| stats_file = "../meta/stats.json" |
| with open(stats_file, 'r') as f: |
| stats = json.load(f) |
|
|
| print("Keys in stats file:", list(stats.keys())) |
|
|
| |
| problem_found = False |
| for key in stats: |
| print(f"\nExamining key: {key}") |
| for stat_type in ["mean", "std"]: |
| if stat_type in stats[key]: |
| value = stats[key][stat_type] |
| print(f" - {stat_type} type: {type(value)}") |
| |
| try: |
| |
| numpy_val = np.array(value) |
| print(f" NumPy array shape: {numpy_val.shape}, dtype: {numpy_val.dtype}") |
| |
| |
| try: |
| torch_val = torch.from_numpy(numpy_val).to(dtype=torch.float32) |
| print(f" ✓ Successfully converted to torch tensor") |
| except Exception as e: |
| print(f" ✗ ERROR converting to torch tensor: {type(e).__name__}: {e}") |
| print(f" Value: {numpy_val}") |
| problem_found = True |
| except Exception as e: |
| print(f" ✗ ERROR converting to NumPy array: {type(e).__name__}: {e}") |
| print(f" Value: {value}") |
| problem_found = True |
|
|
| if not problem_found: |
| print("\nNo problems found in the stats file. The error might be happening in another part of the code.") |
| print("Try fixing the stats file with a preprocessing step:") |
|
|
| |
| fixed_stats = {} |
| for key in stats: |
| fixed_stats[key] = {} |
| for field, value in stats[key].items(): |
| if field in ["mean", "std"]: |
| |
| try: |
| |
| arr = np.array(value) |
| |
| if arr.dtype == np.dtype('O'): |
| arr = np.ones_like(arr, dtype=np.float32) |
| else: |
| |
| arr = arr.astype(np.float32) |
| |
| fixed_stats[key][field] = arr.tolist() |
| except Exception as e: |
| print(f"Fixing {key}.{field}: {e}") |
| |
| fixed_stats[key][field] = [1.0] |
| else: |
| |
| fixed_stats[key][field] = value |
| |
| |
| with open("../meta/stats_fixed.json", 'w') as f: |
| json.dump(fixed_stats, f, indent=2) |
| |
| print("Created fixed stats file: ../meta/stats_fixed.json") |
| print("You can replace the original stats.json with this file.") |