PaddleOCR simple text recognition use (1)

Look at the renderings first

Insert picture description here

Insert picture description here
The effect is okay, no, you can actually adjust it yourself, but I am basically not enough, so I won't talk about it.I wrote down the pitfalls of setting up the environment and I forgot it.

Set up the environment before use. Here, because the computer of the linux system is not at hand, it is built on win. The cpu used in the python3.7 pycharm development environment old notebook does not have a GPU.

1. Configure the environment under the paddlepaddle framework

First look at the official quick installation link: quick installation

Install the requirements of the official documentation here. For example, he wants paddlepaddle version 1.8 or higher, and then I only have 1.7, so I need to update. Currently, the official recommendation is to install to 2.0 and install to 2.0.
Here, because there is no discrete graphics card, the first step is saved. , The driver for students with GPU is installed, follow the official document slowly

2. Install PaddlePaddle v2.0

python3 -m pip install --upgrade pip

如果您的机器安装的是CUDA9或CUDA10,请运行以下命令安装
python3 -m pip install paddlepaddle-gpu==2.0.0b0 -i https://mirror.baidu.com/pypi/simple

如果您的机器是CPU,请运行以下命令安装

python3 -m pip install paddlepaddle==2.0.0b0 -i https://mirror.baidu.com/pypi/simple

Since I am running python3 -m in the Terminal of pycharm, I don't need it, I just pip install directly.

As shown

Insert picture description here
It is worth noting here that students who use anaconda, pay attention not to put Kuan wrong, if you are not sure of the python environment for the terminal, it is best to open the window of anaconda corresponding to the python environment (I was pitted the day before yesterday)

3. Clone the PaddleOCR repo code
. Before cloning, remember to enter the folder you created in the operation window so as not to find it, and use the hosting on the code cloud, otherwise it will be too slow

【推荐】git clone https://github.com/PaddlePaddle/PaddleOCR

如果因为网络问题无法pull成功,也可选择使用码云上的托管:

git clone https://gitee.com/paddlepaddle/PaddleOCR

注:码云托管代码可能无法实时同步本github项目更新,存在3~5天延时,请优先使用推荐方式。

4. Install third-party libraries
. Remember to enter the right directory here.

cd PaddleOCR
python3 -m pip install -r requirements.txt

The official said here to note that in the windows environment, it is recommended to download the shapely installation package from here to complete the installation. The shapely library installed directly through pip may have a problem that [winRrror 126] cannot find the specified module. I didn't encounter it when I installed it. In case anyone encounters it, I will manually download the shapely installation package first. After installation, install the package in the requirements.txt file.

Note that in case there is an error of the installation package is not complete, use the installation again, the following library. (Generally, it is complete)

#由于PaddleHub升级比较快,建议大家直接升级到最新版本的PaddleHub,无需指定版本升级
pip install paddlehub --upgrade -i https://pypi.tuna.tsinghua.edu.cn/simple 
#该Module依赖于第三方库shapely、pyclipper,使用该Module之前,请先安装shapely、pyclipper
pip install shapely -i https://pypi.tuna.tsinghua.edu.cn/simple 
pip install pyclipper -i https://pypi.tuna.tsinghua.edu.cn/simple

5. Adjust the downloaded official source code

First of all, students who use ide remember to put the PaddleOCR folder, right-click to select the mark directory as source code (always forget, alas...)

Secondly, some folders are not available under PaddleOCR, so they must be created first,

inference      det_db            inference_results              models
```![在这里插入图片描述](https://img-blog.csdnimg.cn/20201206222459389.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzEzNDA0OQ==,size_16,color_FFFFFF,t_70)


![在这里插入图片描述](https://img-blog.csdnimg.cn/20201204192318478.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzEzNDA0OQ==,size_16,color_FFFFFF,t_70)

不要问我为什么知道要创建这些,问就是看的启动命令,所以说用其他模型同理.


还有在实际运行的时候,PaddleOCR\tools\infer\predict_det.py的

```python
import tools.infer.utility as utility

The quote is not reported wrong, and then I found that the package to be quoted is in its same level directory...
So I changed this comment and changed it directly to

import utility

Insert picture description here

At this time, it's basically ok

Now let’s prepare the model for text recognition.
Remember to create the folders and their subfolders that are not available.
Insert picture description here

Two, model preparation

Official description link: click to enter

Here I chose the model based on the Resnet50_vd backbone network and trained on the ICDAR2015 English data set, as shown in the figure below.

After downloading the model link , unzip it and place it in the PaddleOCR\models\det_r50_vd_db folder, (oh, this det_r50_vd_db folder also needs to be created by yourself)
Insert picture description here
and run

python tools/export_model.py -c configs/det/det_r50_vd_db.yml -o Global.checkpoints="./models/det_r50_vd_db/best_accuracy" Global.save_inference_dir="./inference/det_db"

To generate the converted model in the PaddleOCR\inference\det_db folder
Insert picture description here

The last command is enough, oh remember to change to your own picture path, the final generated picture is in the PaddleOCR\inference_results folder.

python tools/infer/predict_det.py --image_dir="./doc/imgs_en/img_10.jpg" --det_model_dir="./inference/det_db/"

Guess you like

Origin blog.csdn.net/weixin_43134049/article/details/110670762