from pathlib import Path
from rapidocr import RapidOCR, VisRes
from rapid_table import RapidTable, RapidTableInput, VisTable
# 默认是slanet_plus模型
table_engine = RapidTable()
# # 开启onnx-gpu推理
# input_args = RapidTableInput(use_cuda=True)
# table_engine = RapidTable(input_args)
# 使用torch推理版本的unitable模型
input_args = RapidTableInput(model_path="C:/Users/10034/.cache/modelscope/hub/models/RapidAI/RapidTable",model_type="unitable", use_cuda=True, device="cuda:0")
table_engine = RapidTable(input_args)
ocr_engine = RapidOCR()
vis_ocr = VisRes()
input_args = RapidTableInput(model_type="unitable")
table_engine = RapidTable(input_args)
viser = VisTable()
img_path = "img.png"
# OCR
rapid_ocr_output = ocr_engine(img_path, return_word_box=True)
ocr_result = list(
zip(rapid_ocr_output.boxes, rapid_ocr_output.txts, rapid_ocr_output.scores)
)
# 使用单字识别
# word_results = rapid_ocr_output.word_results
# ocr_result = [
# [word_result[2], word_result[0], word_result[1]] for word_result in word_results
# ]
table_results = table_engine(img_path, ocr_result)
table_html_str, table_cell_bboxes = table_results.pred_html, table_results.cell_bboxes
# Save
save_dir = Path("outputs")
save_dir.mkdir(parents=True, exist_ok=True)
save_html_path = save_dir / f"{Path(img_path).stem}.html"
save_drawed_path = save_dir / f"{Path(img_path).stem}_table_vis{Path(img_path).suffix}"
save_logic_points_path = save_dir / f"{Path(img_path).stem}_table_col_row_vis{Path(img_path).suffix}"
# Visualize table rec result
vis_imged = viser(img_path, table_results, save_html_path, save_drawed_path, save_logic_points_path)
print(f"The results has been saved {save_dir}")
ImportError: cannot import name 'GraphOptimizationLevel' from 'onnxruntime' (unknown location)
这个onnxruntime包卸载了,怎么修改
ImportError: cannot import name 'GraphOptimizationLevel' from 'onnxruntime' (unknown location)
这个onnxruntime包卸载了,怎么修改