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