利用MindSpore實(shí)現(xiàn)VI-LayoutXLM模型
?本文參考地址:https://github.com/PaddlePaddle/PaddleOCR/blob/release/2.6/doc/doc_ch/quickstart.md
前置mindspore安裝參考我的acfun教程:https://www.acfun.cn/a/ac41786362
清華鏡像:(如果pip出問題就在后面加這個(gè))
-i https://pypi.tuna.tsinghua.edu.cn/simple
具體步驟:
打開pycharm的控制臺(tái)
安裝PaddlePaddle(cpu平臺(tái))
python3 -m pip install paddlepaddle -i https://mirror.baidu.com/pypi/simple
安裝PaddleOCR whl包
pip install "paddleocr>=2.0.1" -i https://pypi.tuna.tsinghua.edu.cn/simple
PaddleOCR提供了一系列測試圖片,點(diǎn)擊
下載并解壓,然后在終端中切換到相應(yīng)目錄(/path/to/ppocr_img填你實(shí)際的目錄)cd /path/to/ppocr_img
檢測+方向分類器+識(shí)別全流程:--use_angle_cls true
設(shè)置使用方向分類器識(shí)別180度旋轉(zhuǎn)文字,--use_gpu false
設(shè)置不使用GPU
paddleocr --image_dir ./imgs/11.jpg --use_angle_cls true --use_gpu false
提示沒有paddle包:
安裝:
python -m pip install paddlepaddle==2.4.2 -i https://pypi.tuna.tsinghua.edu.cn/simple
參見:https://www.paddlepaddle.org.cn/、
再次出現(xiàn)問題:ImportError: numpy.core.multiarray failed to import
在終端輸入:
python
import numpy
print(numpy.__path__)
exit()
刪除顯示的路徑
重新安裝numpy
調(diào)試程序:檢測+方向分類器+識(shí)別全流程
from paddleocr import PaddleOCR, draw_ocr
ocr = PaddleOCR(use_angle_cls=True, lang="ch")
img_path = r"C:\Users\34476\Desktop\賽題四所需\ppocr_img\ppocr_img\imgs\11.jpg"
result = ocr.ocr(img_path, cls=True)
for idx in range(len(result)):
? ?res = result[idx]
? ?for line in res:
? ? ? ?print(line)
from PIL import Image
result = result[0]
image = Image.open(img_path).convert('RGB')
boxes = [line[0] for line in result]
txts = [line[1][0] for line in result]
scores = [line[1][1] for line in result]
font_path = r"C:\Users\34476\Desktop\賽題四所需\ppocr_img\ppocr_img\fonts\simfang.ttf"
im_show = draw_ocr(image, boxes, txts, scores, font_path=font_path)
im_show = Image.fromarray(im_show)
im_show.save('result.jpg')

結(jié)果
