优化异常处理

This commit is contained in:
2024-07-11 12:59:05 +08:00
parent 507ac30915
commit e3198ccdf6

View File

@@ -261,13 +261,12 @@ def get_mask_layout(image, contents):
# layouts = get_ocr_layout(OCR, temp_file.name) # layouts = get_ocr_layout(OCR, temp_file.name)
try: try:
layouts = DOC_PARSER.parse({"doc": temp_file.name})["layout"] layouts = DOC_PARSER.parse({"doc": temp_file.name})["layout"]
except MemoryError as me: except TypeError as te:
# 如果是显存溢出问题,则抛出 # 如果是类型错误,大概率是没识别到文字
raise me
except Exception as e:
# 如果是没有识别到文字等问题,则继续
logging.warning("识别失败", exc_info=e)
layouts = [] layouts = []
except Exception as e:
# 如果出现其他错误,抛出
raise e
if not layouts: if not layouts:
# 无识别结果 # 无识别结果
return result return result