# ling_python_common **Repository Path**: ling2/ling_python_common ## Basic Information - **Project Name**: ling_python_common - **Description**: ling_python_common - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2023-03-21 - **Last Updated**: 2023-05-22 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README pip freeze > requirements.txt pip install -r requirements.txt python -m pip install paddlepaddle -i https://mirror.baidu.com/pypi/simple [//]: # (python -m pip install paddlepaddle-gpu -i https://mirror.baidu.com/pypi/simple (2.4.2)) paddlepaddle-gpu的版本需要和CUDA和版本一致 https://www.paddlepaddle.org.cn/ 比如window python -m pip install paddlepaddle-gpu==2.4.2.post117 -f https://www.paddlepaddle.org.cn/whl/windows/mkl/avx/stable.html linux python -m pip install paddlepaddle-gpu==2.4.2.post117 -f https://www.paddlepaddle.org.cn/whl/linux/mkl/avx/stable.html 对应paddlepaddle-gpu==2.4.2 CUDA为11.7 https://developer.download.nvidia.com/compute/cuda/11.7.1/local_installers/cuda_11.7.1_516.94_windows.exe wget https://developer.download.nvidia.com/compute/cuda/11.7.1/local_installers/cuda-repo-rhel7-11-7-local-11.7.1_515.65.01-1.x86_64.rpm sudo rpm -i cuda-repo-rhel7-11-7-local-11.7.1_515.65.01-1.x86_64.rpm sudo yum clean all sudo yum -y install nvidia-driver-latest-dkms sudo yum -y install cuda pip install "paddleocr>=2.0.1" # 推荐使用2.0.1+版本 paddleocr默认使用PP-OCRv3模型(--ocr_version PP-OCRv3) paddleocr --image_dir ./imgs_words/ch/word_1.jpg --lang=ch C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.7\bin C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.7\libnvvp C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.7\cudnn\bin C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.7\extras\CUPTI\lib64 cd /ling-cloud git clone https://ling2:Wb191010610109@gitee.com/ling2/PaddleOCR.git source /root/anaconda3/bin/activate conda activate paddle_env cd /ling-cloud/PaddleOCR/ # 下载英文PP-OCRv3的预训练模型 wget -P ./pretrain_models/ https://paddleocr.bj.bcebos.com/PP-OCRv3/english/en_PP-OCRv3_rec_train.tar # 训练集标签 wget -P ./train_data/ic15_data https://paddleocr.bj.bcebos.com/dataset/rec_gt_train.txt # 测试集标签 wget -P ./train_data/ic15_data https://paddleocr.bj.bcebos.com/dataset/rec_gt_test.txt # 解压模型参数 cd pretrain_models tar -xf en_PP-OCRv3_rec_train.tar && rm -rf en_PP-OCRv3_rec_train.tar 训练中文数据,推荐使用rec_chinese_lite_train_v2.0.yml, # GPU训练 支持单卡,多卡训练 # 训练icdar15英文数据 训练日志会自动保存为 "{save_model_dir}" 下的train.log #单卡训练(训练周期长,不建议) python3 tools/train.py -c configs/rec/PP-OCRv3/en_PP-OCRv3_rec.yml -o Global.pretrained_model=./pretrain_models/en_PP-OCRv3_rec_train/best_accuracy #多卡训练,通过--gpus参数指定卡号 python3 -m paddle.distributed.launch --gpus '0,1,2,3' tools/train.py -c configs/rec/ch_ppocr_v2.0/rec_chinese_lite_train_v2.0.yml [//]: # (python tools/train.py -c configs/rec/ch_ppocr_v2.0/rec_chinese_lite_train_v2.0.yml) # 预测中文结果 [//]: # (python3 tools/infer_rec.py -c configs/rec/ch_ppocr_v2.0/rec_chinese_lite_train_v2.0.yml -o Global.pretrained_model=output/rec_chinese_lite_v2.0/best_accuracy Global.load_static_weights=false Global.infer_img=train_data/customer/1.png) PaddleOCR提供的配置文件是在8卡训练(相当于总的batch size是8*128=1024)、且没有加载预训练模型情况下的配置文件,因此您的场景中,学习率与总的batch size需要对应线性调整,例如: 如果您的场景中是单卡训练,单卡batch_size=128,则总的batch_size=128,在加载预训练模型的情况下,建议将学习率调整为[1e-4, 2e-5]左右(piecewise学习率策略,需设置2个值,下同)。 如果您的场景中是单卡训练,因为显存限制,只能设置单卡batch_size=64,则总的batch_size=64,在加载预训练模型的情况下,建议将学习率调整为[5e-5, 1e-5]左右。 python tools/train.py -c configs/rec/PP-OCRv3/ch_PP-OCRv3_rec_distillation_customer.yml python tools/infer_rec.py -c configs/rec/PP-OCRv3/ch_PP-OCRv3_rec_distillation_customer.yml -o Global.load_static_weights=false Global.infer_img=train_data/customer/crop_img/1_crop_0.jpg #多卡训练,通过--gpus参数指定卡号 python -m paddle.distributed.launch --gpus '1' tools/train.py -c configs/rec/PP-OCRv3/ch_PP-OCRv3_rec_distillation_customer.yml # inference 模型(paddle.jit.save保存的模型) 一般是模型训练,把模型结构和模型参数保存在文件中的固化模型,多用于预测部署场景。 训练过程中保存的模型是checkpoints模型,保存的只有模型的参数,多用于恢复训练等。 与checkpoints模型相比,inference 模型会额外保存模型的结构信息,在预测部署、加速推理上性能优越,灵活方便,适合于实际系统集成。识别模型转inference模型与检测的方式相同,如下: # -c 后面设置训练算法的yml配置文件 # -o 配置可选参数 # Global.pretrained_model 参数设置待转换的训练模型地址,不用添加文件后缀 .pdmodel,.pdopt或.pdparams。 # Global.save_inference_dir参数设置转换的模型将保存的地址。 python tools/export_model.py -c configs/rec/PP-OCRv3/ch_PP-OCRv3_rec_distillation_customer.yml # 自定义模型推理 python tools/infer/predict_rec.py --image_dir="./doc/imgs_words_en/word_336.png" --rec_model_dir="./inference/ch_PP-OCRv3_rec_train_customer" --rec_image_shape="3, 48, 320" --rec_char_dict_path="your text dict path" pip install pyqt5 cd ./PPOCRLabel # 将目录切换到PPOCRLabel文件夹下 python PPOCRLabel.py --lang ch python PPOCRLabel.py --lang ch --kie True --gpu false # 选择标签模式来启动 PPOCRLabel --lang ch # 启动【普通模式】,用于打【检测+识别】场景的标签 PPOCRLabel --lang ch --kie True # 启动 【KIE 模式】,用于打【检测+识别+关键字提取】场景的标签 建议选择PP-OCRv3模型(配置文件:ch_PP-OCRv3_rec_distillation.yml,预训练模型:ch_PP-OCRv3_rec_train.tar)进行微调,其精度与泛化性能是目前提供的最优预训练模型。