mirror of
https://gitcode.com/gh_mirrors/eas/EasyFace.git
synced 2026-01-17 22:00:17 +00:00
18 lines
478 B
Python
18 lines
478 B
Python
# Copyright (c) Alibaba, Inc. and its affiliates.
|
|
|
|
import json
|
|
|
|
import numpy as np
|
|
|
|
|
|
class EnhancedEncoder(json.JSONEncoder):
|
|
""" Enhanced json encoder for not supported types """
|
|
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()
|
|
return json.JSONEncoder.default(self, obj)
|