利用MindSpore实现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出问题就在后面加这个)
-i https://pypi.tuna.tsinghua.edu.cn/simple
具体步骤:
打开pycharm的控制台
安装PaddlePaddle(cpu平台)
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提供了一系列测试图片,点击
下载并解压,然后在终端中切换到相应目录(/path/to/ppocr_img填你实际的目录)cd /path/to/ppocr_img
检测+方向分类器+识别全流程:--use_angle_cls true
设置使用方向分类器识别180度旋转文字,--use_gpu false
设置不使用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/、
再次出现问题:ImportError: numpy.core.multiarray failed to import
在终端输入:
python
import numpy
print(numpy.__path__)
exit()
删除显示的路径
重新安装numpy
调试程序:检测+方向分类器+识别全流程
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')

结果
