【cnocr的安装使用】

docker环境

  1. 由于docker hub无法正常访问,导致cnocr的docker镜像无法拉取,所以只能自己做一个docker镜像
  2. Dockerfile如下
FROM python:3.8

RUN pip install cnocr[ort-cpu] -i https://pypi.tuna.tsinghua.edu.cn/simple
  1. 原cnocr中使用的是阿里云镜像,但是实测下载速度超慢,所以切换为https://pypi.tuna.tsinghua.edu.cn/simple 清华镜像源
  2. 下载完成后,使用docker build -t cnocr:qinghua . 生成docker镜像
  3. 使用docker run -it -p 8501:8501 cnocr:qinghua bash 启动镜像
  4. 此时还需要导入cnocr已经训练好的模型数据,可直接从百度云盘下载cnocr模型百度网盘链接,当然也可以使用cnocr在线操作手册去找
  5. 下载完毕后,需要将模型zip压缩文件导入镜像中的/root/.cnocr/2.3目录下
  6. docker环境准备完毕

运行操作

  • 第一次运行时会缺少很多python模块,所以按命令 cnocr serve -p 8501 运行

1.libGL.so.1错误

ImportError: libGL.so.1: cannot open shared object file: No such file or dir

需要安装opencv-python-headless模块

pip uninstall opencv-python -y
pip install opencv-python-headless -i https://pypi.tuna.tsinghua.edu.cn/simple

2.uvicorn错误

FileNotFoundError: [Errno 2] No such file or directory: 'uvicorn'

需要安装uvicorn模块

pip install uvicorn -i https://pypi.tuna.tsinghua.edu.cn/simple

3.pydantic错误

FileNotFoundError: [Errno 2] No such file or directory: 'uvicorn'

需要安装pydantic模块

pip install pydantic -i https://pypi.tuna.tsinghua.edu.cn/simple

4.fastapi错误

FileNotFoundError: [Errno 2] No such file or directory: 'fastapi'

需要安装fastapi模块

pip install fastapi -i https://pypi.tuna.tsinghua.edu.cn/simple

5.cnocr错误

FileNotFoundError: [Errno 2] No such file or directory: 'cnocr'

需要安装cnocr模块,切记此时不要安装cnocr[serve],否则会出现一堆其他问题,安装了这个之后,建议重新卸载opencv-python模块及cnocr模块,重新安装

pip install cnocr -i https://pypi.tuna.tsinghua.edu.cn/simple

6.其他的问题就只能搜索解决了

  • 问题都解决之后,就可以后台运行了

  • nohup cnocr serve -p 8501 > /home/cnocr.log 2>&1 &

  • 运行原理就是如下文件
    /usr/local/bin/cnocr 调用 /usr/local/lib/python3.8/site-packages/cnocr/cli.py cli方法,然后调用/usr/local/lib/python3.8/site-packages/cnocr/serve.py 启动FastAPI服务

  • serve.py只使用了基础模型,可以手动修改serve.py以方便外界调用切换模型

外界调用

  • curl -F image=@1_副.jpg http://0.0.0.0:8501/ocr
  • 上面的图片名称1_副.jpg就在当前目录下,@是为了将其转换为需要传输的数据格式类型

模型训练及其他操作正在实践中

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值