赞
踩
LPRNet车辆识别模型
数据集处理:
CCCPD数据集
CCPD2019数据集:
CCPD2019数据集主要采集于合肥市停车场,采集时间为上午7:30到晚上10:00,停车场采集人员手持Android POS机对停车场的车辆拍照进行数据采集。所拍摄的车牌照片涉及多种复杂环境,包括模糊、倾斜、雨天、雪天等。CCPD2019数据集包含了25万多幅中国城市车牌图像和车牌检测与识别信息的标注。主要介绍如下:
类别 描述 图片数
CCPD-Base 通用车牌图片 200k
CCPD-FN 车牌离摄像头拍摄位置相对较近或较远 20k
CCPD-DB 车牌区域亮度较亮、较暗或者不均匀 20k
CCPD-Rotate 车牌水平倾斜20到50度,竖直倾斜-10到10度 10k
CCPD-Tilt 车牌水平倾斜15到45度,竖直倾斜15到45度 10k
CCPD-Weather 车牌在雨雪雾天气拍摄得到 10k
CCPD-Challenge 在车牌检测识别任务中较有挑战性的图片 10k
CCPD-Blur 由于摄像机镜头抖动导致的模糊车牌图片 5k
CCPD-NP 没有安装车牌的新车图片 5k
CCPD2019/CCPD-Base中的图像被拆分为train/val数据集。使用CCPD2019中的子数据集(CCPD-DB、CCPD-Blur、CCPD-FN、CCPD-Rotate、CCPD-Tilt、CCPD-Challenge)进行测试。
CCPD2019数据集(数据大小12.26G)下载地址:
链接:https://pan.baidu.com/s/1Jh55ufXZZpusg7Vhn4ZYdQ
提取码:f6mo
包括train,val,test;
首先,需要通过脚本将图片名称保存为一个txt中 "/data/zjzhang25/core_use/txt_check.py"
# coding=UTF8
import os
p="/data/aimonitor/data/datasets/car_license/1002/license_new/CCPD/test_datasets/images/"
data = os.listdir(p)
# print(data)
filename="/data/zjzhang25/core_our/myfile.txt"
file = open(filename,'a')
for i in range(len(data)):
s = str(data[i]).replace('[','').replace(']','') + '\n'#去除[],这两行按数据不同,可以选择
# s = s.replace("'",'').replace(',','') +'\n' #去除单引号,逗号,每行末尾追加换行符
file.write(s)
file.close()
print("保存文件成功")
其次,使用txt得到车牌和车牌尺寸并且将车牌切出并且加上车牌号名称保存与某一文件夹中 "/data/zjzhang25/core_use/split_liense.py",代码在下面:
# coding=UTF8
import cv2
import os
def new_label(old_label):
provinces = ["皖", "沪", "津", "渝", "冀", "晋", "蒙", "辽", "吉", "黑", "苏", "浙",
"京", "闽", "赣", "鲁", "豫", "鄂", "湘", "粤", "桂",
"琼", "川", "贵", "云", "藏", "陕", "甘", "青", "宁", "新", "警", "学",
"O"]
ads = ['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', 'O']
# code 2
char_dict = {"京": 0, "沪": 1, "津": 2, "渝": 3, "冀": 4, "晋": 5, "蒙": 6, "辽": 7, "吉": 8, "黑": 9, "苏": 10,
"浙": 11, "皖": 12, "闽": 13, "赣": 14, "鲁": 15, "豫": 16, "鄂": 17, "湘": 18, "粤": 19, "桂": 20,
"琼": 21, "川": 22, "贵": 23, "云": 24, "藏": 25, "陕": 26, "甘": 27, "青": 28, "宁": 29, "新": 30,
"0": 31, "1": 32, "2": 33, "3": 34, "4": 35, "5": 36, "6": 37, "7": 38, "8": 39, "9": 40,
"A": 41, "B": 42, "C": 43, "D": 44, "E": 45, "F": 46, "G": 47, "H": 48, "J": 49, "K": 50,
"L": 51, "M": 52, "N": 53, "P": 54, "Q": 55, "R": 56, "S": 57, "T": 58, "U": 59, "V": 60,
"W": 61, "X": 62, "Y": 63, "Z": 64}
car_code2 = ""
for i, number in enumerate(old_label.split("_")):
if i == 0:
car_origin_number = provinces[int(number)]
else:
car_origin_number = ads[int(number)]
# car_code2.append(char_dict[car_origin_number])
car_code2+=str(car_origin_number)
return car_code2
f=open('myfile.txt', encoding="utf-8")
txt=[]
for line in f:
txt.append(line.strip())
path="/data/aimonitor/data/datasets/car_license/1002/license_new/CCPD/test_datasets/images/"
path_new=[]
car_code2=[]
for i in range(len(txt)):
path_new=os.path.join(path,txt[i])
img=cv2.imread(path_new)
img_name = path_new
iname = img_name.rsplit('/', 1)[-1].rsplit('.', 1)[0].split('-')
old_label=iname[-3]
old_label=new_label(old_label)
[leftUp, rightDown] = [[int(eel) for eel in el.split('&')] for el in iname[2].split('_')]
cropped=img[leftUp[1]:rightDown[1],leftUp[0]:rightDown[0]]
pic = cv2.resize(cropped, (240, 80), interpolation=cv2.INTER_CUBIC)
#imagename = "images/" + str(old_label) + ".jpg"
imagename = str(old_label) + ".jpg"
cv2.imwrite(imagename, cropped)
cv2.imencode('.jpg', pic)[1].tofile(imagename)
print(i)
最终获取的数据是带着车牌号名称的车牌图片。
LPRnet模型代码可以自己去寻找
LPRnet中有train_LPRNet.py文件,这是训练文件
首先最好可以将
def train():
batch_iterator = iter(DataLoader(train_dataset, args.train_batch_size, shuffle=True, num_workers=args.num_workers, collate_fn=collate_fn))
中的shuffle=True删掉
如果我们使用的是自我定义的数据集的话
其次:
修改参数:
--train_img_dirs 后面处理后的数据集
--test_img_dirs 后面接测试数据集,测试数据集也要按要求(图片名称和车牌号相同)
--pretrained_model 模型权重
例如:
python3 train_LPRNet.py --train_img_dirs /data/aimonitor/data/datasets/car_shibie_license/1002/liense/images/ --test_img_dirs /data/aimonitor/data/datasets/car_shibie_license/1002/liense/test/ --pretrained_model ./weights/Final_LPRNet_model.pth
然后我们就可以找个地方玩玩,等待模型训练完成
等到训练完成,我们需要查看训练结果,并且需要测试数据
测试数据集需要按照要求,前面我们已经说过了,我们就不提了。
测试需要修改数据路径,模型路径,添加show命令
测试命令:
python3 test_LPRNet.py --test_img_dirs /data/lanpai --pretrained_model /home/aimonitor/tools/lprnet_master/weights/Final_LPRNet_model.pth --show True
这样就可以看到测试数据:
preb_label [12, 67, 41, 41, 67, 47, 47, 67, 52, 52, 67, 36, 67, 67, 38, 67, 39, 67]
preb_label [12, 12, 67, 41, 41, 67, 35, 67, 35, 35, 67, 39, 67, 39, 67, 67, 31, 67]
preb_label [12, 67, 41, 41, 67, 67, 57, 67, 49, 67, 67, 37, 67, 40, 40, 67, 37, 67]
preb_label [12, 67, 67, 41, 67, 60, 60, 67, 37, 37, 67, 37, 37, 67, 34, 67, 67, 48]
preb_label [12, 67, 41, 41, 62, 62, 67, 31, 31, 67, 34, 67, 67, 34, 67, 34, 67, 67]
preb_label [12, 41, 41, 67, 44, 67, 36, 36, 67, 36, 36, 67, 32, 32, 67, 36, 67, 67]
preb_label [12, 41, 41, 67, 67, 48, 67, 67, 43, 67, 40, 40, 67, 32, 67, 33, 33, 67]
preb_label [12, 12, 41, 41, 67, 64, 64, 67, 40, 40, 67, 36, 67, 67, 40, 67, 56, 67]
preb_label [12, 12, 41, 41, 67, 67, 31, 67, 67, 41, 67, 39, 67, 67, 39, 67, 67, 40]
preb_label [12, 12, 67, 41, 41, 67, 54, 54, 67, 51, 51, 67, 36, 67, 34, 67, 67, 37]
preb_label [12, 67, 41, 41, 67, 67, 56, 32, 67, 67, 33, 33, 67, 39, 67, 67, 39, 67]
preb_label [12, 12, 41, 41, 67, 41, 41, 32, 67, 32, 32, 67, 36, 36, 67, 60, 67, 67]
preb_label [12, 67, 41, 41, 67, 67, 41, 67, 63, 67, 67, 32, 67, 31, 31, 67, 37, 67]
preb_label [67, 12, 67, 41, 36, 46, 67, 64, 67, 34, 67, 12, 34, 67, 33, 67, 33, 67]
preb_label [12, 67, 41, 41, 67, 67, 56, 67, 67, 39, 67, 67, 40, 67, 36, 36, 67, 39]
preb_label [12, 12, 50, 50, 67, 67, 39, 39, 67, 47, 67, 34, 34, 67, 32, 67, 67, 32]
preb_label [12, 67, 41, 41, 67, 67, 39, 39, 67, 38, 67, 67, 43, 43, 67, 38, 38, 37]
target: 皖AYP502 ### T ### predict: 皖AYP502
target: 皖AVV576 ### T ### predict: 皖AVV576
target: 皖AC155W ### T ### predict: 皖AC155W
target: 皖AJ1U86 ### T ### predict: 皖AJ1U86
target: 皖A93444 ### F ### predict: 皖A9344
target: 皖AQU831 ### T ### predict: 皖AQU831
target: 皖AH8238 ### T ### predict: 皖AH8238
target: 皖ADM730 ### T ### predict: 皖ADM730
target: 皖AQ4773 ### F ### predict: 皖A04773
target: 皖AC822G ### T ### predict: 皖AC822G
target: 皖AH0C27 ### T ### predict: 皖AH0C27
target: 皖ADA5558 ### F ### predict: 皖AD45558
target: 皖AR2626 ### T ### predict: 皖AR2626
target: 皖AS7T31 ### T ### predict: 皖AS7T31
target: 皖A98R76 ### T ### predict: 皖A98R76
target: 皖AZ5125 ### T ### predict: 皖AZ5125
target: 沪C9J9T1 ### T ### predict: 沪C9J9T1
target: 皖A86N95 ### T ### predict: 皖A86N95
target: 皖AR5398 ### T ### predict: 皖AR5398
target: 皖AA223R ### T ### predict: 皖AA223R
target: 皖ASL244 ### T ### predict: 皖ASL244
target: 皖AZ837Y ### T ### predict: 皖AZ837Y
[Info] Test Accuracy: [94:2:4:100]
[Info] Test Accuracy: 0.94 [94:2:4:100]
至于测试结果怎么去看,下期我们再说
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。