五、调试chineseocr-app
- 首先,将这个项目先下载下来:git clone https://github.com/chineseocr/chineseocr.git
先看readme,根据readme配置环境,参考setup.md和setup-cpu.md
conda create -n chineseocr python=3.6 pip
scipy numpy jupyter ipython ##运用conda 创建python环境
source activate chineseocr #激活环境
安装必要的模型包
git submodule init && git submodule
update
pip install easydict
opencv-contrib-python==4.0.0.21 Cython h5py lmdb mahotas pandas requests bs4
matplotlib lxml -i https://pypi.tuna.tsinghua.edu.cn/simple/
pip install -U pillow -i
https://pypi.tuna.tsinghua.edu.cn/simple/
pip install keras2.1.5 tensorflow1.8
tensorflow-gpu==1.8
pip install web.py==0.40.dev0 redis
conda install pytorch torchvision -c
pytorch
pip install torch torchvision
在这里,我用pip安装的时候,会有一些红色的错误代码,查了查,是下载源的问题,然后我制定下载源下载
pip install 需要下载的模块 -i https://pypi.doubanio.com/simple
然后下载速度就比较稳定也比较快了而且也不会出错误
- 下载编译darknet
git clone
https://github.com/pjreddie/darknet.git
下载完之后移动到chineseocr文件下
3.然后##编译对GPU、cudnn的支持
修改 Makefile
#GPU=1
#CUDNN=1
#OPENCV=0
#OPENMP=0
Make
- 修改 darknet/python/darknet.py line 48
root = ‘/root/’##chineseocr所在目录
lib =
CDLL(root+“chineseocr/darknet/libdarknet.so”, RTLD_GLOBAL)
模型文件地址:
复制文件夹中的所有文件到models目录
模型转换
pytorch ocr 转keras ocr
darknet 转keras
有一个错误 把encoding=’utf-8’去掉 然后成功
keras 转darknet
去掉encoding=’utf-8’之后又有错误,不过还是这个错误所以,找到文件的281行 去掉它即可
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-s8JYGKpB-1588321106788)(https://img-bluog.csdnimg.cn/20200501160716335.png)]
模型转化完成
- 编译语言模型(可选)
git clone
–recursive https://github.com/parlance/ctcdecode.git
cd ctcdecode
pip install .
## 下载语言模型 (可选)
```Bash
wget
https:/'t/deepspeech.bj.bcebos.com/zh_lm/zh_giga.no_cna_cmn.prune01244.klm
mv
zh_giga.no_cna_cmn.prune01244.klm chineseocr/models/
模型选择
参考config.py文件
##下载Anaconda3 python 环境安装包(https://repo.anaconda.com/archive/Anaconda3-2019.03-Linux-x86_64.sh)
放置在chineseocr目录下
##建立镜像
docker build -t
chineseocr .
##启动服务
docker run -d -p
8080:8080 chineseocr /root/anaconda3/bin/python app.py
没有doocker首先需要安装一个docker 先更新apt包索引sudo apt-get update 然后安装
测试 Docker 是否安装成功,输入以下指令sudo docker
run hello-world
打印出以下信息则安装成功:
Unable to find image
‘hello-world:latest’ locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
u
Digest: sha256:c3b4ada4687bbaa170745b3e4dd8ac3f194ca95b2d0518b417fb47e5879d9b5f
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
-
The Docker client contacted the Docker daemon.
-
The Docker daemon pulled the “hello-wo’grld” image from the
Docker Hub.(amd64)
-
The Docker daemon created a new container from that image which
runs theexecutable that produces the output you are currently reading.
-
The Docker daemon streamed that output to the Docker client, which
sent itto your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.ceom/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
docker是安装在根目录下的,有十几G吧,根目录的空间一定要够。安装完之后检测一下是否安装成功docker -V 在运行docker的时候还需要docker login 登录一下 否则的话会出现这个错误:docker: Error response from daemon: pull access denied for chineseocr, repository does not exist or may require 'docker login': denied: requested access to the resource is denied.
建立镜像和启动服务的时候需要加sudo 因为我的根目录空间不足,所以建立镜像的时候,安到一半满了
根目录已经满了 然后我又找到了一篇博客,把docker从根目录迁移到home里面,然后第一次迁移,有部分没有迁移过去,然后又迁移了一遍,然后home满了,Ubuntu打不开了,然后进入命令行模式,把home目录下的文件删了删,进入到了图形界面,home里腾出了20多G空间,最后把docker迁移到了home里面,然后再构建镜像,然后启动服务,最后成功
了。
web服务启动
cd chineseocr## 进入chineseocr目录
python app.py 8080 ##8080端口号,可以设置任意端口
对于python2.7来说
去掉*
改为
然后app.py运行成功
再## 访问服务
http://127.0.0.1:8080/ocr
结果图: