飞桨AI应用@riscv OpenKylin

在riscv编译安装飞桨PaddlePaddle参见:

算能RISC-V通用云编译飞桨paddlepaddle@openKylin留档_在riscv下进行paddlelite源码编译-CSDN博客

安装好飞桨,就可以用飞桨进行推理了。刚开始计划用ONNX推理,但是在算能云没有装上,所以最终是用的飞桨推理。但是还是用到了Paddle2ONNX里的代码。

下载Paddle2ONNX源代码

git clone https://github.com/PaddlePaddle/Paddle2ONNX

ocr文字识别

下面是使用ONNX进行推理的示例,我没有弄成,希望有成功的朋友交流下经验。

安装需要的库

pip install shapely pyclipper

如果在riscv系统无法编译安装shapely,那么可以先安装包:

apt install libgeos-dev

下载相关模型文件

复制代码
cd Paddle2ONNX/model_zoo/ocr

# 下载det模型
wget https://bj.bcebos.com/paddle2onnx/model_zoo/ch_PP-OCRv2_det_infer.onnx

# 下载rec模型
wget https://bj.bcebos.com/paddle2onnx/model_zoo/ch_PP-OCRv2_rec_infer.onnx

# 下载cls模型
wget https://bj.bcebos.com/paddle2onnx/model_zoo/ch_ppocr_mobile_v2.0_cls_infer.onnx

进行识别

复制代码
python3 infer.py  \
--det_model_dir=./ch_PP-OCRv2_det_infer.onnx  \
--rec_model_dir=./ch_PP-OCRv2_rec_infer.onnx  \
--cls_model_dir=./ch_ppocr_mobile_v2.0_cls_infer.onnx  \
--image_path=./images/lite_demo.png

使用飞桨推理进行文字识别

这个推理成功了。

下载和解压模型

复制代码
wget -nc  -P ./inference https://bj.bcebos.com/paddle2onnx/model_zoo/ch_PP-OCRv2_det_infer.tar
cd ./inference && tar xf ch_PP-OCRv2_det_infer.tar && cd ..

wget -nc  -P ./inference https://bj.bcebos.com/paddle2onnx/model_zoo/ch_PP-OCRv2_rec_infer.tar
cd ./inference && tar xf ch_PP-OCRv2_rec_infer.tar && cd ..

wget -nc  -P ./inference https://bj.bcebos.com/paddle2onnx/model_zoo/ch_ppocr_mobile_v2.0_cls_infer.tar
cd ./inference && tar xf ch_ppocr_mobile_v2.0_cls_infer.tar && cd ..

进行文字识别

复制代码
python3 infer.py \
--cls_model_dir=./inference/ch_ppocr_mobile_v2.0_cls_infer \
--rec_model_dir=./inference/ch_PP-OCRv2_rec_infer \
--det_model_dir=./inference/ch_PP-OCRv2_det_infer \
--image_path=./images/lite_demo.png \
--use_paddle_predict=True

推理识别结果

输出可紧致头发磷层,从而达到0.99444813即时持久改善头发光泽的效果,给干燥的头0.99019814发足够的滋养0.997668花费了0.457335秒

效果还不错

调试

ocr读取文件的时候报错:

Python 3.11.0rc2 (main, Sep 4 2023, 07:22:49) [GCC 9.3.0] on linux

Type "help", "copyright", "credits" or "license" for more information.

>>> import cv2

Traceback (most recent call last):

File "<stdin>", line 1, in <module>

File "/root/py311/lib/python3.11/site-packages/cv2/init.py", line 8, in <module>

from .cv2 import *

ImportError: libtiff.so.6: cannot open shared object file: No such file or directory

安装libtiff

pip install pylibtiff

结果还是报错

找到libtiff.so.5文件在/lib/riscv64-linux-gnu,做了个链接。

ln -s libtiff.so.5 libtiff.so.6

报错ImportError: libgtk-x11-2.0.so.0

SyntaxError: invalid syntax

(py311) root@863c89a419ec:~/github/Paddle2ONNX/model_zoo/ocr# python -c "import cv2"

Traceback (most recent call last):

File "<string>", line 1, in <module>

File "/root/py311/lib/python3.11/site-packages/cv2/init.py", line 8, in <module>

from .cv2 import *

ImportError: libtiff.so.6: cannot open shared object file: No such file or directory

(py311) root@863c89a419ec:~/github/Paddle2ONNX/model_zoo/ocr# python -c "import cv2"

Traceback (most recent call last):

File "<string>", line 1, in <module>

File "/root/py311/lib/python3.11/site-packages/cv2/init.py", line 8, in <module>

from .cv2 import *

ImportError: libgtk-x11-2.0.so.0: cannot open shared object file: No such file or directory

安装包:apt-get install libgtk2.0-dev

ok了

识别是numpy.int报错

File "/root/github/Paddle2ONNX/model_zoo/ocr/utils/predict_det.py", line 210, in box_score_fast

xmin = np.clip(np.floor(box[:, 0].min()).astype(np.int), 0, w - 1)

File "/usr/local/lib/python3.8/dist-packages/numpy/init.py", line 305, in getattr

raise AttributeError(former_attrs[attr])

AttributeError: module 'numpy' has no attribute 'int'.

`np.int` was a deprecated alias for the builtin `int`. To avoid this error in existing code, use `int` by itself. Doing this will not modify any behavior and is safe. When replacing `np.int`, you may wish to use e.g. `np.int64` or `np.int32` to specify the precision. If you wish to review your current use, check the release note link for additional information.

The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:

进入/root/github/Paddle2ONNX/model_zoo/ocr/utils/predict_det.py源码,把np.int都改成np.int32

相关推荐
云知谷4 小时前
【C++基本功】C++适合做什么,哪些领域适合哪些领域不适合?
c语言·开发语言·c++·人工智能·团队开发
rit84324995 小时前
基于MATLAB实现基于距离的离群点检测算法
人工智能·算法·matlab
初学小刘6 小时前
深度学习:从图片数据到模型训练(十分类)
人工智能·深度学习
递归不收敛6 小时前
大语言模型(LLM)入门笔记:嵌入向量与位置信息
人工智能·笔记·语言模型
之墨_7 小时前
【大语言模型】—— 自注意力机制及其变体(交叉注意力、因果注意力、多头注意力)的代码实现
人工智能·语言模型·自然语言处理
从孑开始8 小时前
ManySpeech.MoonshineAsr 使用指南
人工智能·ai·c#·.net·私有化部署·语音识别·onnx·asr·moonshine
涛涛讲AI8 小时前
一段音频多段字幕,让音频能够流畅自然对应字幕 AI生成视频,扣子生成剪映视频草稿
人工智能·音视频·语音识别
可触的未来,发芽的智生8 小时前
新奇特:黑猫警长的纳米世界,忆阻器与神经网络的智慧
javascript·人工智能·python·神经网络·架构
WWZZ20258 小时前
快速上手大模型:机器学习2(一元线性回归、代价函数、梯度下降法)
人工智能·算法·机器学习·计算机视觉·机器人·大模型·slam
AKAMAI9 小时前
数据孤岛破局之战 :跨业务分析的难题攻坚
运维·人工智能·云计算