Datasets:
Delete debug/test.py
Browse files- debug/test.py +0 -74
debug/test.py
DELETED
|
@@ -1,74 +0,0 @@
|
|
| 1 |
-
import numpy as np
|
| 2 |
-
import json
|
| 3 |
-
import torch
|
| 4 |
-
|
| 5 |
-
# Load stats file
|
| 6 |
-
stats_file = "../meta/stats.json"
|
| 7 |
-
with open(stats_file, 'r') as f:
|
| 8 |
-
stats = json.load(f)
|
| 9 |
-
|
| 10 |
-
print("Keys in stats file:", list(stats.keys()))
|
| 11 |
-
|
| 12 |
-
# Check each field more thoroughly by simulating the torch conversion
|
| 13 |
-
problem_found = False
|
| 14 |
-
for key in stats:
|
| 15 |
-
print(f"\nExamining key: {key}")
|
| 16 |
-
for stat_type in ["mean", "std"]:
|
| 17 |
-
if stat_type in stats[key]:
|
| 18 |
-
value = stats[key][stat_type]
|
| 19 |
-
print(f" - {stat_type} type: {type(value)}")
|
| 20 |
-
|
| 21 |
-
try:
|
| 22 |
-
# Try converting to numpy array (this is what the code does)
|
| 23 |
-
numpy_val = np.array(value)
|
| 24 |
-
print(f" NumPy array shape: {numpy_val.shape}, dtype: {numpy_val.dtype}")
|
| 25 |
-
|
| 26 |
-
# Test if this can be converted to torch tensor
|
| 27 |
-
try:
|
| 28 |
-
torch_val = torch.from_numpy(numpy_val).to(dtype=torch.float32)
|
| 29 |
-
print(f" ✓ Successfully converted to torch tensor")
|
| 30 |
-
except Exception as e:
|
| 31 |
-
print(f" ✗ ERROR converting to torch tensor: {type(e).__name__}: {e}")
|
| 32 |
-
print(f" Value: {numpy_val}")
|
| 33 |
-
problem_found = True
|
| 34 |
-
except Exception as e:
|
| 35 |
-
print(f" ✗ ERROR converting to NumPy array: {type(e).__name__}: {e}")
|
| 36 |
-
print(f" Value: {value}")
|
| 37 |
-
problem_found = True
|
| 38 |
-
|
| 39 |
-
if not problem_found:
|
| 40 |
-
print("\nNo problems found in the stats file. The error might be happening in another part of the code.")
|
| 41 |
-
print("Try fixing the stats file with a preprocessing step:")
|
| 42 |
-
|
| 43 |
-
# Create a fixed stats file
|
| 44 |
-
fixed_stats = {}
|
| 45 |
-
for key in stats:
|
| 46 |
-
fixed_stats[key] = {}
|
| 47 |
-
for field, value in stats[key].items():
|
| 48 |
-
if field in ["mean", "std"]:
|
| 49 |
-
# Try to safely convert to float array
|
| 50 |
-
try:
|
| 51 |
-
# First convert to numpy array
|
| 52 |
-
arr = np.array(value)
|
| 53 |
-
# If object type, replace with safe values
|
| 54 |
-
if arr.dtype == np.dtype('O'):
|
| 55 |
-
arr = np.ones_like(arr, dtype=np.float32)
|
| 56 |
-
else:
|
| 57 |
-
# Make sure it's float32
|
| 58 |
-
arr = arr.astype(np.float32)
|
| 59 |
-
# Convert back to list for JSON
|
| 60 |
-
fixed_stats[key][field] = arr.tolist()
|
| 61 |
-
except Exception as e:
|
| 62 |
-
print(f"Fixing {key}.{field}: {e}")
|
| 63 |
-
# Just use a safe default
|
| 64 |
-
fixed_stats[key][field] = [1.0]
|
| 65 |
-
else:
|
| 66 |
-
# Keep other fields unchanged
|
| 67 |
-
fixed_stats[key][field] = value
|
| 68 |
-
|
| 69 |
-
# Save the fixed stats
|
| 70 |
-
with open("../meta/stats_fixed.json", 'w') as f:
|
| 71 |
-
json.dump(fixed_stats, f, indent=2)
|
| 72 |
-
|
| 73 |
-
print("Created fixed stats file: ../meta/stats_fixed.json")
|
| 74 |
-
print("You can replace the original stats.json with this file.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|