planktoscope/software/planktoscope-backend/src/planktoscope_backend/segmenter/encoder.py

15 lines
380 B
Python
Raw Normal View History

import json
import numpy as np
class NpEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, np.integer):
return int(obj)
elif isinstance(obj, np.floating):
return float(obj)
elif isinstance(obj, np.ndarray):
return obj.tolist()
else:
return super(NpEncoder, self).default(obj)