1、参考文档
#1、安装paddle
https://github.com/PaddlePaddle/PaddleOCR/blob/static/doc/doc_ch/installation.md
#2、基于Python预测引擎推理
https://gitee.com/paddlepaddle/PaddleOCR/blob/release/2.1/doc/doc_ch/inference.md
#3、paddleOCR使用说明
https://gitee.com/paddlepaddle/PaddleOCR/blob/develop/doc/doc_ch/whl.md#自定义模型
https://github.com/PaddlePaddle/PaddleOCR/blob/release/2.6/PPOCRLabel/README_ch.md
https://zhuanlan.zhihu.com/p/435118207 #文本标注、训练检测模型、训练识别模型
https://blog.csdn.net/didiaopao/article/details/119541103
#4、脚本测试文字检测和识别效果
from paddleocr import PaddleOCR, draw_ocr
import time
t1 = time.time()
#自训练模型
#ocr = PaddleOCR(det_model_dir='./inference/ch_ppocr_mobile_v1.1_det_infer/', rec_model_dir='./inference/ch_ppocr_mobile_v1.1_rec_infer/', cls_model_dir='./inference/ch_ppocr_mobile_v1.1_cls_infer/', use_angle_cls=True) # need to run only once to download and load model into memory
ocr = PaddleOCR()
# enable_mkldnn=True,use_tensorrt=True,use_angle_cls=False
img_path = 'imgs/101.jpg'
result = ocr.ocr(img_path)
t2 = time.time() - t1
print(t2)
#for line in result:
#print(line)
# 显示结果
from PIL import Image
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]
im_show = draw_ocr(image, boxes, txts, scores, font_path='imgs/fonts/simfang.ttf')
im_show = Image.fromarray(im_show)
im_show.save('result.jpg')
2、windows11主机虚拟环境搭建文本标注环境、模型训练环境
#1、安装python3.7.7
#官网下载链接https://www.python.org/ftp/python/3.7.7/python-3.7.7-amd64.exe
#下载完后安装python3.7
#2、安装虚拟环境工具https://blog.csdn.net/liuchunming033/article/details/79582617
pip install pipenv
#3、创建项目目录,进入目录
#4、创建虚拟环境
pipenv --python 3.7.7
#5、进入虚拟环境
pipenv shell
(PaddleOCR-_5YaYxkJ) C:\Users\pml\Desktop\test\src\PaddleOCR>python -V
Python 3.7.7
(PaddleOCR-_5YaYxkJ) C:\Users\pml\Desktop\test\src\PaddleOCR>pip -V
pip 22.3.1 from C:\Users\pml\.virtualenvs\PaddleOCR-_5YaYxkJ\lib\site-packages\pip (python 3.7)
#6、更新pip(可选)
python -m pip install --upgrade pip
#项目目录会生成Pipfile文件
修改:url = "https://mirror.baidu.com/pypi/simple"
#7、安装paddlepaddle
#如果您的机器安装的是CUDA9或CUDA10,请运行以下命令安装,官方建议2.4.2
python -m pip install paddlepaddle-gpu==2.0.2 -i https://mirror.baidu.com/pypi/simple
#如果您的机器是CPU,请运行以下命令安装
python -m pip install paddlepaddle==2.0.2 -i https://mirror.baidu.com/pypi/simple
#8、从码云克隆代码
git clone https://gitee.com/paddlepaddle/PaddleOCR
#进入代码目录
cd PaddleOCR
# 安装的版本不能太新(最新版第三方库安装会报错),故而切换到2.0版本cd PaddleOCR
git checkout origin/release/2.0
#9、安装第三方库,PyWavelets需要单独安装
pip install PyWavelets
pip install -r requirements.txt -i https://mirror.baidu.com/pypi/simple
#备注
#shapely库不要使用pip安装,使用官方推荐网址(https://www.lfd.uci.edu/~gohlke/pythonlibs/#shapely)下载Shapely-1.8.1.post1-cp37-cp37m-win_amd64.whl
#安装pip install Shapely-1.8.1.post1-cp37-cp37m-win_amd64.whl
#10、安装PPOCRLabel
pip install PPOCRLabel -i https://mirror.baidu.com/pypi/simple
# 选择标签模式来启动
PPOCRLabel --lang ch # 启动【普通模式】,用于打【检测+识别】场景的标签
PPOCRLabel --lang ch --kie True # 启动 【KIE 模式】,用于打【检测+识别+关键字提取】场景的标签
3、调研 PPOCRLabel模块文本标注功能使用自定义数据集、训练检测模型、训练识别模型
https://zhuanlan.zhihu.com/p/435118207
#文本标注
https://gitee.com/paddlepaddle/PaddleOCR/blob/release/2.1/PPOCRLabel/README_ch.md
#文字检测模型
https://gitee.com/paddlepaddle/PaddleOCR/blob/release/2.1/doc/doc_ch/detection.md
#文字识别模型
https://gitee.com/paddlepaddle/PaddleOCR/blob/release/2.1/doc/doc_ch/recognition.md
4、制作训练数据集
#使用PPOCRLabel进行文本标注、导出标识结果label文件、划分数据集
5、训练模型
#安装依赖pip install pyyaml Levenshtein -i https://pypi.douban.com/simple
#修改配置文件configs/rec/multi_language/rec_en_number_lite_train.yml
训练集和测试卷的label_file_list和data_dir路径要正确
load_static_weights: False
use_gpu: false
#1、训练检测模型
#(1)训练
#python tools/train.py -c configs/det/det_mv3_east.yml -o Global.pretrain_weights=./pretrain_models/ResNet18_vd_pretrained/
python tools/train.py -c configs/det/det_mv3_db.yml -o Global.pretrain_weights=./pretrain_models/ResNet18_vd_pretrained/
python tools/train.py -c configs/det/det_mv3_db.yml -o Global.pretrain_weights=./pretrain_models/MobileNetV3_large_x0_5_pretrained/
#(2)预测
python tools/infer_det.py -c configs/det/det_mv3_db.yml -o Global.infer_img="./train_data/test/104.jpg" Global.pretrained_model="./output/db_mv3/latest" Global.load_static_weights=false
#(3)导出模型
Python tools/export_model.py -c configs/det/det_mv3_db.yml -o Global.pretrained_model="./output/db_mv3/latest" Global.load_static_weights=False Global.save_inference_dir=./inference/db_mv3/
#2、训练识别模型
python tools/train.py -c configs/rec/rec_icdar15_train.yml -o Global.pretrain_weights=./pretrain_models/en_number_mobile_v2.0_rec_slim_train/
python tools/train.py -c configs/rec/rec_en_number_lite_train.yml -o Global.pretrain_weights=./pretrain_models/en_number_mobile_v2.0_rec_slim_train/
python tools/infer_rec.py -c configs/rec/rec_en_number_lite_train.yml -o Global.infer_img="train_data/rec/test/2_37.jpg" Global.pretrained_model="./output/db_mv3/latest" Global.load_static_weights=false