breezedeus / CnOCR

CnOCR: Awesome Chinese/English OCR Python toolkits based on PyTorch. It comes with 20+ well-trained models for different application scenarios and can be used directly after installation. 【基于 PyTorch/MXNet 的中文/英文 OCR Python 包。】
https://www.breezedeus.com/article/cnocr
Apache License 2.0
3.29k stars 507 forks source link

在使用识别模型ch_PP-OCRv3部署http服务时,返回结果会出现json序列号报错 #291

Open YanceyHo opened 1 year ago

YanceyHo commented 1 year ago

当使用 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')