PaddleOCR训练自己数据集
目录1. 新建文件夹2. 准备数据3. 数据集的划分注意1注意24. 下载预训练模型5. 训练文字检测模型6. 训练文字识别模型7. 测试8. 转换为推理模型9. 检测模型和识别模型推理1. 新建文件夹进入PPOCRLabel源码目录在上一层目录新建文件夹train_data在train_data中新建文件夹drivingData。2. 准备数据在PPOCRLabel中标注好的数据如下图将标注好的数据拷贝到drivingData文件夹。3. 数据集的划分cd到PPOCRLabel源码路径运行划分数据集代码python gen_ocr_train_val_test.py--trainValTestRatio6:2:2--datasetRootPath../train_data/drivingData会在train_data文件夹下出现如下文件夹可删除drivingData文件夹。注意1新版本gen_ocr_train_val_test.py中做了操作系统兼容处理在linux下不会报错代码如下部分代码withopen(label_file_path,r,encodingUTF-8)aslabel_file:label_file_contentlabel_file.readlines()random.shuffle(label_file_content)label_record_lenlen(label_file_content)forindex,label_record_infoinenumerate(label_file_content):image_relative_path,image_labellabel_record_info.split(\t)image_nameos.path.basename(image_relative_path)ifflagdet:image_pathos.path.join(data_abs_path,image_name)elifflagrec:image_pathos.path.join(data_abs_path,args.recImageDirName,image_name)老版本gen_ocr_train_val_test.py中labelFileReadopen(labelFilePath,r,encodingUTF-8)labelFileContentlabelFileRead.readlines()random.shuffle(labelFileContent)labelRecordLenlen(labelFileContent)forindex,labelRecordInfoinenumerate(labelFileContent):imageRelativePathlabelRecordInfo.split(\t)[0]imageLabellabelRecordInfo.split(\t)[1]imageNameos.path.basename(imageRelativePath)ifflagdet:imagePathos.path.join(dataAbsPath,imageName)elifflagrec:imagePathos.path.join(dataAbsPath,{}\\{}.format(args.recImageDirName,imageName))在windows下使用以上代码在linux下将上面代码最后一行的“{}\{}”改为“{}/{}”。注意2如果是在云端AutoDL上进行训练建议在云端linux进行上面的数据划分代码如果在windows下划分的数据集路径为如下格式训练要在云端需要改路径D:\项目\train_data\det\train\2026_6_18_11_22_25_Digital.jpg[{transcription:23.6,points:[[287,152],[509,152],[509,277],[287,277]],difficult:false},{transcription:89,points:[[369,271],[505,271],[505,401],[369,401]],difficult:false}]D:\项目\train_data\det\train\2026_6_16_16_25_30_Digital.jpg[{transcription:21.5,points:[[300,197],[480,197],[480,283],[300,283]],difficult:false},{transcription:41.9,points:[[280,278],[485,278],[485,372],[280,372]],difficult:false}]D:\项目\train_data\det\train\2026_6_17_15_29_20_Digital.jpg[{transcription:20.2,points:[[305,154],[507,154],[507,280],[305,280]],difficult:false},{transcription:56,points:[[373,271],[502,271],[502,400],[373,400]],difficult:false}]train.txt文件中D:\项目\train_data\det\train替换/root/PaddleOCR/PaddleOCR-main/train_data/det/train/val.txt替换/root/PaddleOCR/PaddleOCR-main/train_data/det/val/test.txt替换/root/PaddleOCR/PaddleOCR-main/train_data/det/test/#rec文件夹也类似替换。4. 下载预训练模型模型列表将下载的预训练模型放在如下文件夹下5. 训练文字检测模型打开如下文件做如下修改Global: model_name: PP-OCRv5_server_det# To use static model for inference.debug:falseuse_gpu:trueepoch_num:epoch_num500log_smooth_window:20print_batch_step:10save_model_dir: /root/autodl-fs/output-1/PP-OCRv5_server_det save_epoch_step:10eval_batch_step: -0-200cal_metric_during_train:falsecheckpoints: pretrained_model: /root/PaddleOCR/PaddleOCR-main/pretrain_models/PP-OCRv5_server_det_pretrained.pdparams save_inference_dir: null use_visualdl:falseinfer_img: doc/imgs_en/img_10.jpg save_res_path: ./checkpoints/det_db/predicts_db.txt distributed:trueArchitecture: model_type: det algorithm: DB Transform: null Backbone: name: PPHGNetV2_B4 det: True Neck: name: LKPAN out_channels:256intracl:trueHead: name: PFHeadLocal k:50mode:largeLoss: name: DBLoss balance_loss:truemain_loss_type: DiceLoss alpha:5beta:10ohem_ratio:3Optimizer: name: Adam beta1:0.9beta2:0.999lr: name: Cosine learning_rate:0.001#(8*8c)warmup_epoch:2regularizer: name: L2 factor: 1e-6 PostProcess: name: DBPostProcess thresh:0.3box_thresh:0.6max_candidates:1000unclip_ratio:1.5Metric: name: DetMetric main_indicator: hmean Train: dataset: name: SimpleDataSet data_dir: /root/PaddleOCR/PaddleOCR-main/train_data label_file_list: - /root/PaddleOCR/PaddleOCR-main/train_data/det/train.txt ratio_list:[1.0]transforms: - DecodeImage: img_mode: BGR channel_first:false- DetLabelEncode: null - CopyPaste: null - IaaAugment: augmenter_args: - type: Fliplr args: p:0.5- type: Affine args: rotate: --10-10- type: Resize args: size: -0.5-3- EastRandomCropData: size: -640-640max_tries:50keep_ratio:true- MakeBorderMap: shrink_ratio:0.4thresh_min:0.3thresh_max:0.7total_epoch: *epoch_num - MakeShrinkMap: shrink_ratio:0.4min_text_size:8total_epoch: *epoch_num - NormalizeImage: scale:1./255. mean: -0.485-0.456-0.406std: -0.229-0.224-0.225order: hwc - ToCHWImage: null - KeepKeys: keep_keys: - image - threshold_map - threshold_mask - shrink_map - shrink_mask loader: shuffle:truedrop_last:falsebatch_size_per_card:8num_workers:8Eval: dataset: name: SimpleDataSet data_dir: /root/PaddleOCR/PaddleOCR-main/train_data label_file_list: - /root/PaddleOCR/PaddleOCR-main/train_data/det/val.txt transforms: - DecodeImage: img_mode: BGR channel_first:false- DetLabelEncode: null - DetResizeForTest: - NormalizeImage: scale:1./255. mean: -0.485-0.456-0.406std: -0.229-0.224-0.225order: hwc - ToCHWImage: null - KeepKeys: keep_keys: - image - shape - polys - ignore_tags loader: shuffle:falsedrop_last:falsebatch_size_per_card:4num_workers:8profiler_options: null打开anaconda激活虚拟环境进入到PaddleOCR-Main路径下输入下列代码开始训练python tools/train.py-c configs/det/PP-OCRv5/PP-OCRv5_server_det.yml6. 训练文字识别模型做如下修改Global: model_name: PP-OCRv5_server_rec# To use static model for inference.debug:falseuse_gpu:trueepoch_num:500log_smooth_window:20print_batch_step:10save_model_dir: /root/autodl-fs/output-1/PP-OCRv5_server_rec save_epoch_step:10eval_batch_step:[0,200]cal_metric_during_train:truecalc_epoch_interval:1pretrained_model: /root/PaddleOCR/PaddleOCR-main/pretrain_models/PP-OCRv5_server_rec_pretrained.pdparams checkpoints: save_inference_dir: use_visualdl:falseinfer_img: doc/imgs_words/ch/word_1.jpg character_dict_path: ./ppocr/utils/dict/weily.txt max_text_length:max_text_length25infer_mode:falseuse_space_char:truedistributed:truesave_res_path: /root/autodl-fs/output/rec/predicts_ppocrv5.txt d2s_train_image_shape:[3,48,320]Optimizer: name: Adam beta1:0.9beta2:0.999lr: name: Cosine learning_rate:0.0005warmup_epoch:1regularizer: name: L2 factor:3.0e-05 Architecture: model_type: rec algorithm: SVTR_HGNet Transform: Backbone: name: PPHGNetV2_B4 text_rec: True Head: name: MultiHead head_list: - CTCHead: Neck: name: svtr dims:120depth:2hidden_dims:120kernel_size:[1,3]use_guide: True Head: fc_decay:0.00001- NRTRHead: nrtr_dim:384max_text_length: *max_text_length Loss: name: MultiLoss loss_config_list: - CTCLoss: - NRTRLoss: PostProcess: name: CTCLabelDecode Metric: name: RecMetric main_indicator: acc Train: dataset: name: MultiScaleDataSet ds_width:falsedata_dir: /root/PaddleOCR/PaddleOCR-main/train_data ext_op_transform_idx:1label_file_list: - /root/PaddleOCR/PaddleOCR-main/train_data/rec/train.txt transforms: - DecodeImage: img_mode: BGR channel_first:false- RecAug: - MultiLabelEncode: gtc_encode: NRTRLabelEncode - KeepKeys: keep_keys: - image - label_ctc - label_gtc - length - valid_ratio sampler: name: MultiScaleSampler scales:[[320,32],[320,48],[320,64]]first_bs:bs128fix_bs:falsedivided_factor:[8,16]# w, his_training: True loader: shuffle:truebatch_size_per_card: *bs drop_last:truenum_workers:16Eval: dataset: name: SimpleDataSet data_dir: /root/PaddleOCR/PaddleOCR-main/train_data label_file_list: - /root/PaddleOCR/PaddleOCR-main/train_data/rec/val.txt transforms: - DecodeImage: img_mode: BGR channel_first:false- MultiLabelEncode: gtc_encode: NRTRLabelEncode - RecResizeImg: image_shape:[3,48,320]- KeepKeys: keep_keys: - image - label_ctc - label_gtc - length - valid_ratio loader: shuffle:falsedrop_last:falsebatch_size_per_card:128num_workers:4weily.txt文件如下0123456789-.输入下列代码开始训练python tools/train.py-c configs/rec/PP-OCRv5/PP-OCRv5_server_rec.yml7. 测试文本检测模型测试python tools/infer_det.py-c configs/det/PP-OCRv5/PP-OCRv5_server_det.yml-o Global.pretrained_model./output/PP-OCRv5_det/best_accuracy.pdparams Global.infer_imgC:\Users\langr\Desktop\PaddleOCR\PaddleOCR-main\test.jpg文本识别模型测试python tools/infer_rec.py-c configs/rec/PP-OCRv5/PP-OCRv5_server_rec.yml-o Global.pretrained_model./output/PP-OCRv5_rec/best_accuracy.pdparams Global.infer_imgC:\Users\langr\Desktop\PaddleOCR\PaddleOCR-main\test_crop.jpg8. 转换为推理模型文本检测模型python tools/export_model.py-c./configs/det/PP-OCRv5/PP-OCRv5_server_det.yml-o Global.pretrained_model./output/PP-OCRv5_server_det/best_accuracy.pdparamsGlobal.save_inference_dir./inference_model/det/文本识别模型python tools/export_model.py-c./configs/rec/PP-OCRv5/PP-OCRv5_server_rec.yml-o Global.pretrained_model./output/PP-OCRv5_server_rec/latest.pdparamsGlobal.save_inference_dir./inference_model/rec/9. 检测模型和识别模型推理步骤8的权重放在inference_model中测试代码如下frompaddleocrimportPaddleOCR,TextDetection,TextRecognition modelPaddleOCR(det_model_dirr/root/PaddleOCR/PaddleOCR-main/inference_model/det,rec_model_dirr/root/PaddleOCR/PaddleOCR-main/inference_model/rec,use_doc_orientation_classifyFalse,use_doc_unwarpingFalse,use_textline_orientationFalse,text_det_unclip_ratio1.5,text_det_limit_side_len1580,# 1080*2text_det_limit_typemax,text_det_thresh0.3,text_det_box_thresh0.6)outputmodel.predict(r/root/PaddleOCR/PaddleOCR-main/train_data/det/test/2026_8_6_10_44_04_Digital.jpg)forresinoutput:res.save_to_img(save_path./output/)res.save_to_json(save_path./output/res.json)

相关新闻

怎么降低ai查重率?AI降重后用AIGC检测报告定位具体反弹段

怎么降低ai查重率?AI降重后用AIGC检测报告定位具体反弹段

怎么降低ai查重率?AI降重后用AIGC检测报告定位具体反弹段 AI降重后全文数字看起来变低,却有几个原本正常的段落被新报告提示,这就是需要优先排查的反弹段。怎么降低ai查重率,不能再整篇重复处理,而要把处理前后AIGC报…

2026/10/25 18:37:18 阅读更多 →
02_Codex小白技巧_工作案例与私有化指南

02_Codex小白技巧_工作案例与私有化指南

02|接入 GitHub 之后,Codex 小白如何真正用起来? 快速部署 (gpt5.6)Codex 系列下篇|小白技巧、工作案例、安全与私有化 上篇我们解决了两件事:GitHub 是什么,以及怎么让 Codex 帮我…

2026/10/24 16:24:30 阅读更多 →
工业级布匹缺陷数据集构建:从采集、标注到模型训练全流程详解

工业级布匹缺陷数据集构建:从采集、标注到模型训练全流程详解

简介:在工业视觉与智能制造领域,高质量数据集是算法模型成功落地的基石。其核心原理在于为监督学习提供精准的标注信息,使模型能够学习从输入图像到目标输出的映射关系。构建一个符合工业标准的数据集具有极高的技术价值,它直接决…

2026/10/25 7:21:17 阅读更多 →

最新新闻

Electron桌面应用开发实战:从环境搭建到打包发布全流程

Electron桌面应用开发实战:从环境搭建到打包发布全流程

做前端这些年,我大部分时间都在跟浏览器标签页打交道,直到第一次把桌面应用跑起来,才发现原来自己一直被限制在地址栏和刷新按钮围起来的框框里。Electron这个词,最开始是在某段时间频繁出现在同事的讨论里,一个用HTML…

2026/11/6 15:21:35 阅读更多 →
滑盖智能锁T109深度解析:结构原理、安装调试与故障排查

滑盖智能锁T109深度解析:结构原理、安装调试与故障排查

简介:亚太天能T109滑盖智能锁产品说明书是一份PDF格式的官方技术文档,主要面向智能锁安装人员、终端用户及售后维护者,帮助快速掌握产品安装、配置与常见故障处理。全包仅1个PDF文件,大小4.37MB,内容结构清晰&#xff…

2026/11/6 9:29:27 阅读更多 →
PMSM弱磁控制原理与Simulink建模:高速AGV驱动系统设计指南

PMSM弱磁控制原理与Simulink建模:高速AGV驱动系统设计指南

上个月我在调试一台高速AGV的驱动系统,整车要求空载跑到8m/s,电机转速已经拉到额定点,驱动器的输出电压也顶到了母线电压极限附近。再往上踩速度指令,转速纹丝不动,三相电流反而开始震荡。那会儿我的第一反应就是&…

2026/11/5 12:28:01 阅读更多 →
C++核心知识点:从内存管理到STL的实战指南

C++核心知识点:从内存管理到STL的实战指南

C 这门语言我前前后后折腾了十几年,用它写过嵌入式驱动、做过游戏服务端,也搭过基础组件库。每次看到新人一头扎进"C 核心知识点"这个搜索词,我其实挺感慨的——这门语言的难点从来不是语法多,而是知识点之间的耦合太深…

2026/11/5 12:28:02 阅读更多 →
T109滑盖智能锁怎么装?安装调试与故障排查全攻略

T109滑盖智能锁怎么装?安装调试与故障排查全攻略

简介:亚太天能T109滑盖智能锁产品说明书以PDF格式发布,适合智能锁用户、安装人员与售后维修人员阅读。内容围绕T109系列指纹密码刷卡锁展开,先介绍前面板、后面板、锁体、机械钥匙、电池盒盖等部件名称与功能,再给出完整安装步骤&…

2026/11/6 8:08:42 阅读更多 →
LLM知识降熵:从信息垄断到理解权下放

LLM知识降熵:从信息垄断到理解权下放

你有没有过这种经历:翻开源码注释、论文摘要或者一份专业报告,每个字都认识,连在一起却像天书。想找人聊聊,身边要么没人懂,要么懂的懒得跟你解释。后来我试着把同一段内容丢给一个大语言模型,几秒钟之后&a…

2026/11/5 19:38:59 阅读更多 →

日新闻

周新闻

月新闻