Update inference.py

This commit is contained in:
2026-03-10 17:00:06 +08:00
parent ee38f71f40
commit 057f64cc37

View File

@@ -81,13 +81,18 @@ class DotsOcr:
generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
) )
result_str = output_text[0] result_str = output_text[0]
try:
result_list = json.loads(result_str) result_list = json.loads(result_str)
return result_list return result_list
except json.JSONDecodeError:
print(f"无法解析 JSON 输出: {result_str}")
return {"error": "无法解析 JSON 输出"}
if __name__=="__main__": if __name__=="__main__":
model_path = "DotsOCR" model_path = "DotsOCR"
dots_ocr = DotsOcr(model_path) dots_ocr = DotsOcr(model_path)
image_paths = ["20260306-065852.webp", "20260306-065909.webp"] image_paths = ["20260310-162729.webp"]
for image_path in image_paths: for image_path in image_paths:
output_text = dots_ocr.sample_inference(image_path) output_text = dots_ocr.sample_inference(image_path)
print(output_text) print(output_text)