Skip to content

Commit 2995496

Browse files
authored
fixed some serialization issues
1 parent a0fbce4 commit 2995496

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

examples/TTSwithVerification/bestofk_baseline.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,19 @@
4242
# Save the real stderr so tqdm always works even if suppress_output is active
4343
_real_stderr = sys.stderr
4444

45+
class NumpyEncoder(json.JSONEncoder):
46+
"""Custom JSON encoder that handles numpy types."""
47+
def default(self, obj):
48+
if isinstance(obj, np.bool_):
49+
return bool(obj)
50+
if isinstance(obj, np.integer):
51+
return int(obj)
52+
if isinstance(obj, np.floating):
53+
return float(obj)
54+
if isinstance(obj, np.ndarray):
55+
return obj.tolist()
56+
return super().default(obj)
57+
4558

4659
@contextmanager
4760
def suppress_output():
@@ -1005,5 +1018,5 @@ def process_example(idx):
10051018

10061019
summary_path = os.path.join(output_dirs["base"], "summary.json")
10071020
with open(summary_path, "w", encoding="utf-8") as f:
1008-
json.dump(summary, f, indent=2)
1021+
json.dump(summary, f, indent=2, cls=NumpyEncoder)
10091022
# logger.info(f"Saved summary to {summary_path}")

0 commit comments

Comments
 (0)