**step1:**進入BML主頁,點選立即使用
🔗:https://ai.baidu.com/bml/
**step2:**點選Notebook,建立「通用任務」
**step3:**填寫任務資訊
第一步:設定Notebook
1.找到昨天建立的Notebook任務,點選設定
**
**
2.開啟Notebook
3.建立一個Notebook,選擇Python3
第二步:上傳資料集至Notebook
1.下載資料集至本地
https://aistudio.baidu.com/aistudio/datasetdetail/123686
2.上傳資料集至Notebook並解壓
!unzip -q /home/work/chepaishibie.zip
3.生成標籤檔案
CCPD資料集沒有專門的標註檔案,每張影象的檔名就是對應的資料標註(label)
僅使用到資料集中正常車牌即ccpd_base的資料
import os, cv2
import random
words_list = [
"A", "B", "C", "D", "E",
"F", "G", "H", "J", "K",
"L", "M", "N", "P", "Q",
"R", "S", "T", "U", "V",
"W", "X", "Y", "Z", "0",
"1", "2", "3", "4", "5",
"6", "7", "8", "9" ]
con_list = [
"皖", "滬", "津", "渝", "冀",
"晉", "蒙", "遼", "吉", "黑",
"蘇", "浙", "京", "閩", "贛",
"魯", "豫", "鄂", "湘", "粵",
"桂", "瓊", "川", "貴", "雲",
"西", "陝", "甘", "青", "寧",
"新"]
count = 0
total = []
paths = os.listdir('/home/work/chepaishibie')#真實資料集路徑
#for path in paths:
for item in os.listdir(os.path.join('/home/work/chepaishibie')):#真實資料集路徑
if item[-3:] =='jpg':
new_path = os.path.join('/home/work/chepaishibie', item) #訓練圖片路徑的路徑
_, _, bbox, points, label, _, _ = item.split('-')
points = points.split('_')
points = [_.split('&') for _ in points]
tmp = points[-2:]+points[:2]
points = []
for point in tmp:
points.append([int(_) for _ in point])
label = label.split('_')
con = con_list[int(label[0])]
words = [words_list[int(_)] for _ in label[1:]]
label = con+''.join(words)
line = new_path+'\t'+'[{"transcription": "%s", "points": %s}]' % (' ', str(points))
line = line[:]+'\n'
total.append(line)
random.shuffle(total)
with open('/home/work/data/train.txt', 'w', encoding='UTF-8') as f:
for line in total[:-200]:
f.write(line)
with open('/home/work/data/dev.txt', 'w', encoding='UTF-8') as f:
for line in total[-200:]:
f.write(line)
檢查data下的兩個txt檔案
第三步:設定環境
1.升級PaddlePaddle
!pip install paddlepaddle-gpu==2.2.1.post101 -f https://www.paddlepaddle.org.cn/whl/linux/mkl/avx/stable.html
2.下載PaddleOCR
!git clone https://gitee.com/PaddlePaddle/PaddleOCR.git
3.下載預訓練模型
cd /home/work/PaddleOCR
!wget -P ./pretrain_models/ https://paddleocr.bj.bcebos.com/ch_models/ch_det_mv3_db.tar!wget -P ./pretrain_models/ https://paddleocr.bj.bcebos.com/rec_mv3_tps_bilstm_attn.tar
cd pretrain_models
!tar -xf ch_det_mv3_db.tar && rm -rf ch_det_mv3_db.tar!tar -xf rec_mv3_tps_bilstm_attn.tar && rm -rf rec_mv3_tps_bilstm_attn.tar
第四步:儲存Notebook並關閉、停止執行
第一步:重新安裝環境
1.啟動Notebook並開啟
2.重新執行以下安裝命令
第二步:安裝PaddleOCR相關依賴檔案
1.修改requirements檔案
刪除opencv-contrib-python==4.4.0.46
2.執行以下兩個安裝命令
cd /home/work/PaddleOCR
!pip install -r requirements.txt
!pip install opencv-contrib-python==4.2.0.32
第三步:修改模型訓練的yml檔案
進入路徑PaddleOCR/configs/det/
開啟det_mv3_db.yml
1.修改模型路徑和儲存路徑
2.修改訓練資料的路徑
訓練集:
驗證集:
3.設定訓練引數
epoch數:
batch_size:
第四步:模型訓練
CUDA_VISIBLE_DEVICES=0!python3 tools/train.py -c configs/det/det_mv3_db.yml
第五步:儲存Notebook並關閉、停止執行
第一步:重新安裝環境
1.啟動Notebook並開啟
2.重新執行以下安裝命令
升級PaddlePaddle
安裝相關依賴
第二步:匯出文字檢測模型
!python3 /home/work/PaddleOCR/tools/export_model.py \ -c /home/work/PaddleOCR/configs/det/det_mv3_db.yml \ -o Global.checkpoints=/home/work/PaddleOCR/output/db_mv3/best_accuracy \ Global.save_inference_dir=/home/work/PaddleOCR/inference/
第三步:下載安裝文字識別模型
!wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_server_v2.0_rec_infer.tar!tar -xf ch_ppocr_server_v2.0_rec_infer.tar -C inference
第四步:模型預測
1.上傳一張車牌圖片作為預測圖片
上傳至home/work根目錄,命名為test.jpg
2.執行預測命令
!python /home/work/PaddleOCR/tools/infer/predict_system.py \
--image_dir="/home/work/test.jpg" \ --det_model_dir="/home/work/PaddleOCR/inference/" \ --rec_model_dir="/home/work/PaddleOCR/inference/ch_ppocr_server_v2.0_rec_infer/" \ --use_gpu False