From d4710a25971d4df29a7ceb90829fb3092f2e9e82 Mon Sep 17 00:00:00 2001 From: David Manthey Date: Tue, 30 Jan 2024 12:10:42 -0700 Subject: [PATCH] Don't serialize some options to json (#1097) Debug a serialization failure --- .../SuperpixelSegmentation/SuperpixelSegmentation.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/histomicstk/cli/SuperpixelSegmentation/SuperpixelSegmentation.py b/histomicstk/cli/SuperpixelSegmentation/SuperpixelSegmentation.py index 9dd42ea5f..6bdef8de4 100644 --- a/histomicstk/cli/SuperpixelSegmentation/SuperpixelSegmentation.py +++ b/histomicstk/cli/SuperpixelSegmentation/SuperpixelSegmentation.py @@ -237,7 +237,7 @@ def createSuperPixels(opts): # noqa 'boundaries': opts.boundaries, }], 'attributes': { - 'params': vars(opts), + 'params': {k: v for k, v in vars(opts).items() if not callable(v)}, 'cli': Path(__file__).stem, 'version': histomicstk.__version__, }, @@ -259,14 +259,19 @@ def createSuperPixels(opts): # noqa 'lineColor': opts.default_strokeColor, } for bidx, (bcx, bcy, bw, bh) in enumerate(bboxes)], 'attributes': { - 'params': vars(opts), + 'params': {k: v for k, v in vars(opts).items() if not callable(v)}, 'cli': Path(__file__).stem, 'version': histomicstk.__version__, }, } annotation = [annotation, bboxannotation] with open(opts.outputAnnotationFile, 'w') as annotation_file: - json.dump(annotation, annotation_file, separators=(',', ':'), sort_keys=False) + try: + json.dump(annotation, annotation_file, separators=(',', ':'), sort_keys=False) + except Exception: + print('Failed to serialize annotation') + print(repr(annotation)) + raise if hasattr(opts, 'callback'): opts.callback('file', 2, 2)