CnOCR
CnOCR copied to clipboard
在使用识别模型ch_PP-OCRv3部署http服务时,返回结果会出现json序列号报错
当使用 scripts/flask-serve.py 脚本部署 rec_model_name='ch_PP-OCRv3' 的http服务时会出现如下错误
raise TypeError(f"Object of type {type(o).__name__} is not JSON serializable")
TypeError: Object of type float32 is not JSON serializable
经排查发现是此处漏掉了score的类型转换,此处的score类型是np.float32无法序列化
for _one in res:
_one['position'] = _one['position'].tolist()
_one['score'] = float(_one['score']) #此处score也要加上转换
if 'cropped_img' in _one:
_one.pop('cropped_img')