From 5d02e6bd2079a3691c5ef7a1c888abe6a16d854b Mon Sep 17 00:00:00 2001 From: Hari <58052269+harisankar95@users.noreply.github.com> Date: Thu, 11 May 2023 14:54:23 +0200 Subject: [PATCH] Convert numpy arrays to lists before saving the evaluation metrics as json (#23268) * convert numpy array to list before writing to json per_category_iou and per_category_accuracy are ndarray in the eval_metrics * code reformatted with make style --- .../run_semantic_segmentation_no_trainer.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/pytorch/semantic-segmentation/run_semantic_segmentation_no_trainer.py b/examples/pytorch/semantic-segmentation/run_semantic_segmentation_no_trainer.py index 783810be64..de997529de 100644 --- a/examples/pytorch/semantic-segmentation/run_semantic_segmentation_no_trainer.py +++ b/examples/pytorch/semantic-segmentation/run_semantic_segmentation_no_trainer.py @@ -682,7 +682,9 @@ def main(): if args.push_to_hub: repo.push_to_hub(commit_message="End of training", auto_lfs_prune=True) - all_results = {f"eval_{k}": v for k, v in eval_metrics.items()} + all_results = { + f"eval_{k}": v.tolist() if isinstance(v, np.ndarray) else v for k, v in eval_metrics.items() + } with open(os.path.join(args.output_dir, "all_results.json"), "w") as f: json.dump(all_results, f)