代码拉取完成,页面将自动刷新
# 1. 安装PaddleOCR模型
%cd ~/Project
!git clone -b release/2.1 https://github.com/PaddlePaddle/PaddleOCR.git
# 准备超轻量级检测模型inference model
! 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
# 2. 下载超轻量级中文OCR模型
%cd ~/Project/PaddleOCR
!mkdir inference && cd inference
! 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
! 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
! 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
# 3. 安装依赖库
%cd ~/Project/PaddleOCR
!pip install -r requirements.txt -i https://mirror.baidu.com/pypi/simple
# 4. 快速预测单张图像
# 下面开始调用tools/infer/predict_system.py 完成图像文本识别,共需要传入三个参数:
# - image_dir: 指定要测试的图像
# - det_model_dir: 指定轻量检测模型的inference model
# - rec_model_dir: 指定轻量识别模型的inference model
# - cls_model_dir: 指定轻量方向分类器模型的inference model
# 快速运行,识别结果会可视化在图像中并保存在./inference_results文件夹下
%cd ~/Project/PaddleOCR
import matplotlib.pyplot as plt
from PIL import Image
%pylab inline
def show_img(img_path,figsize=(10,10)):
img = Image.open(img_path)
plt.figure("test_img", figsize=figsize)
plt.imshow(img)
plt.show()
show_img("./doc/imgs/french_0.jpg")
!python3 tools/infer/predict_system.py --image_dir="./doc/imgs/french_0.jpg" \
--det_model_dir="/home/aistudio/Project/PaddleOCR/inference/ch_ppocr_mobile_v2.0_det_infer" \
--rec_model_dir="/home/aistudio/Project/PaddleOCR/inference/ch_ppocr_mobile_v2.0_rec_infer" \
--cls_model_dir="/home/aistudio/Project/PaddleOCR/inference/ch_ppocr_mobile_v2.0_cls_infer"
# 1. 下载MobileNetV3\ResNet50的预训练模型
%cd ~/Project/PaddleOCR
!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
!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
# 2. 训练backbone为MobileNetV3的db算法的检测模型[检测框的训练]
%cd ~/Project
!python3 PaddleOCR/tools/train.py -c PaddleOCR/configs/det/det_mv3_db.yml -o \
Global.epoch_num=1200\
Global.eval_batch_step="[0,500]" \
Global.save_epoch_step=10 \
Global.save_model_dir="./output/Tyre_Defects_detection/det"\
Global.save_res_path="./output/Tyre_Defects_detection/det/predicts_db.txt"\
Train.dataset.data_dir='./train_data/Tyre_Defects_detection/' \
Train.dataset.label_file_list=['./train_data/Tyre_Defects_detection/train_label.txt'] \
Eval.dataset.data_dir='./train_data/Tyre_Defects_detection/' \
Eval.dataset.label_file_list=['./train_data/Tyre_Defects_detection/test_label.txt']
# 3. 模型检测
%cd ~/Project
show_img("./test/test2.jpg")
!python3 PaddleOCR/tools/infer_det.py -c PaddleOCR/configs/det/det_mv3_db.yml -o \
Global.infer_img="./test/test2.jpg" \
Global.checkpoints="./output/Tyre_Defects_detection/det/latest"
# 1. 下载Rec_Mv3的预训练模型
!wget -P ./pretrain_models/ https://paddleocr.bj.bcebos.com/rec_mv3_none_bilstm_ctc.tar
!cd pretrain_models && tar -xf rec_mv3_none_bilstm_ctc.tar && rm -rf rec_mv3_none_bilstm_ctc.tar
# 2. 训练文字检测模型
%cd ~/Project
!python3 PaddleOCR/tools/train.py -c PaddleOCR/configs/rec/rec_icdar15_train.yml -o \
Global.eval_batch_step="[0,500]" \
Global.save_epoch_step=10 \
Global.save_model_dir='./output/Tyre_Defects_detection/rec/'\
Train.dataset.data_dir='./train_data/Tyre_Defects_detection' \
Train.dataset.label_file_list=['./train_data/Tyre_Defects_detection/rec_gt_train.txt'] \
Eval.dataset.data_dir='./train_data/Tyre_Defects_detection' \
Eval.dataset.label_file_list=['./train_data/Tyre_Defects_detection/rec_gt_test.txt'] \
Optimizer.lr.learning_rate=0.0001
# 3. 模型检测
%cd ~/Project
show_img("./test/test1.jpg")
!python3 PaddleOCR/tools/infer_rec.py -c PaddleOCR/configs/rec/rec_icdar15_train.yml -o \
Global.infer_img="./test/test1.jpg" \
Global.checkpoints="./output/Tyre_Defects_detection/rec/latest"
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。