✨写在前面:强烈推荐给大家一个优秀的人工智能学习网站,内容包括人工智能基础、机器学习、深度学习神经网络等,详细介绍各部分概念及实战教程,通俗易懂,非常适合人工智能领域初学者及研究者学习。➡️点击跳转到网站。
面对飞速发展互联网医疗时代,医疗信息化建设已经成为医疗行业发展的趋势。经调研,约80%的医学病历是处于非结构化状态的,难以直接被利用而造成了大量医学资源浪费。医疗数据中大量的半结构化与无结构化的文本,医学术语的专业性以及语言表达的多样性为结构化信息抽取带来了很大难度。因此,针对电子病历和报告的信息识别抽取和结构化管理对临床诊断、疾病预防与医学研究具有重要意义。
体检报告识别可以帮助医务服务人员自动识别录入用户征信信息,节约人力成本、提升服务效率,实现降本增效,具有重要实际意义。基于PaddleOCR已在文字识别领域取得优秀成果,本项目基于PaddleOCR实现体检报告检测与识别,对数据进行结构化处理,结合CV+NLP技术达到一定识别精度,未来推广应用场景可以基于识别信息做个性化疾病预测与健康推荐。
PaddleOCR体检报告识别 - 飞桨AI Studio
PaddleOCR是百度开源的超轻量级OCR模型库,本文使用其框架进行体检报告识别,本次项目具体流程包括:
针对PaddleOCR提供的算法模型,本次选择基础模型用于体检报告识别与检测,流程如下:
文字检测参考这篇:
CRNN可参考这篇文章:
CRNN文字识别_GoAI的博客-CSDN博客_crnn
数据位置: data/data159696/report_ex.tar
解压命令 !tar -xf /home/aistudio/data/data159696/report_ex.tar
数据集结构:
/home/aistudio/report_ex
└─ pngs:存放体检照片,以pngs形式结尾
└─ txts: 存放标注坐标信息及包含内容.
└─ json:内容同上 ,存放json格式信息。
数据集txt格式为:
Rect (182.0, 1078.03125, 266.0, 1064.03125) 姓名:张某某
Rect (356.0, 1078.03125, 412.0, 1064.03125) 性别:男
Rect (516.0, 1078.03125, 572.0, 1064.03125) 年龄:40
图片样式:
安装PaddleOCR相关环境
%cd ~
!git clone -b release/2.1 https://github.com/PaddlePaddle/PaddleOCR.git
# 安装依赖库
%cd ~/PaddleOCR
!pip install -r requirements.txt -i https://mirror.baidu.com/pypi/simple
下载PaddleOCR中文轻量级OCR模型用于测试部分图像识别结果,模型存放在在PaddleOCR/inference目录下。
In [ ]
! mkdir inference
# 下载超轻量级中文OCR模型的检测模型并解压
! cd inference && wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_det_infer.tar && tar xf ch_ppocr_mobile_v2.0_det_infer.tar && rm ch_ppocr_mobile_v2.0_det_infer.tar
# 下载超轻量级中文OCR模型的识别模型并解压
! cd inference && wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_rec_infer.tar && tar xf ch_ppocr_mobile_v2.0_rec_infer.tar && rm ch_ppocr_mobile_v2.0_rec_infer.tar
# 下载超轻量级中文OCR模型的文本方向分类器模型并解压
! cd inference && wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_cls_infer.tar && tar xf ch_ppocr_mobile_v2.0_cls_infer.tar && rm ch_ppocr_mobile_v2.0_cls_infer.tar
In [ ]
import matplotlib.pyplot as plt
from PIL import Image
%pylab inline
def show_img(img_path,figsize=(10,10)):
## 显示原图,读取名称为11.jpg的测试图像
img = Image.open(img_path)
plt.figure("test_img", figsize=figsize)
plt.imshow(img)
plt.show()
show_img("../20220623110401-0.png")
Populating the interactive namespace from numpy and matplotlib
调用tools/infer/predict_system.py 完成报告识别,共需要传入三个参数:
In [ ]
# 快速运行
!python3 ./tools/infer/predict_system.py --image_dir="../20220623110401-0.png" \
--det_model_dir="./inference/ch_ppocr_mobile_v2.0_det_infer" \
--rec_model_dir="./inference/ch_ppocr_mobile_v2.0_rec_infer" \
--cls_model_dir="./inference/ch_ppocr_mobile_v2.0_cls_infer"
In [27]
# 训练效果
!python3 ./tools/infer/predict_system.py --image_dir="../20220623110401-0.png" \
--det_model_dir="./outputall/db_mv3/best_accuracy" \
--rec_model_dir="./output/rec/best_accuracy" \
--cls_model_dir="./inference/ch_ppocr_mobile_v2.0_cls_infer"
上述结果说明:输出结果中有两列数据,第一列表示PaddleOCR识别出的文字,第二列表示识别出当前文字的置信度。置信度的数据范围是[0-1],置信度越接近1表示文本识别对的“信心”越大。 同时,识别结果会可视化在图像中并保存在./inference_results文件夹下,可以通过左边的目录结构选择要打开的文件, 也可以通过如下代码将可视化后的图像显示出来,观察OCR文本识别的效果。
针对上述./inference_results/20220623110401-0.png检测结果展示如下:
In [ ]
show_img("./inference_results/20220623110401-0.png",figsize=(20,20))
PaddOCR官方检测模型数据集以icdar15为例,本文参照其标注格式进行检测模型的训练、评估与测试,模型以MobienetV3网络为例,可自己更改其他网络。
注:官方icdar15数据集存放在 ~/data/data34815/icdar2015.tar ,后续如有数据格式问题可做参考。官方数据~/train_data/icdar2015/text_localization 有两个文件夹和两个文件,分别是:
~/train_data/icdar2015/text_localization
└─ icdar_c4_train_imgs/ icdar数据集的训练数据
└─ ch4_test_images/ icdar数据集的测试数据
└─ train_icdar2015_label.txt icdar数据集的训练标注
└─ test_icdar2015_label.txt icdar数据集的测试标注
官方提供的标注文件格式为:
" 图像文件名 json.dumps编码的图像标注信息"
ch4_test_images/img_61.jpg [{"transcription": "MASA", "points": [[310, 104], [416, 141], [418, 216], [312, 179]], ...}]
json.dumps编码前的图像标注信息是包含多个字典的list,字典中的pointspointspoints表示文本框的四个点的坐标(x, y),从左上角的点开始顺时针排列。 transcriptiontranscriptiontranscription表示当前文本框的文字,在文本检测任务中并不需要这个信息。
首先解压本次体检报告数据到当前目录,解压命令如下:
!tar -xf /home/aistudio/data/data159696/report_ex.tar
#查看当前文件夹图片数量
%cd /home/aistudio/report_ex/pngs
!ls -l | grep "^-" | wc -l #一共20011张图片
/home/aistudio/report_ex/pngs 20011
本次体检报告数据集txt格式为:
Rect (182.0, 1078.03125, 266.0, 1064.03125) 姓名:张某某
Rect (356.0, 1078.03125, 412.0, 1064.03125) 性别:男
Rect (516.0, 1078.03125, 572.0, 1064.03125) 年龄:40
由于数据格式不同,本项目需要编写转换数据程序构建为PaddleOCR标注文件格式, 由于时间原因,格式代码比较粗糙,读者后续可根据需求自行完善。
以1.部分数据集为例的训练相关代码:
/home/aistudio/report_ex/
└─ train_det_new1_hebing/ report_ex数据集的测试数据
└─ test_det_new1_hebing report_ex数据集的测试数据
/home/aistudio/
└─ train_det_new1_hebing.txt.txt report_ex数据集的训练标注
└─ test_det_new1_hebing.txt.txt report_ex数据集的测试标注
└─ gen_data_det_reg.py 格式转换代码
└─ hebing.py 数据合并
└─ split_data.py 切分训练集与测试集
└─ file.py 拷贝训练集与测试集图片到文件夹
/home/aistudio/PaddleOCR
└─ tools/train.py 训练代码
└─ tools/infer_det.py 推理代码
└─ configs/det/det_mv3_db_all.yml 配置文件
下载PaddleOCR主流两种检测模型backbone,MobileNetV3和ResNet50_vd,后续可以根据需求使用PaddleClas中的模型更换backbone。
In [ ]
# 下载MobileNetV3的预训练模型
!pwd
!wget -P ./pretrain_models/ https://paddle-imagenet-models-name.bj.bcebos.com/MobileNetV3_large_x0_5_pretrained.tar
! cd pretrain_models/ && tar xf MobileNetV3_large_x0_5_pretrained.tar
# 下载ResNet50的预训练模型
!wget -P ./pretrain_models/ https://paddle-imagenet-models-name.bj.bcebos.com/ResNet50_vd_ssld_pretrained.tar
! cd pretrain_models/ && tar xf ResNet50_vd_ssld_pretrained.tar
运行转换程序gen_data_det_reg.py,生成det检测和reg识别的txt格式,以实际运行结果为准!
det.txt
20220623110401-0.png [{"transcription":"姓名:张某某","points":[[182.0,4256.125],[266.0,4256.125],[182.0,4312.125],[266.0,4312.125]]}]
20220623110401-0.png [{"transcription":"性别:男","points":[[356.0,4256.125],[412.0,4256.125],[356.0,4312.125],[412.0,4312.125]]}]
20220623110401-0.png [{"transcription":"年龄:40","points":[[516.0,4256.125],[572.0,4256.125],[516.0,4312.125],[572.0,4312.125]]}]
reg.txt
20220623110401-0.png 姓名:张某某
20220623110401-0.png 性别:男
20220623110401-0.png 年龄:40
本次体检报告由于数据量巨大且训练时间长,为了方便大家查看运行效果及调试 ,下列训练用到的数据集会分为 1.部分数据集与 2.全集数据集,脚本命名已写在注释中,按需运行按需打开注释即可。
#1.部分数据集数据转换脚本, 生成det1.txt ,合并后一共一百多张图片, 坐标为横坐标×4 、 纵坐标=图片高度-纵坐标×4 , reg.txt目前没用到。
#执行报错,会出现IndexError: list index out of range, 只生成2万多条数据,但不影响跑。
%cd /home/aistudio/
# !python ./gen_data_det_reg.py
#2.跑全量数据脚本,生成det_all.txt,可以跑通,但全量数据集太大,还未执行,
# %cd /home/aistudio/
!python ./gen_data_all.py
#合并上述生成txt的数据,改为一张照片对应所有坐标合并成一行 ,生成合并后新的txt
#1.部分数据合并 det1.txt,生成det_new_hebing.txt
# !python hebing.py
#2.全量数据合并 det_all.txt,生成det_new_hebing_all.txt
!python hebing_all.py
将检测数据det.txt、识别数据reg.txt 划分训练集和验证集 , 生成train_det.txt 、 test_det.txt、 train_reg.txt 、 test_reg.txt四个文件
In [ ]
#1.划分部分数据集用于训练,将det.txt拆成train_det_new1_hebing.txt和test_det_new1_hebing.txt,注意生成的训练测试集txt名字要跟训练时相同
# !python split_data.py
#2.划分全量数据集,将det_new_hebing_all.txt拆成 train_det_hebing_all.txt和test_det_hebing_all.txt
!python split_data_all.py
20011
#注:拷贝上述训练及验证集图片到对应路径
#编辑file.py打开对应注释,重复执行两次!!! 一次train 、一次test , 生成上述txt对应的图片文件夹包含图片。
#1.部分数据图片拷贝到文件夹,拷贝train_det_new1.txt和test_det_new1.txt包含的图片拷贝到新文件夹./report_ex/train_det_new1和report_ex/test_det_new1,用于测试
# !python file.py
#2.全量数据图片拷贝到文件夹,train_det_hebing_all.txt和test_det_hebing_all.txt包含的图片拷贝到新文件夹./report_ex/train_det_hebing_all和./report_ex/test_det_hebing_all
!python file_all.py
本次选择backbone为MobileNetV3、Resnet50的db算法的检测模型.通过-c 选择训练使用配置文件configs/det/det_db_mv3.yml配置文件,-o参数在不需要修改yml文件的情况下,改变训练的参数
In [ ]
# 官方训练backbone为MobileNetV3的db算法的检测模型,此部分只做参考,不用执行!
# !python3 PaddleOCR/tools/train.py -c PaddleOCR/configs/det/det_mv3_db.yml -o \
# Global.eval_batch_step="[0,500]" \
# Global.load_static_weights=true \
# Global.pretrained_model='PaddleOCR/pretrain_models/MobileNetV3_large_x0_5_pretrained' \
# Train.dataset.data_dir='PaddleOCR/train_data/text_localization/' \
# Train.dataset.label_file_list=['PaddleOCR/train_data/text_localization/train_icdar2015_label.txt'] \
# Eval.dataset.data_dir='PaddleOCR/train_data/text_localization/' \
# Eval.dataset.label_file_list=['PaddleOCR/train_data/text_localization/test_icdar2015_label.txt']
#每次启动运行结果提示缺少包执行此条安装相关环境
!pip install lmdb
!pip install pyclipper
!pip install Levenshtein
!pip install imgaug
由于数据量较大且训练时间较长,针对上述两种不同数据集大小,本次训练分别列出全量及部分数据集训练代码,可按需选择。
In [ ]
#1.合并后全量数据集+MobileNetV3检测模型训练
%cd /home/aistudio/
!python3 PaddleOCR/tools/train.py -c PaddleOCR/configs/det/det_mv3_db_all.yml -o \
Global.eval_batch_step="[0,300]" \
Global.load_static_weights=true \
Global.checkpoints='./outputall/db_mv3/best_accuracy' \
Global.pretrained_model='PaddleOCR/pretrain_models/MobileNetV3_large_x0_5_pretrained' \
Train.loader.batch_size_per_card=32 \
Train.dataset.data_dir='./report_ex/train_det_hebing_all' \
Train.dataset.label_file_list=['./train_det_hebing_all.txt'] \
Eval.dataset.data_dir='./report_ex/test_det_hebing_all' \
Eval.dataset.label_file_list=['./test_det_hebing_all.txt']
/home/aistudio /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/layers/utils.py:26: DeprecationWarning: `np.int` is a deprecated alias for the builtin `int`. To silence this warning, 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. Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations def convert_to_list(value, n, name, dtype=np.int): [2022/08/10 15:52:35] root INFO: Architecture : [2022/08/10 15:52:35] root INFO: Backbone : [2022/08/10 15:52:35] root INFO: model_name : large [2022/08/10 15:52:35] root INFO: name : MobileNetV3 [2022/08/10 15:52:35] root INFO: scale : 0.5 [2022/08/10 15:52:35] root INFO: Head : [2022/08/10 15:52:35] root INFO: k : 50 [2022/08/10 15:52:35] root INFO: name : DBHead [2022/08/10 15:52:35] root INFO: Neck : [2022/08/10 15:52:35] root INFO: name : DBFPN [2022/08/10 15:52:35] root INFO: out_channels : 256 [2022/08/10 15:52:35] root INFO: Transform : None [2022/08/10 15:52:35] root INFO: algorithm : DB [2022/08/10 15:52:35] root INFO: model_type : det [2022/08/10 15:52:35] root INFO: Eval : [2022/08/10 15:52:35] root INFO: dataset : [2022/08/10 15:52:35] root INFO: data_dir : ./report_ex/test_det_hebing_all [2022/08/10 15:52:35] root INFO: label_file_list : ['./test_det_hebing_all.txt'] [2022/08/10 15:52:35] root INFO: name : SimpleDataSet [2022/08/10 15:52:35] root INFO: transforms : [2022/08/10 15:52:35] root INFO: DecodeImage : [2022/08/10 15:52:35] root INFO: channel_first : False [2022/08/10 15:52:35] root INFO: img_mode : BGR [2022/08/10 15:52:35] root INFO: DetLabelEncode : None [2022/08/10 15:52:35] root INFO: DetResizeForTest : [2022/08/10 15:52:35] root INFO: image_shape : [736, 1280] [2022/08/10 15:52:35] root INFO: NormalizeImage : [2022/08/10 15:52:35] root INFO: mean : [0.485, 0.456, 0.406] [2022/08/10 15:52:35] root INFO: order : hwc [2022/08/10 15:52:35] root INFO: scale : 1./255. [2022/08/10 15:52:35] root INFO: std : [0.229, 0.224, 0.225] [2022/08/10 15:52:35] root INFO: ToCHWImage : None [2022/08/10 15:52:35] root INFO: KeepKeys : [2022/08/10 15:52:35] root INFO: keep_keys : ['image', 'shape', 'polys', 'ignore_tags'] [2022/08/10 15:52:35] root INFO: loader : [2022/08/10 15:52:35] root INFO: batch_size_per_card : 1 [2022/08/10 15:52:35] root INFO: drop_last : False [2022/08/10 15:52:35] root INFO: num_workers : 8 [2022/08/10 15:52:35] root INFO: shuffle : False [2022/08/10 15:52:35] root INFO: use_shared_memory : False [2022/08/10 15:52:35] root INFO: Global : [2022/08/10 15:52:35] root INFO: cal_metric_during_train : False [2022/08/10 15:52:35] root INFO: checkpoints : ./outputall/db_mv3/best_accuracy [2022/08/10 15:52:35] root INFO: debug : False [2022/08/10 15:52:35] root INFO: distributed : False [2022/08/10 15:52:35] root INFO: epoch_num : 1200 [2022/08/10 15:52:35] root INFO: eval_batch_step : [0, 500] [2022/08/10 15:52:35] root INFO: infer_img : ./20220623110401-0.png [2022/08/10 15:52:35] root INFO: load_static_weights : True [2022/08/10 15:52:35] root INFO: log_smooth_window : 20 [2022/08/10 15:52:35] root INFO: pretrained_model : PaddleOCR/pretrain_models/MobileNetV3_large_x0_5_pretrained [2022/08/10 15:52:35] root INFO: print_batch_step : 10 [2022/08/10 15:52:35] root INFO: save_epoch_step : 1200 [2022/08/10 15:52:35] root INFO: save_inference_dir : None [2022/08/10 15:52:35] root INFO: save_model_dir : /home/aistudio/outputall/db_mv3/ [2022/08/10 15:52:35] root INFO: save_res_path : ./outputall/det_db/predicts_db.txt [2022/08/10 15:52:35] root INFO: use_gpu : True [2022/08/10 15:52:35] root INFO: use_visualdl : False [2022/08/10 15:52:35] root INFO: Loss : [2022/08/10 15:52:35] root INFO: alpha : 5 [2022/08/10 15:52:35] root INFO: balance_loss : True [2022/08/10 15:52:35] root INFO: beta : 10 [2022/08/10 15:52:35] root INFO: main_loss_type : DiceLoss [2022/08/10 15:52:35] root INFO: name : DBLoss [2022/08/10 15:52:35] root INFO: ohem_ratio : 3 [2022/08/10 15:52:35] root INFO: Metric : [2022/08/10 15:52:35] root INFO: main_indicator : hmean [2022/08/10 15:52:35] root INFO: name : DetMetric [2022/08/10 15:52:35] root INFO: Optimizer : [2022/08/10 15:52:35] root INFO: beta1 : 0.9 [2022/08/10 15:52:35] root INFO: beta2 : 0.999 [2022/08/10 15:52:35] root INFO: lr : [2022/08/10 15:52:35] root INFO: learning_rate : 0.001 [2022/08/10 15:52:35] root INFO: name : Adam [2022/08/10 15:52:35] root INFO: regularizer : [2022/08/10 15:52:35] root INFO: factor : 0 [2022/08/10 15:52:35] root INFO: name : L2 [2022/08/10 15:52:35] root INFO: PostProcess : [2022/08/10 15:52:35] root INFO: box_thresh : 0.6 [2022/08/10 15:52:35] root INFO: max_candidates : 1000 [2022/08/10 15:52:35] root INFO: name : DBPostProcess [2022/08/10 15:52:35] root INFO: thresh : 0.3 [2022/08/10 15:52:35] root INFO: unclip_ratio : 1.5 [2022/08/10 15:52:35] root INFO: Train : [2022/08/10 15:52:35] root INFO: dataset : [2022/08/10 15:52:35] root INFO: data_dir : ./report_ex/train_det_hebing_all [2022/08/10 15:52:35] root INFO: label_file_list : ['./train_det_hebing_all.txt'] [2022/08/10 15:52:35] root INFO: name : SimpleDataSet [2022/08/10 15:52:35] root INFO: ratio_list : [1.0] [2022/08/10 15:52:35] root INFO: transforms : [2022/08/10 15:52:35] root INFO: DecodeImage : [2022/08/10 15:52:35] root INFO: channel_first : False [2022/08/10 15:52:35] root INFO: img_mode : BGR [2022/08/10 15:52:35] root INFO: DetLabelEncode : None [2022/08/10 15:52:35] root INFO: IaaAugment : [2022/08/10 15:52:35] root INFO: augmenter_args : [2022/08/10 15:52:35] root INFO: args : [2022/08/10 15:52:35] root INFO: p : 0.5 [2022/08/10 15:52:35] root INFO: type : Fliplr [2022/08/10 15:52:35] root INFO: args : [2022/08/10 15:52:35] root INFO: rotate : [-10, 10] [2022/08/10 15:52:35] root INFO: type : Affine [2022/08/10 15:52:35] root INFO: args : [2022/08/10 15:52:35] root INFO: size : [0.5, 3] [2022/08/10 15:52:35] root INFO: type : Resize [2022/08/10 15:52:35] root INFO: EastRandomCropData : [2022/08/10 15:52:35] root INFO: keep_ratio : True [2022/08/10 15:52:35] root INFO: max_tries : 50 [2022/08/10 15:52:35] root INFO: size : [640, 640] [2022/08/10 15:52:35] root INFO: MakeBorderMap : [2022/08/10 15:52:35] root INFO: shrink_ratio : 0.4 [2022/08/10 15:52:35] root INFO: thresh_max : 0.7 [2022/08/10 15:52:35] root INFO: thresh_min : 0.3 [2022/08/10 15:52:35] root INFO: MakeShrinkMap : [2022/08/10 15:52:35] root INFO: min_text_size : 8 [2022/08/10 15:52:35] root INFO: shrink_ratio : 0.4 [2022/08/10 15:52:35] root INFO: NormalizeImage : [2022/08/10 15:52:35] root INFO: mean : [0.485, 0.456, 0.406] [2022/08/10 15:52:35] root INFO: order : hwc [2022/08/10 15:52:35] root INFO: scale : 1./255. [2022/08/10 15:52:35] root INFO: std : [0.229, 0.224, 0.225] [2022/08/10 15:52:35] root INFO: ToCHWImage : None [2022/08/10 15:52:35] root INFO: KeepKeys : [2022/08/10 15:52:35] root INFO: keep_keys : ['image', 'threshold_map', 'threshold_mask', 'shrink_map', 'shrink_mask'] [2022/08/10 15:52:35] root INFO: loader : [2022/08/10 15:52:35] root INFO: batch_size_per_card : 32 [2022/08/10 15:52:35] root INFO: drop_last : False [2022/08/10 15:52:35] root INFO: num_workers : 8 [2022/08/10 15:52:35] root INFO: shuffle : True [2022/08/10 15:52:35] root INFO: use_shared_memory : False [2022/08/10 15:52:35] root INFO: train with paddle 2.0.2 and device CUDAPlace(0) [2022/08/10 15:52:35] root INFO: Initialize indexs of datasets:['./train_det_hebing_all.txt'] [2022/08/10 15:52:35] root INFO: Initialize indexs of datasets:['./test_det_hebing_all.txt']
In [ ]
#2.合并全量数据集+Resnet检测模型训练
%cd /home/aistudio/
!python3 PaddleOCR/tools/train.py -c PaddleOCR/configs/det/det_mv3_db_all_resnet.yml -o \
Global.eval_batch_step="[0,500]" \
Global.load_static_weights=true \
Global.checkpoints='/home/aistudio/outputall/db_resnet/best_accuracy' \
Global.pretrained_model='PaddleOCR/pretrain_models/ResNet50_vd_ssld_pretrained' \
Train.loader.batch_size_per_card=16 \
Train.dataset.data_dir='./report_ex/train_det_hebing_all' \
Train.dataset.label_file_list=['./train_det_hebing_all.txt'] \
Eval.dataset.data_dir='./report_ex/test_det_hebing_all' \
Eval.dataset.label_file_list=['./test_det_hebing_all.txt']
/home/aistudio /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/layers/utils.py:26: DeprecationWarning: `np.int` is a deprecated alias for the builtin `int`. To silence this warning, 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. Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations def convert_to_list(value, n, name, dtype=np.int): [2022/08/11 13:35:54] root INFO: Architecture : [2022/08/11 13:35:54] root INFO: Backbone : [2022/08/11 13:35:54] root INFO: model_name : large [2022/08/11 13:35:54] root INFO: name : ResNet [2022/08/11 13:35:54] root INFO: scale : 0.5 [2022/08/11 13:35:54] root INFO: Head : [2022/08/11 13:35:54] root INFO: k : 50 [2022/08/11 13:35:54] root INFO: name : DBHead [2022/08/11 13:35:54] root INFO: Neck : [2022/08/11 13:35:54] root INFO: name : DBFPN [2022/08/11 13:35:54] root INFO: out_channels : 256 [2022/08/11 13:35:54] root INFO: Transform : None [2022/08/11 13:35:54] root INFO: algorithm : DB [2022/08/11 13:35:54] root INFO: model_type : det [2022/08/11 13:35:54] root INFO: Eval : [2022/08/11 13:35:54] root INFO: dataset : [2022/08/11 13:35:54] root INFO: data_dir : ./report_ex/test_det_hebing_all [2022/08/11 13:35:54] root INFO: label_file_list : ['./test_det_hebing_all.txt'] [2022/08/11 13:35:54] root INFO: name : SimpleDataSet [2022/08/11 13:35:54] root INFO: transforms : [2022/08/11 13:35:54] root INFO: DecodeImage : [2022/08/11 13:35:54] root INFO: channel_first : False [2022/08/11 13:35:54] root INFO: img_mode : BGR [2022/08/11 13:35:54] root INFO: DetLabelEncode : None [2022/08/11 13:35:54] root INFO: DetResizeForTest : [2022/08/11 13:35:54] root INFO: image_shape : [736, 1280] [2022/08/11 13:35:54] root INFO: NormalizeImage : [2022/08/11 13:35:54] root INFO: mean : [0.485, 0.456, 0.406] [2022/08/11 13:35:54] root INFO: order : hwc [2022/08/11 13:35:54] root INFO: scale : 1./255. [2022/08/11 13:35:54] root INFO: std : [0.229, 0.224, 0.225] [2022/08/11 13:35:54] root INFO: ToCHWImage : None [2022/08/11 13:35:54] root INFO: KeepKeys : [2022/08/11 13:35:54] root INFO: keep_keys : ['image', 'shape', 'polys', 'ignore_tags'] [2022/08/11 13:35:54] root INFO: loader : [2022/08/11 13:35:54] root INFO: batch_size_per_card : 1 [2022/08/11 13:35:54] root INFO: drop_last : False [2022/08/11 13:35:54] root INFO: num_workers : 8 [2022/08/11 13:35:54] root INFO: shuffle : False [2022/08/11 13:35:54] root INFO: use_shared_memory : False [2022/08/11 13:35:54] root INFO: Global : [2022/08/11 13:35:54] root INFO: cal_metric_during_train : False [2022/08/11 13:35:54] root INFO: checkpoints : /home/aistudio/outputall/db_resnet//best_accuracy [2022/08/11 13:35:54] root INFO: debug : False [2022/08/11 13:35:54] root INFO: distributed : False [2022/08/11 13:35:54] root INFO: epoch_num : 1200 [2022/08/11 13:35:54] root INFO: eval_batch_step : [0, 500] [2022/08/11 13:35:54] root INFO: infer_img : ./20220623110401-0.png [2022/08/11 13:35:54] root INFO: load_static_weights : True [2022/08/11 13:35:54] root INFO: log_smooth_window : 20 [2022/08/11 13:35:54] root INFO: pretrained_model : PaddleOCR/pretrain_models/ResNet50_vd_ssld_pretrained [2022/08/11 13:35:54] root INFO: print_batch_step : 10 [2022/08/11 13:35:54] root INFO: save_epoch_step : 1200 [2022/08/11 13:35:54] root INFO: save_inference_dir : None [2022/08/11 13:35:54] root INFO: save_model_dir : /home/aistudio/outputall/db_resnet/ [2022/08/11 13:35:54] root INFO: save_res_path : ./outputall_resnet/det_db/predicts_db.txt [2022/08/11 13:35:54] root INFO: use_gpu : True [2022/08/11 13:35:54] root INFO: use_visualdl : False [2022/08/11 13:35:54] root INFO: Loss : [2022/08/11 13:35:54] root INFO: alpha : 5 [2022/08/11 13:35:54] root INFO: balance_loss : True [2022/08/11 13:35:54] root INFO: beta : 10 [2022/08/11 13:35:54] root INFO: main_loss_type : DiceLoss [2022/08/11 13:35:54] root INFO: name : DBLoss [2022/08/11 13:35:54] root INFO: ohem_ratio : 3 [2022/08/11 13:35:54] root INFO: Metric : [2022/08/11 13:35:54] root INFO: main_indicator : hmean [2022/08/11 13:35:54] root INFO: name : DetMetric [2022/08/11 13:35:54] root INFO: Optimizer : [2022/08/11 13:35:54] root INFO: beta1 : 0.9 [2022/08/11 13:35:54] root INFO: beta2 : 0.999 [2022/08/11 13:35:54] root INFO: lr : [2022/08/11 13:35:54] root INFO: learning_rate : 0.001 [2022/08/11 13:35:54] root INFO: name : Adam [2022/08/11 13:35:54] root INFO: regularizer : [2022/08/11 13:35:54] root INFO: factor : 0 [2022/08/11 13:35:54] root INFO: name : L2 [2022/08/11 13:35:54] root INFO: PostProcess : [2022/08/11 13:35:54] root INFO: box_thresh : 0.6 [2022/08/11 13:35:54] root INFO: max_candidates : 1000 [2022/08/11 13:35:54] root INFO: name : DBPostProcess [2022/08/11 13:35:54] root INFO: thresh : 0.3 [2022/08/11 13:35:54] root INFO: unclip_ratio : 1.5 [2022/08/11 13:35:54] root INFO: Train : [2022/08/11 13:35:54] root INFO: dataset : [2022/08/11 13:35:54] root INFO: data_dir : ./report_ex/train_det_hebing_all [2022/08/11 13:35:54] root INFO: label_file_list : ['./train_det_hebing_all.txt'] [2022/08/11 13:35:54] root INFO: name : SimpleDataSet [2022/08/11 13:35:54] root INFO: ratio_list : [1.0] [2022/08/11 13:35:54] root INFO: transforms : [2022/08/11 13:35:54] root INFO: DecodeImage : [2022/08/11 13:35:54] root INFO: channel_first : False [2022/08/11 13:35:54] root INFO: img_mode : BGR [2022/08/11 13:35:54] root INFO: DetLabelEncode : None [2022/08/11 13:35:54] root INFO: IaaAugment : [2022/08/11 13:35:54] root INFO: augmenter_args : [2022/08/11 13:35:54] root INFO: args : [2022/08/11 13:35:54] root INFO: p : 0.5 [2022/08/11 13:35:54] root INFO: type : Fliplr [2022/08/11 13:35:54] root INFO: args : [2022/08/11 13:35:54] root INFO: rotate : [-10, 10] [2022/08/11 13:35:54] root INFO: type : Affine [2022/08/11 13:35:54] root INFO: args : [2022/08/11 13:35:54] root INFO: size : [0.5, 3] [2022/08/11 13:35:54] root INFO: type : Resize [2022/08/11 13:35:54] root INFO: EastRandomCropData : [2022/08/11 13:35:54] root INFO: keep_ratio : True [2022/08/11 13:35:54] root INFO: max_tries : 50 [2022/08/11 13:35:54] root INFO: size : [640, 640] [2022/08/11 13:35:54] root INFO: MakeBorderMap : [2022/08/11 13:35:54] root INFO: shrink_ratio : 0.4 [2022/08/11 13:35:54] root INFO: thresh_max : 0.7 [2022/08/11 13:35:54] root INFO: thresh_min : 0.3 [2022/08/11 13:35:54] root INFO: MakeShrinkMap : [2022/08/11 13:35:54] root INFO: min_text_size : 8 [2022/08/11 13:35:54] root INFO: shrink_ratio : 0.4 [2022/08/11 13:35:54] root INFO: NormalizeImage : [2022/08/11 13:35:54] root INFO: mean : [0.485, 0.456, 0.406] [2022/08/11 13:35:54] root INFO: order : hwc [2022/08/11 13:35:54] root INFO: scale : 1./255. [2022/08/11 13:35:54] root INFO: std : [0.229, 0.224, 0.225] [2022/08/11 13:35:54] root INFO: ToCHWImage : None [2022/08/11 13:35:54] root INFO: KeepKeys : [2022/08/11 13:35:54] root INFO: keep_keys : ['image', 'threshold_map', 'threshold_mask', 'shrink_map', 'shrink_mask'] [2022/08/11 13:35:54] root INFO: loader : [2022/08/11 13:35:54] root INFO: batch_size_per_card : 16 [2022/08/11 13:35:54] root INFO: drop_last : False [2022/08/11 13:35:54] root INFO: num_workers : 8 [2022/08/11 13:35:54] root INFO: shuffle : True [2022/08/11 13:35:54] root INFO: use_shared_memory : False [2022/08/11 13:35:54] root INFO: train with paddle 2.0.2 and device CUDAPlace(0) [2022/08/11 13:35:54] root INFO: Initialize indexs of datasets:['./train_det_hebing_all.txt'] [2022/08/11 13:35:54] root INFO: Initialize indexs of datasets:['./test_det_hebing_all.txt'] W0811 13:35:54.603739 1610 device_context.cc:362] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 11.2, Runtime API Version: 10.1 W0811 13:35:54.608341 1610 device_context.cc:372] device: 0, cuDNN Version: 7.6.
#3.合并后部分数据训练模版,下面显示输出是用这个训练的结果
%cd /home/aistudio/
!python3 PaddleOCR/tools/train.py -c PaddleOCR/configs/det/det_mv3_db.yml -o \
Global.eval_batch_step="[0,50]" \
Global.load_static_weights=true \
Global.pretrained_model='PaddleOCR/pretrain_models/MobileNetV3_large_x0_5_pretrained' \
Train.loader.batch_size_per_card=16 \
Train.dataset.data_dir='./report_ex/train_det_new1_hebing' \
Train.dataset.label_file_list=['./train_det_new1_hebing.txt'] \
Eval.dataset.data_dir='./report_ex/test_det_new1_hebing' \
Eval.dataset.label_file_list=['./test_det_new1_hebing.txt']
#3.合并后全集训练模版,可能要调batch_size_per_card大小 ,执行打开注释,注释其他,
# %cd /home/aistudio/
# !python3 PaddleOCR/tools/train.py -c PaddleOCR/configs/det/det_mv3_db.yml -o \
# Global.eval_batch_step="[0,10]" \
# Global.load_static_weights=true \
# Global.pretrained_model='PaddleOCR/pretrain_models/MobileNetV3_large_x0_5_pretrained' \
# Train.loader.batch_size_per_card=32 \
# Train.dataset.data_dir='./report_ex/train_det_hebing_all' \
# Train.dataset.label_file_list=['./train_det_hebing_all.txt'] \
# Eval.dataset.data_dir='./report_ex/test_det_hebing_all' \
# Eval.dataset.label_file_list=['./test_det_hebing_all.txt']
/home/aistudio /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/layers/utils.py:26: DeprecationWarning: `np.int` is a deprecated alias for the builtin `int`. To silence this warning, 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. Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations def convert_to_list(value, n, name, dtype=np.int): [2022/08/09 09:38:47] root INFO: Architecture : [2022/08/09 09:38:47] root INFO: Backbone : [2022/08/09 09:38:47] root INFO: model_name : large [2022/08/09 09:38:47] root INFO: name : MobileNetV3 [2022/08/09 09:38:47] root INFO: scale : 0.5 [2022/08/09 09:38:47] root INFO: Head : [2022/08/09 09:38:47] root INFO: k : 50 [2022/08/09 09:38:47] root INFO: name : DBHead [2022/08/09 09:38:47] root INFO: Neck : [2022/08/09 09:38:47] root INFO: name : DBFPN [2022/08/09 09:38:47] root INFO: out_channels : 256 [2022/08/09 09:38:47] root INFO: Transform : None [2022/08/09 09:38:47] root INFO: algorithm : DB [2022/08/09 09:38:47] root INFO: model_type : det [2022/08/09 09:38:47] root INFO: Eval : [2022/08/09 09:38:47] root INFO: dataset : [2022/08/09 09:38:47] root INFO: data_dir : ./report_ex/test_det_new1_hebing [2022/08/09 09:38:47] root INFO: label_file_list : ['./test_det_new1_hebing.txt'] [2022/08/09 09:38:47] root INFO: name : SimpleDataSet [2022/08/09 09:38:47] root INFO: transforms : [2022/08/09 09:38:47] root INFO: DecodeImage : [2022/08/09 09:38:47] root INFO: channel_first : False [2022/08/09 09:38:47] root INFO: img_mode : BGR [2022/08/09 09:38:47] root INFO: DetLabelEncode : None [2022/08/09 09:38:47] root INFO: DetResizeForTest : [2022/08/09 09:38:47] root INFO: image_shape : [736, 1280] [2022/08/09 09:38:47] root INFO: NormalizeImage : [2022/08/09 09:38:47] root INFO: mean : [0.485, 0.456, 0.406] [2022/08/09 09:38:47] root INFO: order : hwc [2022/08/09 09:38:47] root INFO: scale : 1./255. [2022/08/09 09:38:47] root INFO: std : [0.229, 0.224, 0.225] [2022/08/09 09:38:47] root INFO: ToCHWImage : None [2022/08/09 09:38:47] root INFO: KeepKeys : [2022/08/09 09:38:47] root INFO: keep_keys : ['image', 'shape', 'polys', 'ignore_tags'] [2022/08/09 09:38:47] root INFO: loader : [2022/08/09 09:38:47] root INFO: batch_size_per_card : 1 [2022/08/09 09:38:47] root INFO: drop_last : False [2022/08/09 09:38:47] root INFO: num_workers : 8 [2022/08/09 09:38:47] root INFO: shuffle : False [2022/08/09 09:38:47] root INFO: use_shared_memory : False [2022/08/09 09:38:47] root INFO: Global : [2022/08/09 09:38:47] root INFO: cal_metric_during_train : False [2022/08/09 09:38:47] root INFO: checkpoints : None [2022/08/09 09:38:47] root INFO: debug : False [2022/08/09 09:38:47] root INFO: distributed : False [2022/08/09 09:38:47] root INFO: epoch_num : 1200 [2022/08/09 09:38:47] root INFO: eval_batch_step : [0, 50] [2022/08/09 09:38:47] root INFO: infer_img : ./20220623110401-0.png [2022/08/09 09:38:47] root INFO: load_static_weights : True [2022/08/09 09:38:47] root INFO: log_smooth_window : 20 [2022/08/09 09:38:47] root INFO: pretrained_model : PaddleOCR/pretrain_models/MobileNetV3_large_x0_5_pretrained [2022/08/09 09:38:47] root INFO: print_batch_step : 10 [2022/08/09 09:38:47] root INFO: save_epoch_step : 1200 [2022/08/09 09:38:47] root INFO: save_inference_dir : None [2022/08/09 09:38:47] root INFO: save_model_dir : ./output1/db_mv3/ [2022/08/09 09:38:47] root INFO: save_res_path : ./output1/det_db/predicts_db.txt [2022/08/09 09:38:47] root INFO: use_gpu : True [2022/08/09 09:38:47] root INFO: use_visualdl : False [2022/08/09 09:38:47] root INFO: Loss : [2022/08/09 09:38:47] root INFO: alpha : 5 [2022/08/09 09:38:47] root INFO: balance_loss : True [2022/08/09 09:38:47] root INFO: beta : 10 [2022/08/09 09:38:47] root INFO: main_loss_type : DiceLoss [2022/08/09 09:38:47] root INFO: name : DBLoss [2022/08/09 09:38:47] root INFO: ohem_ratio : 3 [2022/08/09 09:38:47] root INFO: Metric : [2022/08/09 09:38:47] root INFO: main_indicator : hmean [2022/08/09 09:38:47] root INFO: name : DetMetric [2022/08/09 09:38:47] root INFO: Optimizer : [2022/08/09 09:38:47] root INFO: beta1 : 0.9 [2022/08/09 09:38:47] root INFO: beta2 : 0.999 [2022/08/09 09:38:47] root INFO: lr : [2022/08/09 09:38:47] root INFO: learning_rate : 0.001 [2022/08/09 09:38:47] root INFO: name : Adam [2022/08/09 09:38:47] root INFO: regularizer : [2022/08/09 09:38:47] root INFO: factor : 0 [2022/08/09 09:38:47] root INFO: name : L2 [2022/08/09 09:38:47] root INFO: PostProcess : [2022/08/09 09:38:47] root INFO: box_thresh : 0.6 [2022/08/09 09:38:47] root INFO: max_candidates : 1000 [2022/08/09 09:38:47] root INFO: name : DBPostProcess [2022/08/09 09:38:47] root INFO: thresh : 0.3 [2022/08/09 09:38:47] root INFO: unclip_ratio : 1.5 [2022/08/09 09:38:47] root INFO: Train : [2022/08/09 09:38:47] root INFO: dataset : [2022/08/09 09:38:47] root INFO: data_dir : ./report_ex/train_det_new1_hebing [2022/08/09 09:38:47] root INFO: label_file_list : ['./train_det_new1_hebing.txt'] [2022/08/09 09:38:47] root INFO: name : SimpleDataSet [2022/08/09 09:38:47] root INFO: ratio_list : [1.0] [2022/08/09 09:38:47] root INFO: transforms : [2022/08/09 09:38:47] root INFO: DecodeImage : [2022/08/09 09:38:47] root INFO: channel_first : False [2022/08/09 09:38:47] root INFO: img_mode : BGR [2022/08/09 09:38:47] root INFO: DetLabelEncode : None [2022/08/09 09:38:47] root INFO: IaaAugment : [2022/08/09 09:38:47] root INFO: augmenter_args : [2022/08/09 09:38:47] root INFO: args : [2022/08/09 09:38:47] root INFO: p : 0.5 [2022/08/09 09:38:47] root INFO: type : Fliplr [2022/08/09 09:38:47] root INFO: args : [2022/08/09 09:38:47] root INFO: rotate : [-10, 10] [2022/08/09 09:38:47] root INFO: type : Affine [2022/08/09 09:38:47] root INFO: args : [2022/08/09 09:38:47] root INFO: size : [0.5, 3] [2022/08/09 09:38:47] root INFO: type : Resize [2022/08/09 09:38:47] root INFO: EastRandomCropData : [2022/08/09 09:38:47] root INFO: keep_ratio : True [2022/08/09 09:38:47] root INFO: max_tries : 50 [2022/08/09 09:38:47] root INFO: size : [640, 640] [2022/08/09 09:38:47] root INFO: MakeBorderMap : [2022/08/09 09:38:47] root INFO: shrink_ratio : 0.4 [2022/08/09 09:38:47] root INFO: thresh_max : 0.7 [2022/08/09 09:38:47] root INFO: thresh_min : 0.3 [2022/08/09 09:38:47] root INFO: MakeShrinkMap : [2022/08/09 09:38:47] root INFO: min_text_size : 8 [2022/08/09 09:38:47] root INFO: shrink_ratio : 0.4 [2022/08/09 09:38:47] root INFO: NormalizeImage : [2022/08/09 09:38:47] root INFO: mean : [0.485, 0.456, 0.406] [2022/08/09 09:38:47] root INFO: order : hwc [2022/08/09 09:38:47] root INFO: scale : 1./255. [2022/08/09 09:38:47] root INFO: std : [0.229, 0.224, 0.225] [2022/08/09 09:38:47] root INFO: ToCHWImage : None [2022/08/09 09:38:47] root INFO: KeepKeys : [2022/08/09 09:38:47] root INFO: keep_keys : ['image', 'threshold_map', 'threshold_mask', 'shrink_map', 'shrink_mask'] [2022/08/09 09:38:47] root INFO: loader : [2022/08/09 09:38:47] root INFO: batch_size_per_card : 16 [2022/08/09 09:38:47] root INFO: drop_last : False [2022/08/09 09:38:47] root INFO: num_workers : 8 [2022/08/09 09:38:47] root INFO: shuffle : True [2022/08/09 09:38:47] root INFO: use_shared_memory : False [2022/08/09 09:38:47] root INFO: train with paddle 2.0.2 and device CUDAPlace(0) [2022/08/09 09:38:47] root INFO: Initialize indexs of datasets:['./train_det_new1_hebing.txt'] [2022/08/09 09:38:47] root INFO: Initialize indexs of datasets:['./test_det_new1_hebing.txt'] W0809 09:38:47.257441 10327 device_context.cc:362] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 11.2, Runtime API Version: 10.1 W0809 09:38:47.261169 10327 device_context.cc:372] device: 0, cuDNN Version: 7.6. [2022/08/09 09:38:50] root INFO: load pretrained model from ['PaddleOCR/pretrain_models/MobileNetV3_large_x0_5_pretrained'] [2022/08/09 09:38:50] root INFO: train dataloader has 9 iters [2022/08/09 09:38:50] root INFO: valid dataloader has 16 iters [2022/08/09 09:38:50] root INFO: During the training process, after the 0th iteration, an evaluation is run every 50 iterations [2022/08/09 09:38:50] root INFO: Initialize indexs of datasets:['./train_det_new1_hebing.txt'] [2022/08/09 09:39:51] root INFO: epoch: [1/1200], iter: 8, lr: 0.001000, loss: 7.751804, loss_shrink_maps: 4.606901, loss_threshold_maps: 2.225027, loss_binary_maps: 0.919876, reader_cost: 5.55701 s, batch_cost: 6.10987 s, samples: 140, ips: 2.29137 [2022/08/09 09:39:52] root INFO: save model in ./output1/db_mv3/latest [2022/08/09 09:39:52] root INFO: Initialize indexs of datasets:['./train_det_new1_hebing.txt'] [2022/08/09 09:40:55] root INFO: epoch: [2/1200], iter: 10, lr: 0.001000, loss: 7.377272, loss_shrink_maps: 4.554792, loss_threshold_maps: 1.911745, loss_binary_maps: 0.910735, reader_cost: 6.11302 s, batch_cost: 6.33029 s, samples: 32, ips: 0.50551 [2022/08/09 09:40:58] root INFO: epoch: [2/1200], iter: 17, lr: 0.001000, loss: 6.610305, loss_shrink_maps: 4.466334, loss_threshold_maps: 1.255741, loss_binary_maps: 0.897122, reader_cost: 0.07724 s, batch_cost: 0.30940 s, samples: 108, ips: 34.90611 [2022/08/09 09:40:59] root INFO: save model in ./output1/db_mv3/latest [2022/08/09 09:40:59] root INFO: Initialize indexs of datasets:['./train_det_new1_hebing.txt'] ^C main proc 11724 exit, kill process group 10327 main proc 11723 exit, kill process group 10327
训练过程中的检测模型保存在'./output/det_db/'中,模型保存的位置通过yml配置文件的Global.save_model_dir参数设置。
使用训练好的模型测试单张图像的检测效果。
In [ ]
# %cd PaddleOCR
#部分数据结果
# !python3 tools/infer_det.py -c configs/det/det_mv3_db.yml -o Global.infer_img="../20220623110401-0.png" Global.pretrained_model="/home/aistudio/output1/db_mv3/best_accuracy"
#全集数据结果,全集只训练一个epoch
!python3 tools/infer_det.py -c configs/det/det_mv3_db_all.yml -o Global.infer_img="../20220623110401-0.png" Global.pretrained_model="/home/aistudio/outputall/db_mv3/best_accuracy"
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/layers/utils.py:26: DeprecationWarning: `np.int` is a deprecated alias for the builtin `int`. To silence this warning, 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. Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations def convert_to_list(value, n, name, dtype=np.int): [2022/08/17 22:49:37] root INFO: Architecture : [2022/08/17 22:49:37] root INFO: Backbone : [2022/08/17 22:49:37] root INFO: model_name : large [2022/08/17 22:49:37] root INFO: name : MobileNetV3 [2022/08/17 22:49:37] root INFO: scale : 0.5 [2022/08/17 22:49:37] root INFO: Head : [2022/08/17 22:49:37] root INFO: k : 50 [2022/08/17 22:49:37] root INFO: name : DBHead [2022/08/17 22:49:37] root INFO: Neck : [2022/08/17 22:49:37] root INFO: name : DBFPN [2022/08/17 22:49:37] root INFO: out_channels : 256 [2022/08/17 22:49:37] root INFO: Transform : None [2022/08/17 22:49:37] root INFO: algorithm : DB [2022/08/17 22:49:37] root INFO: model_type : det [2022/08/17 22:49:37] root INFO: Eval : [2022/08/17 22:49:37] root INFO: dataset : [2022/08/17 22:49:37] root INFO: data_dir : ./train_data/icdar2015/text_localization/ [2022/08/17 22:49:37] root INFO: label_file_list : ['./train_data/icdar2015/text_localization/test_icdar2015_label.txt'] [2022/08/17 22:49:37] root INFO: name : SimpleDataSet [2022/08/17 22:49:37] root INFO: transforms : [2022/08/17 22:49:37] root INFO: DecodeImage : [2022/08/17 22:49:37] root INFO: channel_first : False [2022/08/17 22:49:37] root INFO: img_mode : BGR [2022/08/17 22:49:37] root INFO: DetLabelEncode : None [2022/08/17 22:49:37] root INFO: DetResizeForTest : [2022/08/17 22:49:37] root INFO: image_shape : [736, 1280] [2022/08/17 22:49:37] root INFO: NormalizeImage : [2022/08/17 22:49:37] root INFO: mean : [0.485, 0.456, 0.406] [2022/08/17 22:49:37] root INFO: order : hwc [2022/08/17 22:49:37] root INFO: scale : 1./255. [2022/08/17 22:49:37] root INFO: std : [0.229, 0.224, 0.225] [2022/08/17 22:49:37] root INFO: ToCHWImage : None [2022/08/17 22:49:37] root INFO: KeepKeys : [2022/08/17 22:49:37] root INFO: keep_keys : ['image', 'shape', 'polys', 'ignore_tags'] [2022/08/17 22:49:37] root INFO: loader : [2022/08/17 22:49:37] root INFO: batch_size_per_card : 1 [2022/08/17 22:49:37] root INFO: drop_last : False [2022/08/17 22:49:37] root INFO: num_workers : 8 [2022/08/17 22:49:37] root INFO: shuffle : False [2022/08/17 22:49:37] root INFO: use_shared_memory : False [2022/08/17 22:49:37] root INFO: Global : [2022/08/17 22:49:37] root INFO: cal_metric_during_train : False [2022/08/17 22:49:37] root INFO: checkpoints : None [2022/08/17 22:49:37] root INFO: debug : False [2022/08/17 22:49:37] root INFO: distributed : False [2022/08/17 22:49:37] root INFO: epoch_num : 1200 [2022/08/17 22:49:37] root INFO: eval_batch_step : [0, 2000] [2022/08/17 22:49:37] root INFO: infer_img : ../20220623110401-0.png [2022/08/17 22:49:37] root INFO: log_smooth_window : 20 [2022/08/17 22:49:37] root INFO: pretrained_model : /home/aistudio/outputall/db_mv3/best_accuracy [2022/08/17 22:49:37] root INFO: print_batch_step : 10 [2022/08/17 22:49:37] root INFO: save_epoch_step : 1200 [2022/08/17 22:49:37] root INFO: save_inference_dir : None [2022/08/17 22:49:37] root INFO: save_model_dir : /home/aistudio/outputall/db_mv3/ [2022/08/17 22:49:37] root INFO: save_res_path : ./outputall/det_db/predicts_db.txt [2022/08/17 22:49:37] root INFO: use_gpu : True [2022/08/17 22:49:37] root INFO: use_visualdl : False [2022/08/17 22:49:37] root INFO: Loss : [2022/08/17 22:49:37] root INFO: alpha : 5 [2022/08/17 22:49:37] root INFO: balance_loss : True [2022/08/17 22:49:37] root INFO: beta : 10 [2022/08/17 22:49:37] root INFO: main_loss_type : DiceLoss [2022/08/17 22:49:37] root INFO: name : DBLoss [2022/08/17 22:49:37] root INFO: ohem_ratio : 3 [2022/08/17 22:49:37] root INFO: Metric : [2022/08/17 22:49:37] root INFO: main_indicator : hmean [2022/08/17 22:49:37] root INFO: name : DetMetric [2022/08/17 22:49:37] root INFO: Optimizer : [2022/08/17 22:49:37] root INFO: beta1 : 0.9 [2022/08/17 22:49:37] root INFO: beta2 : 0.999 [2022/08/17 22:49:37] root INFO: lr : [2022/08/17 22:49:37] root INFO: learning_rate : 0.001 [2022/08/17 22:49:37] root INFO: name : Adam [2022/08/17 22:49:37] root INFO: regularizer : [2022/08/17 22:49:37] root INFO: factor : 0 [2022/08/17 22:49:37] root INFO: name : L2 [2022/08/17 22:49:37] root INFO: PostProcess : [2022/08/17 22:49:37] root INFO: box_thresh : 0.6 [2022/08/17 22:49:37] root INFO: max_candidates : 1000 [2022/08/17 22:49:37] root INFO: name : DBPostProcess [2022/08/17 22:49:37] root INFO: thresh : 0.3 [2022/08/17 22:49:37] root INFO: unclip_ratio : 1.5 [2022/08/17 22:49:37] root INFO: Train : [2022/08/17 22:49:37] root INFO: dataset : [2022/08/17 22:49:37] root INFO: data_dir : ./train_data/icdar2015/text_localization/ [2022/08/17 22:49:37] root INFO: label_file_list : ['./train_data/icdar2015/text_localization/train_icdar2015_label.txt'] [2022/08/17 22:49:37] root INFO: name : SimpleDataSet [2022/08/17 22:49:37] root INFO: ratio_list : [1.0] [2022/08/17 22:49:37] root INFO: transforms : [2022/08/17 22:49:37] root INFO: DecodeImage : [2022/08/17 22:49:37] root INFO: channel_first : False [2022/08/17 22:49:37] root INFO: img_mode : BGR [2022/08/17 22:49:37] root INFO: DetLabelEncode : None [2022/08/17 22:49:37] root INFO: IaaAugment : [2022/08/17 22:49:37] root INFO: augmenter_args : [2022/08/17 22:49:37] root INFO: args : [2022/08/17 22:49:37] root INFO: p : 0.5 [2022/08/17 22:49:37] root INFO: type : Fliplr [2022/08/17 22:49:37] root INFO: args : [2022/08/17 22:49:37] root INFO: rotate : [-10, 10] [2022/08/17 22:49:37] root INFO: type : Affine [2022/08/17 22:49:37] root INFO: args : [2022/08/17 22:49:37] root INFO: size : [0.5, 3] [2022/08/17 22:49:37] root INFO: type : Resize [2022/08/17 22:49:37] root INFO: EastRandomCropData : [2022/08/17 22:49:37] root INFO: keep_ratio : True [2022/08/17 22:49:37] root INFO: max_tries : 50 [2022/08/17 22:49:37] root INFO: size : [640, 640] [2022/08/17 22:49:37] root INFO: MakeBorderMap : [2022/08/17 22:49:37] root INFO: shrink_ratio : 0.4 [2022/08/17 22:49:37] root INFO: thresh_max : 0.7 [2022/08/17 22:49:37] root INFO: thresh_min : 0.3 [2022/08/17 22:49:37] root INFO: MakeShrinkMap : [2022/08/17 22:49:37] root INFO: min_text_size : 8 [2022/08/17 22:49:37] root INFO: shrink_ratio : 0.4 [2022/08/17 22:49:37] root INFO: NormalizeImage : [2022/08/17 22:49:37] root INFO: mean : [0.485, 0.456, 0.406] [2022/08/17 22:49:37] root INFO: order : hwc [2022/08/17 22:49:37] root INFO: scale : 1./255. [2022/08/17 22:49:37] root INFO: std : [0.229, 0.224, 0.225] [2022/08/17 22:49:37] root INFO: ToCHWImage : None [2022/08/17 22:49:37] root INFO: KeepKeys : [2022/08/17 22:49:37] root INFO: keep_keys : ['image', 'threshold_map', 'threshold_mask', 'shrink_map', 'shrink_mask'] [2022/08/17 22:49:37] root INFO: loader : [2022/08/17 22:49:37] root INFO: batch_size_per_card : 64 [2022/08/17 22:49:37] root INFO: drop_last : False [2022/08/17 22:49:37] root INFO: num_workers : 8 [2022/08/17 22:49:37] root INFO: shuffle : True [2022/08/17 22:49:37] root INFO: use_shared_memory : False [2022/08/17 22:49:37] root INFO: train with paddle 2.0.2 and device CUDAPlace(0) W0817 22:49:37.830164 5900 device_context.cc:362] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 11.2, Runtime API Version: 10.1 W0817 22:49:37.835045 5900 device_context.cc:372] device: 0, cuDNN Version: 7.6. [2022/08/17 22:49:40] root INFO: load pretrained model from ['/home/aistudio/outputall/db_mv3/best_accuracy'] [2022/08/17 22:49:40] root INFO: infer_img: ../20220623110401-0.png [2022/08/17 22:49:41] root INFO: The detected Image saved in ./outputall/det_db/det_results/20220623110401-0.png [2022/08/17 22:49:41] root INFO: success!
In [ ]
# %cd PaddleOCR/
# !python3 tools/infer_det.py -c configs/det/det_mv3_db.yml -o Global.infer_img="../20220623110401-0.png" Global.checkpoints="./output/db_mv3/best_accuracy"
使用训练好的模型,测试文件夹下所有图像的检测效果,路径按需更改!下同。
In [ ]
#!python3 tools/infer_det.py -c configs/det/det_mv3_db.yml -o Global.infer_img="./doc/imgs_en/" Global.checkpoints="./output/db_mv3/best_accuracy"
首先请将训练图片放入同一个文件夹(trainimages),并用一个txt文件(recgttrain.txt)记录图片路径和标签。
本项目识别使用的数据集: train_reg.txt 、test_reg.txt ,注意: 默认请将图片路径和图片标签用 \t 分割。
" 图像文件名 图像标注信息 "
20220623110401-0.png 姓名:张某某
训练集及测试集文件结构如下:
|- train_reg.txt
|- report_ex/
|- train_reg
|- word_001.png
|- word_002.jpg
| ...
|- test_reg
|- word_001.png
|- word_002.jpg
| ...
### 3.2. 快速启动训练
本节文字识别网络以 CRNN 识别模型为例,网络模型使用PaddleOCR主流两种识别模型backbone,MobileNetV3和ResNet50_vd :
In [ ]
# 下载ResNet50的预训练模型
%cd PaddleOCR/
!wget -P ./pretrain_models/ https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/rec_mv3_none_bilstm_ctc_v2.0_train.tar
! cd pretrain_models/ && tar xf rec_mv3_none_bilstm_ctc_v2.0_train.tar
/home/aistudio/PaddleOCR --2022-08-05 14:11:03-- https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/rec_mv3_none_bilstm_ctc_v2.0_train.tar Resolving paddleocr.bj.bcebos.com (paddleocr.bj.bcebos.com)... 100.67.200.6 Connecting to paddleocr.bj.bcebos.com (paddleocr.bj.bcebos.com)|100.67.200.6|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 51200000 (49M) [application/x-tar] Saving to: ‘./pretrain_models/rec_mv3_none_bilstm_ctc_v2.0_train.tar.1’ rec_mv3_none_bilstm 100%[===================>] 48.83M 119MB/s in 0.4s 2022-08-05 14:11:03 (119 MB/s) - ‘./pretrain_models/rec_mv3_none_bilstm_ctc_v2.0_train.tar.1’ saved [51200000/51200000]
In [12]
#rec.py为按坐标截取图片脚本,将原来一张图片的所有标注截取成多张,生成new_pngs图像文件夹并生成对应rec.txt,用于识别模型
%cd /home/aistudio/
!python ./rec.py
In [ ]
#查看当前文件夹图片数量
%cd ./new_pngs
!ls -l | grep "^-" | wc -l #一共1490577张图片
/home/aistudio/new_pngs 1492727
In [ ]
#切分训练与测试数据集
%cd /home/aistudio/
!python ./rec_split_data.py
/home/aistudio 2150
In [ ]
#拷贝训练集与测试集对应图片到文件夹用于文字识别训练,执行方法同上,需要执行两次,一次 train ,一次test
!python rec_file.py
本次文字识别训练因为服务器内存原因,只跑小部分数据集,模型只做基础演示,后续可调节参数或更换网络模型进行训练。
In [ ]
%cd PaddleOCR/
!python3 ./tools/train.py -c ./configs/rec/rec_icdar15_train.yml -o \
Global.eval_batch_step="[0,100]" \
Global.save_epoch_step=500 \
Global.pretrained_model='./pretrain_models/rec_mv3_none_bilstm_ctc_v2.0_train/best_accuracy' \
Train.dataset.data_dir='../report_ex/train_rec' \
Train.dataset.label_file_list=['../train_rec.txt'] \
Eval.dataset.data_dir='../report_ex/test_rec' \
Eval.dataset.label_file_list=['../test_rec.txt'] \
Optimizer.lr.learning_rate=0.001
[Errno 2] No such file or directory: 'PaddleOCR//' /home/aistudio/PaddleOCR /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/layers/utils.py:26: DeprecationWarning: `np.int` is a deprecated alias for the builtin `int`. To silence this warning, 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. Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations def convert_to_list(value, n, name, dtype=np.int): [2022/08/09 08:47:02] root INFO: Architecture : [2022/08/09 08:47:02] root INFO: Backbone : [2022/08/09 08:47:02] root INFO: model_name : large [2022/08/09 08:47:02] root INFO: name : MobileNetV3 [2022/08/09 08:47:02] root INFO: scale : 0.5 [2022/08/09 08:47:02] root INFO: Head : [2022/08/09 08:47:02] root INFO: fc_decay : 0 [2022/08/09 08:47:02] root INFO: name : CTCHead [2022/08/09 08:47:02] root INFO: Neck : [2022/08/09 08:47:02] root INFO: encoder_type : rnn [2022/08/09 08:47:02] root INFO: hidden_size : 96 [2022/08/09 08:47:02] root INFO: name : SequenceEncoder [2022/08/09 08:47:02] root INFO: Transform : None [2022/08/09 08:47:02] root INFO: algorithm : CRNN [2022/08/09 08:47:02] root INFO: model_type : rec [2022/08/09 08:47:02] root INFO: Eval : [2022/08/09 08:47:02] root INFO: dataset : [2022/08/09 08:47:02] root INFO: data_dir : ../report_ex/test_rec [2022/08/09 08:47:02] root INFO: label_file_list : ['../test_rec.txt'] [2022/08/09 08:47:02] root INFO: name : SimpleDataSet [2022/08/09 08:47:02] root INFO: transforms : [2022/08/09 08:47:02] root INFO: DecodeImage : [2022/08/09 08:47:02] root INFO: channel_first : False [2022/08/09 08:47:02] root INFO: img_mode : BGR [2022/08/09 08:47:02] root INFO: CTCLabelEncode : None [2022/08/09 08:47:02] root INFO: RecResizeImg : [2022/08/09 08:47:02] root INFO: image_shape : [3, 32, 100] [2022/08/09 08:47:02] root INFO: KeepKeys : [2022/08/09 08:47:02] root INFO: keep_keys : ['image', 'label', 'length'] [2022/08/09 08:47:02] root INFO: loader : [2022/08/09 08:47:02] root INFO: batch_size_per_card : 256 [2022/08/09 08:47:02] root INFO: drop_last : False [2022/08/09 08:47:02] root INFO: num_workers : 4 [2022/08/09 08:47:02] root INFO: shuffle : False [2022/08/09 08:47:02] root INFO: use_shared_memory : False [2022/08/09 08:47:02] root INFO: Global : [2022/08/09 08:47:02] root INFO: cal_metric_during_train : True [2022/08/09 08:47:02] root INFO: character_dict_path : ../label_list.txt [2022/08/09 08:47:02] root INFO: character_type : ch [2022/08/09 08:47:02] root INFO: checkpoints : None [2022/08/09 08:47:02] root INFO: debug : False [2022/08/09 08:47:02] root INFO: distributed : False [2022/08/09 08:47:02] root INFO: epoch_num : 100 [2022/08/09 08:47:02] root INFO: eval_batch_step : [0, 100] [2022/08/09 08:47:02] root INFO: infer_img : ./20220623110401-0.png [2022/08/09 08:47:02] root INFO: infer_mode : False [2022/08/09 08:47:02] root INFO: log_smooth_window : 20 [2022/08/09 08:47:02] root INFO: max_text_length : 25 [2022/08/09 08:47:02] root INFO: pretrained_model : ./pretrain_models/rec_mv3_none_bilstm_ctc_v2.0_train/best_accuracy [2022/08/09 08:47:02] root INFO: print_batch_step : 100 [2022/08/09 08:47:02] root INFO: save_epoch_step : 100 [2022/08/09 08:47:02] root INFO: save_inference_dir : None [2022/08/09 08:47:02] root INFO: save_model_dir : ./output/rec/ [2022/08/09 08:47:02] root INFO: save_res_path : ./output/rec/predicts.txt [2022/08/09 08:47:02] root INFO: use_gpu : True [2022/08/09 08:47:02] root INFO: use_space_char : False [2022/08/09 08:47:02] root INFO: use_visualdl : False [2022/08/09 08:47:02] root INFO: Loss : [2022/08/09 08:47:02] root INFO: name : CTCLoss [2022/08/09 08:47:02] root INFO: Metric : [2022/08/09 08:47:02] root INFO: main_indicator : acc [2022/08/09 08:47:02] root INFO: name : RecMetric [2022/08/09 08:47:02] root INFO: Optimizer : [2022/08/09 08:47:02] root INFO: beta1 : 0.9 [2022/08/09 08:47:02] root INFO: beta2 : 0.999 [2022/08/09 08:47:02] root INFO: lr : [2022/08/09 08:47:02] root INFO: learning_rate : 0.001 [2022/08/09 08:47:02] root INFO: name : Adam [2022/08/09 08:47:02] root INFO: regularizer : [2022/08/09 08:47:02] root INFO: factor : 0 [2022/08/09 08:47:02] root INFO: name : L2 [2022/08/09 08:47:02] root INFO: PostProcess : [2022/08/09 08:47:02] root INFO: name : CTCLabelDecode [2022/08/09 08:47:02] root INFO: Train : [2022/08/09 08:47:02] root INFO: dataset : [2022/08/09 08:47:02] root INFO: data_dir : ../report_ex/train_rec [2022/08/09 08:47:02] root INFO: label_file_list : ['../train_rec.txt'] [2022/08/09 08:47:02] root INFO: name : SimpleDataSet [2022/08/09 08:47:02] root INFO: transforms : [2022/08/09 08:47:02] root INFO: DecodeImage : [2022/08/09 08:47:02] root INFO: channel_first : False [2022/08/09 08:47:02] root INFO: img_mode : BGR [2022/08/09 08:47:02] root INFO: CTCLabelEncode : None [2022/08/09 08:47:02] root INFO: RecResizeImg : [2022/08/09 08:47:02] root INFO: image_shape : [3, 32, 100] [2022/08/09 08:47:02] root INFO: KeepKeys : [2022/08/09 08:47:02] root INFO: keep_keys : ['image', 'label', 'length'] [2022/08/09 08:47:02] root INFO: loader : [2022/08/09 08:47:02] root INFO: batch_size_per_card : 256 [2022/08/09 08:47:02] root INFO: drop_last : True [2022/08/09 08:47:02] root INFO: num_workers : 8 [2022/08/09 08:47:02] root INFO: shuffle : True [2022/08/09 08:47:02] root INFO: use_shared_memory : False [2022/08/09 08:47:02] root INFO: train with paddle 2.0.2 and device CUDAPlace(0) [2022/08/09 08:47:02] root INFO: Initialize indexs of datasets:['../train_rec.txt'] [2022/08/09 08:47:02] root INFO: Initialize indexs of datasets:['../test_rec.txt'] W0809 08:47:02.545296 3246 device_context.cc:362] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 11.2, Runtime API Version: 10.1 W0809 08:47:02.548940 3246 device_context.cc:372] device: 0, cuDNN Version: 7.6. 2022-08-09 08:47:05,035 - INFO - If regularizer of a Parameter has been set by 'paddle.ParamAttr' or 'static.WeightNormParamAttr' already. The weight_decay[L2Decay, regularization_coeff=0.000000] in Optimizer will not take effect, and it will only be applied to other Parameters! [2022/08/09 08:47:05] root INFO: load pretrained model from ['./pretrain_models/rec_mv3_none_bilstm_ctc_v2.0_train/best_accuracy'] [2022/08/09 08:47:05] root INFO: train dataloader has 7 iters [2022/08/09 08:47:05] root INFO: valid dataloader has 1 iters [2022/08/09 08:47:05] root INFO: During the training process, after the 0th iteration, an evaluation is run every 100 iterations eval model:: 100%|████████████████████████████████| 1/1 [00:00<00:00, 1.64it/s] [2022/08/09 08:50:29] root INFO: cur metric, acc: 0.5062761506276151, norm_edit_dis: 0.7929171366686749, fps: 3181.1431744832903 [2022/08/09 08:50:30] root INFO: save best model is to ./output/rec/best_accuracy [2022/08/09 08:50:30] root INFO: best metric, acc: 0.5062761506276151, norm_edit_dis: 0.7929171366686749, fps: 3181.1431744832903, best_epoch: 86 [2022/08/09 08:50:30] root INFO: epoch: [86/100], iter: 601, lr: 0.001000, loss: 2.796403, acc: 0.519531, norm_edit_dis: 0.831250, reader_cost: 0.00002 s, batch_cost: 0.00133 s, samples: 256, ips: 1925.17934 [2022/08/09 08:50:30] root INFO: save model in ./output/rec/latest [2022/08/09 08:50:30] root INFO: Initialize indexs of datasets:['../train_rec.txt'] [2022/08/09 08:50:32] root INFO: epoch: [87/100], iter: 608, lr: 0.001000, loss: 2.669565, acc: 0.542969, norm_edit_dis: 0.835502, reader_cost: 0.00819 s, batch_cost: 0.01664 s, samples: 1792, ips: 1076.79762 [2022/08/09 08:50:33] root INFO: save model in ./output/rec/latest [2022/08/09 08:50:33] root INFO: Initialize indexs of datasets:['../train_rec.txt'] [2022/08/09 08:50:35] root INFO: epoch: [88/100], iter: 615, lr: 0.001000, loss: 2.684035, acc: 0.552734, norm_edit_dis: 0.843117, reader_cost: 0.00747 s, batch_cost: 0.01662 s, samples: 1792, ips: 1078.17574 [2022/08/09 08:50:35] root INFO: save model in ./output/rec/latest [2022/08/09 08:50:35] root INFO: Initialize indexs of datasets:['../train_rec.txt'] [2022/08/09 08:50:37] root INFO: epoch: [89/100], iter: 622, lr: 0.001000, loss: 2.511953, acc: 0.554688, norm_edit_dis: 0.844917, reader_cost: 0.00842 s, batch_cost: 0.01714 s, samples: 1792, ips: 1045.68432 [2022/08/09 08:50:38] root INFO: save model in ./output/rec/latest [2022/08/09 08:50:38] root INFO: Initialize indexs of datasets:['../train_rec.txt'] [2022/08/09 08:50:40] root INFO: epoch: [90/100], iter: 629, lr: 0.001000, loss: 2.481447, acc: 0.562500, norm_edit_dis: 0.847279, reader_cost: 0.00735 s, batch_cost: 0.01727 s, samples: 1792, ips: 1037.49143 [2022/08/09 08:50:40] root INFO: save model in ./output/rec/latest [2022/08/09 08:50:40] root INFO: Initialize indexs of datasets:['../train_rec.txt'] [2022/08/09 08:50:42] root INFO: epoch: [91/100], iter: 636, lr: 0.001000, loss: 2.463750, acc: 0.580078, norm_edit_dis: 0.857158, reader_cost: 0.00820 s, batch_cost: 0.01770 s, samples: 1792, ips: 1012.58188 [2022/08/09 08:50:43] root INFO: save model in ./output/rec/latest [2022/08/09 08:50:43] root INFO: Initialize indexs of datasets:['../train_rec.txt'] [2022/08/09 08:50:45] root INFO: epoch: [92/100], iter: 643, lr: 0.001000, loss: 2.466842, acc: 0.595703, norm_edit_dis: 0.862211, reader_cost: 0.00826 s, batch_cost: 0.01762 s, samples: 1792, ips: 1017.25276 [2022/08/09 08:50:45] root INFO: save model in ./output/rec/latest [2022/08/09 08:50:45] root INFO: Initialize indexs of datasets:['../train_rec.txt'] [2022/08/09 08:50:47] root INFO: epoch: [93/100], iter: 650, lr: 0.001000, loss: 2.466842, acc: 0.611328, norm_edit_dis: 0.868967, reader_cost: 0.00813 s, batch_cost: 0.01704 s, samples: 1792, ips: 1051.46489 [2022/08/09 08:50:48] root INFO: save model in ./output/rec/latest [2022/08/09 08:50:48] root INFO: Initialize indexs of datasets:['../train_rec.txt'] [2022/08/09 08:50:50] root INFO: epoch: [94/100], iter: 657, lr: 0.001000, loss: 2.242416, acc: 0.632812, norm_edit_dis: 0.876017, reader_cost: 0.00886 s, batch_cost: 0.01761 s, samples: 1792, ips: 1017.45601 [2022/08/09 08:50:51] root INFO: save model in ./output/rec/latest [2022/08/09 08:50:51] root INFO: Initialize indexs of datasets:['../train_rec.txt'] [2022/08/09 08:50:52] root INFO: epoch: [95/100], iter: 664, lr: 0.001000, loss: 2.196207, acc: 0.640625, norm_edit_dis: 0.881983, reader_cost: 0.00792 s, batch_cost: 0.01659 s, samples: 1792, ips: 1080.27781 [2022/08/09 08:50:53] root INFO: save model in ./output/rec/latest [2022/08/09 08:50:53] root INFO: Initialize indexs of datasets:['../train_rec.txt'] [2022/08/09 08:50:55] root INFO: epoch: [96/100], iter: 671, lr: 0.001000, loss: 2.113156, acc: 0.648438, norm_edit_dis: 0.882381, reader_cost: 0.00960 s, batch_cost: 0.01858 s, samples: 1792, ips: 964.26967 [2022/08/09 08:50:56] root INFO: save model in ./output/rec/latest [2022/08/09 08:50:56] root INFO: Initialize indexs of datasets:['../train_rec.txt'] [2022/08/09 08:50:58] root INFO: epoch: [97/100], iter: 678, lr: 0.001000, loss: 2.080866, acc: 0.656250, norm_edit_dis: 0.883170, reader_cost: 0.00756 s, batch_cost: 0.01682 s, samples: 1792, ips: 1065.37528 [2022/08/09 08:50:58] root INFO: save model in ./output/rec/latest [2022/08/09 08:50:58] root INFO: Initialize indexs of datasets:['../train_rec.txt'] [2022/08/09 08:51:00] root INFO: epoch: [98/100], iter: 685, lr: 0.001000, loss: 2.028392, acc: 0.660156, norm_edit_dis: 0.885557, reader_cost: 0.00843 s, batch_cost: 0.01686 s, samples: 1792, ips: 1062.57177 [2022/08/09 08:51:01] root INFO: save model in ./output/rec/latest [2022/08/09 08:51:01] root INFO: Initialize indexs of datasets:['../train_rec.txt'] [2022/08/09 08:51:03] root INFO: epoch: [99/100], iter: 692, lr: 0.001000, loss: 1.941369, acc: 0.671875, norm_edit_dis: 0.890019, reader_cost: 0.00725 s, batch_cost: 0.01653 s, samples: 1792, ips: 1084.06991 [2022/08/09 08:51:03] root INFO: save model in ./output/rec/latest [2022/08/09 08:51:03] root INFO: Initialize indexs of datasets:['../train_rec.txt'] [2022/08/09 08:51:05] root INFO: epoch: [100/100], iter: 699, lr: 0.001000, loss: 1.861010, acc: 0.691406, norm_edit_dis: 0.898171, reader_cost: 0.00835 s, batch_cost: 0.01703 s, samples: 1792, ips: 1052.16714 [2022/08/09 08:51:06] root INFO: save model in ./output/rec/latest [2022/08/09 08:51:06] root INFO: save model in ./output/rec/iter_epoch_100 [2022/08/09 08:51:06] root INFO: best metric, acc: 0.5062761506276151, norm_edit_dis: 0.7929171366686749, fps: 3181.1431744832903, best_epoch: 86
测试单张图像的识别结果
# !python3 tools/infer_rec.py -c configs/rec/rec_icdar15_train.yml -o Global.checkpoints=./pretrain_models/rec_mv3_none_bilstm_ctc_v2.0_train/best_accuracy Global.infer_img=../20220623110401-0.png
!python3 tools/infer_rec.py -c configs/rec/rec_icdar15_train.yml -o Global.checkpoints=./output/rec/best_accuracy Global.infer_img=../report_ex/test_rec/20220623110401-1001_0119.png
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/layers/utils.py:26: DeprecationWarning: `np.int` is a deprecated alias for the builtin `int`. To silence this warning, 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. Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations def convert_to_list(value, n, name, dtype=np.int): [2022/08/17 23:45:05] root INFO: Architecture : [2022/08/17 23:45:05] root INFO: Backbone : [2022/08/17 23:45:05] root INFO: model_name : large [2022/08/17 23:45:05] root INFO: name : MobileNetV3 [2022/08/17 23:45:05] root INFO: scale : 0.5 [2022/08/17 23:45:05] root INFO: Head : [2022/08/17 23:45:05] root INFO: fc_decay : 0 [2022/08/17 23:45:05] root INFO: name : CTCHead [2022/08/17 23:45:05] root INFO: Neck : [2022/08/17 23:45:05] root INFO: encoder_type : rnn [2022/08/17 23:45:05] root INFO: hidden_size : 96 [2022/08/17 23:45:05] root INFO: name : SequenceEncoder [2022/08/17 23:45:05] root INFO: Transform : None [2022/08/17 23:45:05] root INFO: algorithm : CRNN [2022/08/17 23:45:05] root INFO: model_type : rec [2022/08/17 23:45:05] root INFO: Eval : [2022/08/17 23:45:05] root INFO: dataset : [2022/08/17 23:45:05] root INFO: data_dir : ./train_data/ [2022/08/17 23:45:05] root INFO: label_file_list : ['./train_data/val_list.txt'] [2022/08/17 23:45:05] root INFO: name : SimpleDataSet [2022/08/17 23:45:05] root INFO: transforms : [2022/08/17 23:45:05] root INFO: DecodeImage : [2022/08/17 23:45:05] root INFO: channel_first : False [2022/08/17 23:45:05] root INFO: img_mode : BGR [2022/08/17 23:45:05] root INFO: CTCLabelEncode : None [2022/08/17 23:45:05] root INFO: RecResizeImg : [2022/08/17 23:45:05] root INFO: image_shape : [3, 32, 100] [2022/08/17 23:45:05] root INFO: KeepKeys : [2022/08/17 23:45:05] root INFO: keep_keys : ['image', 'label', 'length'] [2022/08/17 23:45:05] root INFO: loader : [2022/08/17 23:45:05] root INFO: batch_size_per_card : 256 [2022/08/17 23:45:05] root INFO: drop_last : False [2022/08/17 23:45:05] root INFO: num_workers : 4 [2022/08/17 23:45:05] root INFO: shuffle : False [2022/08/17 23:45:05] root INFO: use_shared_memory : False [2022/08/17 23:45:05] root INFO: Global : [2022/08/17 23:45:05] root INFO: cal_metric_during_train : True [2022/08/17 23:45:05] root INFO: character_dict_path : ../label_list.txt [2022/08/17 23:45:05] root INFO: character_type : ch [2022/08/17 23:45:05] root INFO: checkpoints : ./output/rec/best_accuracy [2022/08/17 23:45:05] root INFO: debug : False [2022/08/17 23:45:05] root INFO: distributed : False [2022/08/17 23:45:05] root INFO: epoch_num : 100 [2022/08/17 23:45:05] root INFO: eval_batch_step : [0, 2000] [2022/08/17 23:45:05] root INFO: infer_img : ../report_ex/test_rec/20220623110401-1001_0119.png [2022/08/17 23:45:05] root INFO: infer_mode : False [2022/08/17 23:45:05] root INFO: log_smooth_window : 20 [2022/08/17 23:45:05] root INFO: max_text_length : 25 [2022/08/17 23:45:05] root INFO: pretrained_model : None [2022/08/17 23:45:05] root INFO: print_batch_step : 100 [2022/08/17 23:45:05] root INFO: save_epoch_step : 3 [2022/08/17 23:45:05] root INFO: save_inference_dir : None [2022/08/17 23:45:05] root INFO: save_model_dir : ./output/rec/ [2022/08/17 23:45:05] root INFO: save_res_path : ./output/rec/predicts.txt [2022/08/17 23:45:05] root INFO: use_gpu : True [2022/08/17 23:45:05] root INFO: use_space_char : False [2022/08/17 23:45:05] root INFO: use_visualdl : False [2022/08/17 23:45:05] root INFO: Loss : [2022/08/17 23:45:05] root INFO: name : CTCLoss [2022/08/17 23:45:05] root INFO: Metric : [2022/08/17 23:45:05] root INFO: main_indicator : acc [2022/08/17 23:45:05] root INFO: name : RecMetric [2022/08/17 23:45:05] root INFO: Optimizer : [2022/08/17 23:45:05] root INFO: beta1 : 0.9 [2022/08/17 23:45:05] root INFO: beta2 : 0.999 [2022/08/17 23:45:05] root INFO: lr : [2022/08/17 23:45:05] root INFO: learning_rate : 0.0005 [2022/08/17 23:45:05] root INFO: name : Adam [2022/08/17 23:45:05] root INFO: regularizer : [2022/08/17 23:45:05] root INFO: factor : 0 [2022/08/17 23:45:05] root INFO: name : L2 [2022/08/17 23:45:05] root INFO: PostProcess : [2022/08/17 23:45:05] root INFO: name : CTCLabelDecode [2022/08/17 23:45:05] root INFO: Train : [2022/08/17 23:45:05] root INFO: dataset : [2022/08/17 23:45:05] root INFO: data_dir : ./train_data/ [2022/08/17 23:45:05] root INFO: label_file_list : ['./train_data/train_list.txt'] [2022/08/17 23:45:05] root INFO: name : SimpleDataSet [2022/08/17 23:45:05] root INFO: transforms : [2022/08/17 23:45:05] root INFO: DecodeImage : [2022/08/17 23:45:05] root INFO: channel_first : False [2022/08/17 23:45:05] root INFO: img_mode : BGR [2022/08/17 23:45:05] root INFO: CTCLabelEncode : None [2022/08/17 23:45:05] root INFO: RecResizeImg : [2022/08/17 23:45:05] root INFO: image_shape : [3, 32, 100] [2022/08/17 23:45:05] root INFO: KeepKeys : [2022/08/17 23:45:05] root INFO: keep_keys : ['image', 'label', 'length'] [2022/08/17 23:45:05] root INFO: loader : [2022/08/17 23:45:05] root INFO: batch_size_per_card : 256 [2022/08/17 23:45:05] root INFO: drop_last : True [2022/08/17 23:45:05] root INFO: num_workers : 8 [2022/08/17 23:45:05] root INFO: shuffle : True [2022/08/17 23:45:05] root INFO: use_shared_memory : False [2022/08/17 23:45:05] root INFO: train with paddle 2.0.2 and device CUDAPlace(0) W0817 23:45:05.465901 12119 device_context.cc:362] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 11.2, Runtime API Version: 10.1 W0817 23:45:05.470815 12119 device_context.cc:372] device: 0, cuDNN Version: 7.6. [2022/08/17 23:45:08] root INFO: resume from ./output/rec/best_accuracy [2022/08/17 23:45:08] root INFO: infer_img: ../report_ex/test_rec/20220623110401-1001_0119.png [2022/08/17 23:45:08] root INFO: result: ('阴性', 0.89460135) [2022/08/17 23:45:08] root INFO: success!
In [ ]
import matplotlib.pyplot as plt
from PIL import Image
%pylab inline
def show_img(img_path,figsize=(10,10)):
## 显示原图,读取名称为11.jpg的测试图像
img = Image.open(img_path)
plt.figure("test_img", figsize=figsize)
plt.imshow(img)
plt.show()
show_img("../report_ex/test_rec/20220623110401-1001_0119.png")
Populating the interactive namespace from numpy and matplotlib
测试文件夹下所有图像的文字识别效果,根据自身需要自行测试
In [ ]
!python3 tools/infer_rec.py -c configs/rec/rec_icdar15_train.yml -o Global.checkpoints=./output/rec_CRNN/best_accuracy Global.infer_img=./doc/imgs_words_en/
In [ ]
!cp ./data/data164761/best_accuracy.pdopt ./outputall/rec
!cp ./data/data164761/best_accuracy.pdparams ./outputall/rec
In [ ]
#1.导出检测模型
%cd PaddleOCR/
!python tools/export_model.py -c configs/det/det_mv3_db_all.yml \
-o Global.pretrained_model="../outputall/db_mv3/best_accuracy" \
Global.save_inference_dir="./my_det_model"
/home/aistudio/PaddleOCR /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/layers/utils.py:26: DeprecationWarning: `np.int` is a deprecated alias for the builtin `int`. To silence this warning, 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. Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations def convert_to_list(value, n, name, dtype=np.int): W0817 22:11:30.547513 1528 device_context.cc:362] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 11.2, Runtime API Version: 10.1 W0817 22:11:30.552330 1528 device_context.cc:372] device: 0, cuDNN Version: 7.6. [2022/08/17 22:11:33] root INFO: load pretrained model from ['../outputall/db_mv3/best_accuracy'] [2022/08/17 22:11:34] root INFO: inference model is saved to ./my_det_model/inference
In [ ]
#2.
%cd PaddleOCR/
!python tools/export_model.py -c configs/rec/ch_PP-OCRv3_rec_distillation.yml \
-o Global.pretrained_model="../outputall/rec/best_accuracy" \
Global.save_inference_dir="./my_rec_model"
#3.导出上述代码生成的识别模型
%cd PaddleOCR/
!python tools/export_model.py -c configs/rec/rec_icdar15_train.yml \
-o Global.pretrained_model="./output/rec/best_accuracy" \
Global.save_inference_dir="./my_zj_rec_model"
/home/aistudio/PaddleOCR /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/layers/utils.py:26: DeprecationWarning: `np.int` is a deprecated alias for the builtin `int`. To silence this warning, 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. Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations def convert_to_list(value, n, name, dtype=np.int): W0820 10:01:46.662283 1446 device_context.cc:362] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 11.2, Runtime API Version: 10.1 W0820 10:01:46.666363 1446 device_context.cc:372] device: 0, cuDNN Version: 7.6. [2022/08/20 10:01:49] root INFO: load pretrained model from ['./output/rec/best_accuracy'] [2022/08/20 10:01:50] root INFO: inference model is saved to ./my_zj_rec_model/inference
# 检测+识别
!pwd
%cd PaddleOCR
# !python3 ./tools/infer/predict_system.py --image_dir="../report_ex/test_rec/20220623110401-1006_0123.png" \
!python3 ./tools/infer/predict_system.py --image_dir="../report_ex/pngs/20220623110401-101.png" \
--det_model_dir="./my_det_model/" \ #使用上述代码生成的检测模型
--rec_model_dir="./my_zj_rec_model/" \ #使用上述代码生成的识别模型
#--rec_model_dir="./inference/ch_ppocr_mobile_v2.0_rec_infer" \ #使用官方识别模型
/home/aistudio/PaddleOCR [Errno 2] No such file or directory: 'PaddleOCR' /home/aistudio/PaddleOCR /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/layers/utils.py:26: DeprecationWarning: `np.int` is a deprecated alias for the builtin `int`. To silence this warning, 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. Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations def convert_to_list(value, n, name, dtype=np.int): [2022/08/20 09:51:36] root INFO: dt_boxes num : 117, elapse : 1.619128942489624 [2022/08/20 09:51:36] root INFO: rec_res num : 117, elapse : 0.24797725677490234 [2022/08/20 09:51:36] root INFO: Predict time of ../report_ex/pngs/20220623110401-101.png: 2.001s [2022/08/20 09:51:36] root INFO: 性别:男, 0.994 [2022/08/20 09:51:36] root INFO: 姓名:张某某, 0.995 [2022/08/20 09:51:36] root INFO: 年龄:40, 0.997 [2022/08/20 09:51:36] root INFO: 尿液其他检查, 0.947 [2022/08/20 09:51:36] root INFO: 检查日期:2022-6-1, 0.997 [2022/08/20 09:51:36] root INFO: 检查医生:徐金凤, 0.981 [2022/08/20 09:51:36] root INFO: 本周氏蛋白定, 0.977 [2022/08/20 09:51:36] root INFO: 阴性, 0.996 [2022/08/20 09:51:36] root INFO: 阴性, 0.992 [2022/08/20 09:51:36] root INFO: 乳魔尿, 0.812 [2022/08/20 09:51:36] root INFO: 阳性, 0.999 [2022/08/20 09:51:36] root INFO: 阴性, 0.995 [2022/08/20 09:51:36] root INFO: U/L, 0.827 [2022/08/20 09:51:36] root INFO: 阴性, 0.995 [2022/08/20 09:51:36] root INFO: 阴性, 0.990 [2022/08/20 09:51:36] root INFO: 58., 0.862 [2022/08/20 09:51:36] root INFO: 3325U/, 0.821 [2022/08/20 09:51:36] root INFO: 绒毛膜促性腺, 0.946 [2022/08/20 09:51:36] root INFO: 尿液淀粉酶测, 0.973 [2022/08/20 09:51:36] root INFO: 阴性, 0.995 [2022/08/20 09:51:36] root INFO: RBC, 0.995 [2022/08/20 09:51:36] root INFO: RBC<3,, 0.874 [2022/08/20 09:51:36] root INFO: 尿含铁血黄素, 0.848 [2022/08/20 09:51:36] root INFO: 阴性, 0.980 [2022/08/20 09:51:36] root INFO: 检查小结, 0.996 [2022/08/20 09:51:36] root INFO: 安全用户电影地方所有你的, 1.000 [2022/08/20 09:51:36] root INFO: 娄便检查, 0.776 [2022/08/20 09:51:36] root INFO: 检查日期:2022-6-1, 0.996 [2022/08/20 09:51:36] root INFO: 检查医生:王超, 0.978 [2022/08/20 09:51:36] root INFO: 粪便常规, 0.830 [2022/08/20 09:51:36] root INFO: RBC, 0.997 [2022/08/20 09:51:36] root INFO: RBC:0, 0.898 [2022/08/20 09:51:36] root INFO: 寄生虫检查, 0.992 [2022/08/20 09:51:36] root INFO: O/H, 0.977 [2022/08/20 09:51:36] root INFO: O/HP, 0.939 [2022/08/20 09:51:36] root INFO: 大便动力, 0.998 [2022/08/20 09:51:36] root INFO: 便潜血检查, 0.971 [2022/08/20 09:51:36] root INFO: 阳性, 0.988 [2022/08/20 09:51:36] root INFO: 阴性, 0.813 [2022/08/20 09:51:36] root INFO: 动力阴性, 0.856 [2022/08/20 09:51:36] root INFO: 阴性, 0.997 [2022/08/20 09:51:36] root INFO: 检查小结, 0.995 [2022/08/20 09:51:36] root INFO: 这个任何不断产品如何今年不是根据, 0.926 [2022/08/20 09:51:36] root INFO: 血液学检测基他, 0.947 [2022/08/20 09:51:36] root INFO: 检查日期:2022-6-1, 0.998 [2022/08/20 09:51:36] root INFO: 检查医生:金桂珍, 0.985 [2022/08/20 09:51:36] root INFO: 项目名称, 0.999 [2022/08/20 09:51:36] root INFO: 检查结果, 0.996 [2022/08/20 09:51:36] root INFO: 参考标识, 0.971 [2022/08/20 09:51:36] root INFO: 单位, 0.999 [2022/08/20 09:51:36] root INFO: 参考范围, 0.996 [2022/08/20 09:51:36] root INFO: 网织红细胞计数, 0.998 [2022/08/20 09:51:36] root INFO: 0.6, 0.956 [2022/08/20 09:51:36] root INFO: (0.5-1.5)0, 0.845 [2022/08/20 09:51:36] root INFO: 12.4, 0.995 [2022/08/20 09:51:36] root INFO: mm/hour, 0.997 [2022/08/20 09:51:36] root INFO: 血沉, 0.980 [2022/08/20 09:51:36] root INFO: 0-15, 0.986 [2022/08/20 09:51:36] root INFO: 阴性, 0.984 [2022/08/20 09:51:36] root INFO: 阴性, 0.991 [2022/08/20 09:51:36] root INFO: 嗜酸球计数, 0.938 [2022/08/20 09:51:36] root INFO: 8, 0.715 [2022/08/20 09:51:36] root INFO: 1.5, 0.980 [2022/08/20 09:51:36] root INFO: (0.5-5)。, 0.841 [2022/08/20 09:51:36] root INFO: 检查小结, 0.994 [2022/08/20 09:51:36] root INFO: 生化室项目一览表, 0.985 [2022/08/20 09:51:36] root INFO: 检查日期:2022-6-1, 0.998 [2022/08/20 09:51:36] root INFO: 检查医生:张海燕, 0.995 [2022/08/20 09:51:36] root INFO: 检查结果, 0.986 [2022/08/20 09:51:36] root INFO: 参考标识, 0.974 [2022/08/20 09:51:36] root INFO: 单位, 0.999 [2022/08/20 09:51:36] root INFO: 项目名称, 0.984 [2022/08/20 09:51:36] root INFO: 参考范围, 0.945 [2022/08/20 09:51:36] root INFO: 131.2, 0.995 [2022/08/20 09:51:36] root INFO: 肌酸激酶, 0.967 [2022/08/20 09:51:36] root INFO: U/L, 0.853 [2022/08/20 09:51:36] root INFO: 15.00~173.00U/l, 0.927 [2022/08/20 09:51:36] root INFO: 5.8, 0.994 [2022/08/20 09:51:36] root INFO: 快速血糖, 0.998 [2022/08/20 09:51:36] root INFO: mmovL, 0.822 [2022/08/20 09:51:36] root INFO: 4.22~6.11mmoVl, 0.920 [2022/08/20 09:51:36] root INFO: 5.3, 0.895 [2022/08/20 09:51:36] root INFO: mmovL, 0.822 [2022/08/20 09:51:36] root INFO: 快速钾, 0.895 [2022/08/20 09:51:36] root INFO: 个, 0.984 [2022/08/20 09:51:36] root INFO: 3.50~5.10 mmov/L, 0.943 [2022/08/20 09:51:36] root INFO: 84.1, 0.993 [2022/08/20 09:51:36] root INFO: umol/L, 0.755 [2022/08/20 09:51:36] root INFO: 44.00~133.00 umol/L, 0.962 [2022/08/20 09:51:36] root INFO: 阳性, 0.998 [2022/08/20 09:51:36] root INFO: 肌红蛋白, 0.965 [2022/08/20 09:51:36] root INFO: 阴性, 0.995 [2022/08/20 09:51:36] root INFO: 30.2, 0.996 [2022/08/20 09:51:36] root INFO: U/L, 0.930 [2022/08/20 09:51:36] root INFO: 0.00~46.00 U/L, 0.907 [2022/08/20 09:51:36] root INFO: 快速谷内转氨酶, 0.951 [2022/08/20 09:51:36] root INFO: 0.00~300 mg/L, 0.964 [2022/08/20 09:51:36] root INFO: 118.0, 0.993 [2022/08/20 09:51:36] root INFO: 脂蛋日(a), 0.883 [2022/08/20 09:51:36] root INFO: mg/L, 0.848 [2022/08/20 09:51:36] root INFO: 224.7, 0.982 [2022/08/20 09:51:36] root INFO: 20.00~220.00mmoV/L, 0.955 [2022/08/20 09:51:36] root INFO: mmovt, 0.774 [2022/08/20 09:51:36] root INFO: 血淀粉酶, 0.906 [2022/08/20 09:51:36] root INFO: 0.4, 0.977 [2022/08/20 09:51:36] root INFO: mmovL, 0.822 [2022/08/20 09:51:36] root INFO: 0.21~0.78 mmoVL, 0.963 [2022/08/20 09:51:36] root INFO: 极低密度脂蛋白胆固醇, 0.992 [2022/08/20 09:51:36] root INFO: 468.2, 0.998 [2022/08/20 09:51:36] root INFO: pmovL, 0.814 [2022/08/20 09:51:36] root INFO: 339.0~1107.0pmol/L, 0.952 [2022/08/20 09:51:36] root INFO: 血清维生素B12, 0.995 [2022/08/20 09:51:36] root INFO: 检查小结, 0.988 [2022/08/20 09:51:36] root INFO: 电脑他的建设进行客户历史自己, 0.999 [2022/08/20 09:51:36] root INFO: XX医院体检中心体检报告, 0.980
通过本次体检报告识别项目,使我对PaddleOCR有了进一步了解,整体项目分为检测+识别部分,最终识别精度可达到90%以上,针对部分文字和符号存在一定错误,后续可以尝试更多模型算法并引入NLP对识别结果进行文字纠错,进一步提升精度,在后续模型推广方面,可以进一步用于移动端或服务器端模型部署,达到真正用于企业需求效果。
参考:https://github.com/PaddlePaddle/PaddleOCR