微信公众号:小白图像与视觉
关于技术、关注
yysilence00
。有问题或建议,请公众号留言。
# 查看当前挂载的数据集目录, 该目录下的变更重启环境后会自动还原
# View dataset directory. This directory will be recovered automatically after resetting environment.
!ls /home/aistudio/data
0 6 C F H jing M Q su wan yu1
1 7 cuan G hei jl meng qing sx X yue
2 8 D gan hu K min qiong T xiang yun
3 9 data23617 gan1 J L N R U xin Z
4 A E gui ji liao ning S V Y zang
5 B e1 gui1 jin lu P shan W yu zhe
# 查看工作区文件, 该目录下的变更将会持久保存. 请及时清理不必要的文件, 避免加载过慢.
# View personal work directory. All changes under this directory will be kept even after reset. Please clean unnecessary files in time to speed up environment loading.
!ls /home/aistudio/work
!rm -rf __MACOSX
#!unzip -q /home/aistudio/data/data23617/characterData.zip
#导入需要的包
import numpy as np
import paddle as paddle
import paddle.fluid as fluid
from PIL import Image
import cv2
import matplotlib.pyplot as plt
import os
from multiprocessing import cpu_count
from paddle.fluid.dygraph import Pool2D,Conv2D
# from paddle.fluid.dygraph import FC
from paddle.fluid.dygraph import Linear
# 生成车牌字符图像列表
data_path = '/home/aistudio/data'
character_folders = os.listdir(data_path)
label = 0
LABEL_temp = {}
if(os.path.exists('./train_data.list')):
os.remove('./train_data.list')
if(os.path.exists('./test_data.list')):
os.remove('./test_data.list')
for character_folder in character_folders:
with open('./train_data.list', 'a') as f_train:
with open('./test_data.list', 'a') as f_test:
if character_folder == '.DS_Store' or character_folder == '.ipynb_checkpoints' or character_folder == 'data23617':
continue
print(character_folder + " " + str(label))
LABEL_temp[str(label)] = character_folder #存储一下标签的对应关系
character_imgs = os.listdir(os.path.join(data_path, character_folder))
for i in range(len(character_imgs)):
if i%10 == 0:
f_test.write(os.path.join(os.path.join(data_path, character_folder), character_imgs[i]) + "\t" + str(label) + '\n')
else:
f_train.write(os.path.join(os.path.join(data_path, character_folder), character_imgs[i]) + "\t" + str(label) + '\n')
label = label + 1
print('图像列表已生成')
zhe 0
W 1
D 2
liao 3
X 4
3 5
T 6
K 7
V 8
yu1 9
5 10
jl 11
gui1 12
Z 13
8 14
jing 15
su 16
Q 17
xin 18
G 19
1 20
gan 21
hei 22
zang 23
cuan 24
H 25
7 26
yue 27
M 28
gan1 29
yun 30
wan 31
min 32
yu 33
L 34
gui 35
J 36
6 37
N 38
xiang 39
0 40
lu 41
sx 42
4 43
jin 44
S 45
U 46
Y 47
9 48
F 49
C 50
E 51
2 52
R 53
e1 54
B 55
meng 56
shan 57
ji 58
qing 59
A 60
P 61
ning 62
qiong 63
hu 64
图像列表已生成
# 用上一步生成的图像列表定义车牌字符训练集和测试集的reader
def data_mapper(sample):
img, label = sample
img = paddle.dataset.image.load_image(file=img, is_color=False)
img = img.flatten().astype('float32') / 255.0
return img, label
def data_reader(data_list_path):
def reader():
with open(data_list_path, 'r') as f:
lines = f.readlines()
for line in lines:
img, label = line.split('\t')
yield img, int(label)
return paddle.reader.xmap_readers(data_mapper, reader, cpu_count(), 1024)
# 用于训练的数据提供器
train_reader = paddle.batch(reader=paddle.reader.shuffle(reader=data_reader('./train_data.list'), buf_size=512), batch_size=128)
# 用于测试的数据提供器
test_reader = paddle.batch(reader=data_reader('./test_data.list'), batch_size=128)
#定义网络
class MyLeNet(fluid.dygraph.Layer):
def __init__(self):
super(MyLeNet,self).__init__()
self.conv1 = Conv2D(1,28,5,1)
self.pool1 = Pool2D(pool_size = 2, pool_type = 'max', pool_stride = 1)
self.conv2 = Conv2D(28,32,3,1)
self.pool2 = Pool2D(pool_size = 2, pool_type = 'max', pool_stride = 1)
self.conv3 = Conv2D(32,32,3,1)
self.fullconnect = Linear(32*10*10,65, act = 'softmax')
def forward(self,input):
x1 = self.conv1(input)
x2 = self.pool1(x1)
x3 = self.conv2(x2)
x4 = self.pool2(x3)
x5 = self.conv3(x4)
x6 = fluid.layers.reshape(x5, shape = [-1,32*10*10])
y = self.fullconnect(x6)
return y
# 绘制曲线函数
iter = 0
iters=[]
all_train_loss=[]
all_train_accs=[]
def draw_train_process(title,iters,training_loss,training_accs):
plt.title(title, fontsize=24)
plt.xlabel("iter", fontsize=20)
plt.ylabel("loss/acc", fontsize=20)
plt.plot(iters, color='red',label='training_loss')
plt.plot(iters, color='green',label='training_accs')
plt.legend()
plt.grid()
plt.show()
with fluid.dygraph.guard():
model=MyLeNet() #模型实例化
model.train() #训练模式
opt=fluid.optimizer.SGDOptimizer(learning_rate=0.001, parameter_list=model.parameters())#优化器选用SGD随机梯度下降,学习率为0.001.
epochs_num= 200 #迭代次数为200
for pass_num in range(epochs_num):
for batch_id, data in enumerate(train_reader()):
images=np.array([x[0].reshape(1,20,20) for x in data],np.float32)
labels = np.array([x[1] for x in data]).astype('int64')
labels = labels[:, np.newaxis]
image=fluid.dygraph.to_variable(images)
label=fluid.dygraph.to_variable(labels)
predict=model(image)#获取分类器 就是预测
loss=fluid.layers.cross_entropy(predict,label)
avg_loss=fluid.layers.mean(loss)#获取loss值
acc=fluid.layers.accuracy(predict,label)#计算精度
iter =iter+ 128
iters.append(iter)
all_train_loss.append(loss.numpy()[0])
all_train_accs.append(acc.numpy()[0])
if batch_id!=0 and batch_id%50==0:
print("train_pass:{},batch_id:{},train_loss:{},train_acc:{}".format(pass_num,batch_id,avg_loss.numpy(),acc.numpy()))
avg_loss.backward()
opt.minimize(avg_loss)
model.clear_gradients()
fluid.save_dygraph(model.state_dict(),'MyLeNet')#保存模型
draw_train_process("training_loss/training_accs",iters,all_train_loss,all_train_accs) #绘制曲线
train_pass:0,batch_id:50,train_loss:[3.3754058],train_acc:[0.0546875]
train_pass:0,batch_id:100,train_loss:[3.7466354],train_acc:[0.3125]
train_pass:1,batch_id:50,train_loss:[1.7177842],train_acc:[0.7890625]
train_pass:1,batch_id:100,train_loss:[3.3241858],train_acc:[0.328125]
train_pass:2,batch_id:50,train_loss:[1.541421],train_acc:[0.7578125]
train_pass:2,batch_id:100,train_loss:[3.3498323],train_acc:[0.296875]
train_pass:3,batch_id:50,train_loss:[1.4854046],train_acc:[0.734375]
train_pass:3,batch_id:100,train_loss:[2.7453446],train_acc:[0.3984375]
train_pass:4,batch_id:50,train_loss:[1.3392676],train_acc:[0.7421875]
train_pass:4,batch_id:100,train_loss:[2.2698183],train_acc:[0.4921875]
train_pass:5,batch_id:50,train_loss:[1.0466999],train_acc:[0.8046875]
train_pass:5,batch_id:100,train_loss:[2.732211],train_acc:[0.4296875]
train_pass:6,batch_id:50,train_loss:[1.0767766],train_acc:[0.7734375]
train_pass:6,batch_id:100,train_loss:[2.185787],train_acc:[0.515625]
train_pass:7,batch_id:50,train_loss:[0.8253602],train_acc:[0.8046875]
train_pass:7,batch_id:100,train_loss:[1.7980326],train_acc:[0.5703125]
train_pass:8,batch_id:50,train_loss:[1.0483953],train_acc:[0.765625]
train_pass:8,batch_id:100,train_loss:[2.1938028],train_acc:[0.5]
train_pass:9,batch_id:50,train_loss:[0.87730736],train_acc:[0.7890625]
train_pass:9,batch_id:100,train_loss:[1.8081508],train_acc:[0.546875]
train_pass:10,batch_id:50,train_loss:[0.740126],train_acc:[0.828125]
train_pass:10,batch_id:100,train_loss:[1.8396097],train_acc:[0.5390625]
train_pass:11,batch_id:50,train_loss:[0.72519565],train_acc:[0.828125]
train_pass:11,batch_id:100,train_loss:[1.5033824],train_acc:[0.625]
train_pass:12,batch_id:50,train_loss:[0.6908928],train_acc:[0.8125]
train_pass:12,batch_id:100,train_loss:[1.5854897],train_acc:[0.6484375]
train_pass:13,batch_id:50,train_loss:[0.61654496],train_acc:[0.875]
train_pass:13,batch_id:100,train_loss:[1.668931],train_acc:[0.578125]
train_pass:14,batch_id:50,train_loss:[0.5948678],train_acc:[0.8828125]
train_pass:14,batch_id:100,train_loss:[1.7278676],train_acc:[0.6015625]
train_pass:15,batch_id:50,train_loss:[0.59903055],train_acc:[0.8828125]
train_pass:15,batch_id:100,train_loss:[1.6990802],train_acc:[0.5390625]
train_pass:16,batch_id:50,train_loss:[0.42459205],train_acc:[0.9296875]
train_pass:16,batch_id:100,train_loss:[1.4252222],train_acc:[0.609375]
train_pass:17,batch_id:50,train_loss:[0.61397314],train_acc:[0.8671875]
train_pass:17,batch_id:100,train_loss:[1.3090667],train_acc:[0.640625]
train_pass:18,batch_id:50,train_loss:[0.6825522],train_acc:[0.8671875]
train_pass:18,batch_id:100,train_loss:[1.1175399],train_acc:[0.703125]
train_pass:19,batch_id:50,train_loss:[0.5552777],train_acc:[0.890625]
train_pass:19,batch_id:100,train_loss:[1.0385547],train_acc:[0.703125]
train_pass:20,batch_id:50,train_loss:[0.6404925],train_acc:[0.8828125]
train_pass:20,batch_id:100,train_loss:[1.2776695],train_acc:[0.65625]
train_pass:21,batch_id:50,train_loss:[0.6192057],train_acc:[0.875]
train_pass:21,batch_id:100,train_loss:[1.0455577],train_acc:[0.7109375]
train_pass:22,batch_id:50,train_loss:[0.5881896],train_acc:[0.875]
train_pass:22,batch_id:100,train_loss:[0.94784504],train_acc:[0.71875]
train_pass:23,batch_id:50,train_loss:[0.39629042],train_acc:[0.9375]
train_pass:23,batch_id:100,train_loss:[0.89984596],train_acc:[0.734375]
train_pass:24,batch_id:50,train_loss:[0.3381021],train_acc:[0.921875]
train_pass:24,batch_id:100,train_loss:[0.7976736],train_acc:[0.7734375]
train_pass:25,batch_id:50,train_loss:[0.3570343],train_acc:[0.9453125]
train_pass:25,batch_id:100,train_loss:[0.8074259],train_acc:[0.8125]
train_pass:26,batch_id:50,train_loss:[0.42688298],train_acc:[0.921875]
train_pass:26,batch_id:100,train_loss:[0.84428596],train_acc:[0.7890625]
train_pass:27,batch_id:50,train_loss:[0.36116683],train_acc:[0.9296875]
train_pass:27,batch_id:100,train_loss:[0.76194763],train_acc:[0.7890625]
train_pass:28,batch_id:50,train_loss:[0.45201427],train_acc:[0.9375]
train_pass:28,batch_id:100,train_loss:[0.5687619],train_acc:[0.8671875]
train_pass:29,batch_id:50,train_loss:[0.32715696],train_acc:[0.921875]
train_pass:29,batch_id:100,train_loss:[0.8799591],train_acc:[0.7578125]
train_pass:30,batch_id:50,train_loss:[0.29492044],train_acc:[0.9453125]
train_pass:30,batch_id:100,train_loss:[0.6027407],train_acc:[0.84375]
train_pass:31,batch_id:50,train_loss:[0.30578583],train_acc:[0.921875]
train_pass:31,batch_id:100,train_loss:[0.7164497],train_acc:[0.7890625]
train_pass:32,batch_id:50,train_loss:[0.3315461],train_acc:[0.921875]
train_pass:32,batch_id:100,train_loss:[0.87599635],train_acc:[0.7578125]
train_pass:33,batch_id:50,train_loss:[0.28660756],train_acc:[0.9453125]
train_pass:33,batch_id:100,train_loss:[0.8077533],train_acc:[0.765625]
train_pass:34,batch_id:50,train_loss:[0.24150865],train_acc:[0.9453125]
train_pass:34,batch_id:100,train_loss:[0.84723336],train_acc:[0.765625]
train_pass:35,batch_id:50,train_loss:[0.26731044],train_acc:[0.9453125]
train_pass:35,batch_id:100,train_loss:[0.70550156],train_acc:[0.8046875]
train_pass:36,batch_id:50,train_loss:[0.2656216],train_acc:[0.9375]
train_pass:36,batch_id:100,train_loss:[0.56681186],train_acc:[0.84375]
train_pass:37,batch_id:50,train_loss:[0.3122633],train_acc:[0.953125]
train_pass:37,batch_id:100,train_loss:[0.7413306],train_acc:[0.796875]
train_pass:38,batch_id:50,train_loss:[0.23440786],train_acc:[0.9609375]
train_pass:38,batch_id:100,train_loss:[0.7030305],train_acc:[0.7890625]
train_pass:39,batch_id:50,train_loss:[0.3090566],train_acc:[0.9453125]
train_pass:39,batch_id:100,train_loss:[0.7924119],train_acc:[0.78125]
train_pass:40,batch_id:50,train_loss:[0.28477138],train_acc:[0.9375]
train_pass:40,batch_id:100,train_loss:[0.7294609],train_acc:[0.7890625]
train_pass:41,batch_id:50,train_loss:[0.38061565],train_acc:[0.90625]
train_pass:41,batch_id:100,train_loss:[0.6941439],train_acc:[0.828125]
train_pass:42,batch_id:50,train_loss:[0.18764797],train_acc:[0.953125]
train_pass:42,batch_id:100,train_loss:[0.68380743],train_acc:[0.8125]
train_pass:43,batch_id:50,train_loss:[0.16184251],train_acc:[0.9609375]
train_pass:43,batch_id:100,train_loss:[0.6035049],train_acc:[0.8515625]
train_pass:44,batch_id:50,train_loss:[0.16549093],train_acc:[0.9609375]
train_pass:44,batch_id:100,train_loss:[0.55046564],train_acc:[0.84375]
train_pass:45,batch_id:50,train_loss:[0.23923558],train_acc:[0.9375]
train_pass:45,batch_id:100,train_loss:[0.7040168],train_acc:[0.8046875]
train_pass:46,batch_id:50,train_loss:[0.2710197],train_acc:[0.9296875]
train_pass:46,batch_id:100,train_loss:[0.60378325],train_acc:[0.8125]
train_pass:47,batch_id:50,train_loss:[0.25476667],train_acc:[0.9609375]
train_pass:47,batch_id:100,train_loss:[0.39143887],train_acc:[0.9140625]
train_pass:48,batch_id:50,train_loss:[0.21921965],train_acc:[0.9609375]
train_pass:48,batch_id:100,train_loss:[0.614906],train_acc:[0.875]
train_pass:49,batch_id:50,train_loss:[0.31311822],train_acc:[0.9453125]
train_pass:49,batch_id:100,train_loss:[0.52768326],train_acc:[0.859375]
train_pass:50,batch_id:50,train_loss:[0.16349964],train_acc:[0.984375]
train_pass:50,batch_id:100,train_loss:[0.54804504],train_acc:[0.828125]
train_pass:51,batch_id:50,train_loss:[0.2330563],train_acc:[0.9453125]
train_pass:51,batch_id:100,train_loss:[0.5351713],train_acc:[0.859375]
train_pass:52,batch_id:50,train_loss:[0.14340752],train_acc:[0.96875]
train_pass:52,batch_id:100,train_loss:[0.5662944],train_acc:[0.859375]
train_pass:53,batch_id:50,train_loss:[0.27538946],train_acc:[0.953125]
train_pass:53,batch_id:100,train_loss:[0.39921778],train_acc:[0.921875]
train_pass:54,batch_id:50,train_loss:[0.24685206],train_acc:[0.9375]
train_pass:54,batch_id:100,train_loss:[0.39409313],train_acc:[0.90625]
train_pass:55,batch_id:50,train_loss:[0.21772203],train_acc:[0.9609375]
train_pass:55,batch_id:100,train_loss:[0.47592366],train_acc:[0.8515625]
train_pass:56,batch_id:50,train_loss:[0.2715933],train_acc:[0.9296875]
train_pass:56,batch_id:100,train_loss:[0.403986],train_acc:[0.921875]
train_pass:57,batch_id:50,train_loss:[0.283537],train_acc:[0.9375]
train_pass:57,batch_id:100,train_loss:[0.53993046],train_acc:[0.8671875]
train_pass:58,batch_id:50,train_loss:[0.14092702],train_acc:[0.9765625]
train_pass:58,batch_id:100,train_loss:[0.34076297],train_acc:[0.9296875]
train_pass:59,batch_id:50,train_loss:[0.2352842],train_acc:[0.953125]
train_pass:59,batch_id:100,train_loss:[0.4428507],train_acc:[0.8828125]
train_pass:60,batch_id:50,train_loss:[0.20739838],train_acc:[0.9453125]
train_pass:60,batch_id:100,train_loss:[0.3833328],train_acc:[0.921875]
train_pass:61,batch_id:50,train_loss:[0.16301377],train_acc:[0.9609375]
train_pass:61,batch_id:100,train_loss:[0.32726508],train_acc:[0.8984375]
train_pass:62,batch_id:50,train_loss:[0.11913799],train_acc:[0.984375]
train_pass:62,batch_id:100,train_loss:[0.368622],train_acc:[0.8984375]
train_pass:63,batch_id:50,train_loss:[0.17862579],train_acc:[0.953125]
train_pass:63,batch_id:100,train_loss:[0.43400204],train_acc:[0.8984375]
train_pass:64,batch_id:50,train_loss:[0.27143943],train_acc:[0.9375]
train_pass:64,batch_id:100,train_loss:[0.40828502],train_acc:[0.8984375]
train_pass:65,batch_id:50,train_loss:[0.08883287],train_acc:[0.9765625]
train_pass:65,batch_id:100,train_loss:[0.2786835],train_acc:[0.921875]
train_pass:66,batch_id:50,train_loss:[0.17707968],train_acc:[0.953125]
train_pass:66,batch_id:100,train_loss:[0.4611581],train_acc:[0.8828125]
train_pass:67,batch_id:50,train_loss:[0.20550081],train_acc:[0.9453125]
train_pass:67,batch_id:100,train_loss:[0.3534715],train_acc:[0.9140625]
train_pass:68,batch_id:50,train_loss:[0.2488931],train_acc:[0.9453125]
train_pass:68,batch_id:100,train_loss:[0.40300387],train_acc:[0.90625]
train_pass:69,batch_id:50,train_loss:[0.2515007],train_acc:[0.953125]
train_pass:69,batch_id:100,train_loss:[0.42873937],train_acc:[0.8828125]
train_pass:70,batch_id:50,train_loss:[0.2189034],train_acc:[0.953125]
train_pass:70,batch_id:100,train_loss:[0.49259496],train_acc:[0.8828125]
train_pass:71,batch_id:50,train_loss:[0.16997628],train_acc:[0.953125]
train_pass:71,batch_id:100,train_loss:[0.37786767],train_acc:[0.9296875]
train_pass:72,batch_id:50,train_loss:[0.19404763],train_acc:[0.96875]
train_pass:72,batch_id:100,train_loss:[0.42319393],train_acc:[0.875]
train_pass:73,batch_id:50,train_loss:[0.20615016],train_acc:[0.953125]
train_pass:73,batch_id:100,train_loss:[0.31426775],train_acc:[0.9140625]
train_pass:74,batch_id:50,train_loss:[0.1496422],train_acc:[0.9765625]
train_pass:74,batch_id:100,train_loss:[0.29980174],train_acc:[0.9453125]
train_pass:75,batch_id:50,train_loss:[0.1562323],train_acc:[0.96875]
train_pass:75,batch_id:100,train_loss:[0.3054116],train_acc:[0.921875]
train_pass:76,batch_id:50,train_loss:[0.17253916],train_acc:[0.96875]
train_pass:76,batch_id:100,train_loss:[0.29974627],train_acc:[0.9296875]
train_pass:77,batch_id:50,train_loss:[0.15353644],train_acc:[0.9765625]
train_pass:77,batch_id:100,train_loss:[0.32281944],train_acc:[0.921875]
train_pass:78,batch_id:50,train_loss:[0.17583515],train_acc:[0.96875]
train_pass:78,batch_id:100,train_loss:[0.31548357],train_acc:[0.9375]
train_pass:79,batch_id:50,train_loss:[0.12505893],train_acc:[0.9765625]
train_pass:79,batch_id:100,train_loss:[0.37649548],train_acc:[0.90625]
train_pass:80,batch_id:50,train_loss:[0.17754388],train_acc:[0.9609375]
train_pass:80,batch_id:100,train_loss:[0.27260414],train_acc:[0.9296875]
train_pass:81,batch_id:50,train_loss:[0.12059503],train_acc:[0.9921875]
train_pass:81,batch_id:100,train_loss:[0.29170412],train_acc:[0.9375]
train_pass:82,batch_id:50,train_loss:[0.20721275],train_acc:[0.9609375]
train_pass:82,batch_id:100,train_loss:[0.33104768],train_acc:[0.921875]
train_pass:83,batch_id:50,train_loss:[0.1416049],train_acc:[0.9609375]
train_pass:83,batch_id:100,train_loss:[0.3134958],train_acc:[0.921875]
train_pass:84,batch_id:50,train_loss:[0.08927596],train_acc:[0.9921875]
train_pass:84,batch_id:100,train_loss:[0.31979546],train_acc:[0.9140625]
train_pass:85,batch_id:50,train_loss:[0.13476367],train_acc:[0.9765625]
train_pass:85,batch_id:100,train_loss:[0.28085268],train_acc:[0.9296875]
train_pass:86,batch_id:50,train_loss:[0.17450145],train_acc:[0.96875]
train_pass:86,batch_id:100,train_loss:[0.3583657],train_acc:[0.90625]
train_pass:87,batch_id:50,train_loss:[0.17817146],train_acc:[0.9609375]
train_pass:87,batch_id:100,train_loss:[0.25172645],train_acc:[0.9375]
train_pass:88,batch_id:50,train_loss:[0.14498395],train_acc:[0.96875]
train_pass:88,batch_id:100,train_loss:[0.45874646],train_acc:[0.8984375]
train_pass:89,batch_id:50,train_loss:[0.10505957],train_acc:[0.9921875]
train_pass:89,batch_id:100,train_loss:[0.2519515],train_acc:[0.9375]
train_pass:90,batch_id:50,train_loss:[0.15261132],train_acc:[0.9765625]
train_pass:90,batch_id:100,train_loss:[0.24966618],train_acc:[0.9296875]
train_pass:91,batch_id:50,train_loss:[0.13288249],train_acc:[0.984375]
train_pass:91,batch_id:100,train_loss:[0.2937683],train_acc:[0.9375]
train_pass:92,batch_id:50,train_loss:[0.16128887],train_acc:[0.96875]
train_pass:92,batch_id:100,train_loss:[0.206138],train_acc:[0.953125]
train_pass:93,batch_id:50,train_loss:[0.07673344],train_acc:[0.9921875]
train_pass:93,batch_id:100,train_loss:[0.28015545],train_acc:[0.9609375]
train_pass:94,batch_id:50,train_loss:[0.12932862],train_acc:[0.96875]
train_pass:94,batch_id:100,train_loss:[0.18601523],train_acc:[0.953125]
train_pass:95,batch_id:50,train_loss:[0.07720471],train_acc:[0.984375]
train_pass:95,batch_id:100,train_loss:[0.15957427],train_acc:[0.9765625]
train_pass:96,batch_id:50,train_loss:[0.16657299],train_acc:[0.9609375]
train_pass:96,batch_id:100,train_loss:[0.23382592],train_acc:[0.953125]
train_pass:97,batch_id:50,train_loss:[0.11316375],train_acc:[0.984375]
train_pass:97,batch_id:100,train_loss:[0.28282773],train_acc:[0.9453125]
train_pass:98,batch_id:50,train_loss:[0.17227583],train_acc:[0.953125]
train_pass:98,batch_id:100,train_loss:[0.18531394],train_acc:[0.9609375]
train_pass:99,batch_id:50,train_loss:[0.09672622],train_acc:[0.9765625]
train_pass:99,batch_id:100,train_loss:[0.30552906],train_acc:[0.9140625]
train_pass:100,batch_id:50,train_loss:[0.08395993],train_acc:[0.984375]
train_pass:100,batch_id:100,train_loss:[0.26352835],train_acc:[0.953125]
train_pass:101,batch_id:50,train_loss:[0.11662146],train_acc:[0.9765625]
train_pass:101,batch_id:100,train_loss:[0.2231214],train_acc:[0.953125]
train_pass:102,batch_id:50,train_loss:[0.10610975],train_acc:[0.9765625]
train_pass:102,batch_id:100,train_loss:[0.21361034],train_acc:[0.953125]
train_pass:103,batch_id:50,train_loss:[0.10999744],train_acc:[0.9765625]
train_pass:103,batch_id:100,train_loss:[0.11534272],train_acc:[0.9921875]
train_pass:104,batch_id:50,train_loss:[0.15831684],train_acc:[0.96875]
train_pass:104,batch_id:100,train_loss:[0.16843115],train_acc:[0.96875]
train_pass:105,batch_id:50,train_loss:[0.11157791],train_acc:[0.9765625]
train_pass:105,batch_id:100,train_loss:[0.22167917],train_acc:[0.9453125]
train_pass:106,batch_id:50,train_loss:[0.07119508],train_acc:[0.9921875]
train_pass:106,batch_id:100,train_loss:[0.22880293],train_acc:[0.9453125]
train_pass:107,batch_id:50,train_loss:[0.10787214],train_acc:[0.96875]
train_pass:107,batch_id:100,train_loss:[0.18812567],train_acc:[0.9765625]
train_pass:108,batch_id:50,train_loss:[0.15858299],train_acc:[0.9609375]
train_pass:108,batch_id:100,train_loss:[0.251326],train_acc:[0.9453125]
train_pass:109,batch_id:50,train_loss:[0.13534705],train_acc:[0.9609375]
train_pass:109,batch_id:100,train_loss:[0.19716421],train_acc:[0.953125]
train_pass:110,batch_id:50,train_loss:[0.15279733],train_acc:[0.9609375]
train_pass:110,batch_id:100,train_loss:[0.19036102],train_acc:[0.9609375]
train_pass:111,batch_id:50,train_loss:[0.10238361],train_acc:[0.984375]
train_pass:111,batch_id:100,train_loss:[0.25333345],train_acc:[0.953125]
train_pass:112,batch_id:50,train_loss:[0.06372672],train_acc:[0.9921875]
train_pass:112,batch_id:100,train_loss:[0.22503015],train_acc:[0.9375]
train_pass:113,batch_id:50,train_loss:[0.10411843],train_acc:[0.9609375]
train_pass:113,batch_id:100,train_loss:[0.23744003],train_acc:[0.9453125]
train_pass:114,batch_id:50,train_loss:[0.13199314],train_acc:[0.9609375]
train_pass:114,batch_id:100,train_loss:[0.19525388],train_acc:[0.9765625]
train_pass:115,batch_id:50,train_loss:[0.10202225],train_acc:[0.96875]
train_pass:115,batch_id:100,train_loss:[0.16648135],train_acc:[0.9609375]
train_pass:116,batch_id:50,train_loss:[0.10757859],train_acc:[0.96875]
train_pass:116,batch_id:100,train_loss:[0.15302385],train_acc:[0.96875]
train_pass:117,batch_id:50,train_loss:[0.05688838],train_acc:[0.9921875]
train_pass:117,batch_id:100,train_loss:[0.17802447],train_acc:[0.9765625]
train_pass:118,batch_id:50,train_loss:[0.06681572],train_acc:[0.9921875]
train_pass:118,batch_id:100,train_loss:[0.21044157],train_acc:[0.9609375]
train_pass:119,batch_id:50,train_loss:[0.08083697],train_acc:[0.984375]
train_pass:119,batch_id:100,train_loss:[0.1553054],train_acc:[0.96875]
train_pass:120,batch_id:50,train_loss:[0.0950775],train_acc:[0.984375]
train_pass:120,batch_id:100,train_loss:[0.15724163],train_acc:[0.984375]
train_pass:121,batch_id:50,train_loss:[0.06979245],train_acc:[0.984375]
train_pass:121,batch_id:100,train_loss:[0.22420907],train_acc:[0.9375]
train_pass:122,batch_id:50,train_loss:[0.11862667],train_acc:[0.984375]
train_pass:122,batch_id:100,train_loss:[0.1824899],train_acc:[0.9765625]
train_pass:123,batch_id:50,train_loss:[0.10106032],train_acc:[0.984375]
train_pass:123,batch_id:100,train_loss:[0.17506209],train_acc:[0.96875]
train_pass:124,batch_id:50,train_loss:[0.06986073],train_acc:[0.9921875]
train_pass:124,batch_id:100,train_loss:[0.12728909],train_acc:[0.984375]
train_pass:125,batch_id:50,train_loss:[0.12744856],train_acc:[0.9765625]
train_pass:125,batch_id:100,train_loss:[0.16052121],train_acc:[0.96875]
train_pass:126,batch_id:50,train_loss:[0.09416071],train_acc:[0.9765625]
train_pass:126,batch_id:100,train_loss:[0.15485269],train_acc:[0.984375]
train_pass:127,batch_id:50,train_loss:[0.05770614],train_acc:[1.]
train_pass:127,batch_id:100,train_loss:[0.16278875],train_acc:[0.96875]
train_pass:128,batch_id:50,train_loss:[0.06604033],train_acc:[0.9921875]
train_pass:128,batch_id:100,train_loss:[0.18395561],train_acc:[0.953125]
train_pass:129,batch_id:50,train_loss:[0.11372809],train_acc:[0.984375]
train_pass:129,batch_id:100,train_loss:[0.18827137],train_acc:[0.953125]
train_pass:130,batch_id:50,train_loss:[0.14008027],train_acc:[0.984375]
train_pass:130,batch_id:100,train_loss:[0.17116944],train_acc:[0.953125]
train_pass:131,batch_id:50,train_loss:[0.03375934],train_acc:[1.]
train_pass:131,batch_id:100,train_loss:[0.17074403],train_acc:[0.96875]
train_pass:132,batch_id:50,train_loss:[0.09432756],train_acc:[0.9765625]
train_pass:132,batch_id:100,train_loss:[0.1406341],train_acc:[0.984375]
train_pass:133,batch_id:50,train_loss:[0.06548487],train_acc:[1.]
train_pass:133,batch_id:100,train_loss:[0.17203578],train_acc:[0.9609375]
train_pass:134,batch_id:50,train_loss:[0.04656129],train_acc:[1.]
train_pass:134,batch_id:100,train_loss:[0.13726953],train_acc:[0.96875]
train_pass:135,batch_id:50,train_loss:[0.07859913],train_acc:[0.984375]
train_pass:135,batch_id:100,train_loss:[0.26488024],train_acc:[0.9296875]
train_pass:136,batch_id:50,train_loss:[0.06347495],train_acc:[0.9921875]
train_pass:136,batch_id:100,train_loss:[0.09135195],train_acc:[0.9765625]
train_pass:137,batch_id:50,train_loss:[0.04575176],train_acc:[1.]
train_pass:137,batch_id:100,train_loss:[0.20261616],train_acc:[0.953125]
train_pass:138,batch_id:50,train_loss:[0.08050522],train_acc:[0.9921875]
train_pass:138,batch_id:100,train_loss:[0.15688586],train_acc:[0.9765625]
train_pass:139,batch_id:50,train_loss:[0.09624804],train_acc:[0.984375]
train_pass:139,batch_id:100,train_loss:[0.13453253],train_acc:[0.96875]
train_pass:140,batch_id:50,train_loss:[0.06726089],train_acc:[0.9921875]
train_pass:140,batch_id:100,train_loss:[0.17761868],train_acc:[0.953125]
train_pass:141,batch_id:50,train_loss:[0.06664023],train_acc:[0.9921875]
train_pass:141,batch_id:100,train_loss:[0.18851143],train_acc:[0.9453125]
train_pass:142,batch_id:50,train_loss:[0.07290477],train_acc:[0.984375]
train_pass:142,batch_id:100,train_loss:[0.19879211],train_acc:[0.9375]
train_pass:143,batch_id:50,train_loss:[0.0653451],train_acc:[0.9921875]
train_pass:143,batch_id:100,train_loss:[0.13977729],train_acc:[0.96875]
train_pass:144,batch_id:50,train_loss:[0.06490891],train_acc:[0.9921875]
train_pass:144,batch_id:100,train_loss:[0.11657418],train_acc:[0.9765625]
train_pass:145,batch_id:50,train_loss:[0.05173156],train_acc:[1.]
train_pass:145,batch_id:100,train_loss:[0.15238747],train_acc:[0.96875]
train_pass:146,batch_id:50,train_loss:[0.04705027],train_acc:[0.9921875]
train_pass:146,batch_id:100,train_loss:[0.1657183],train_acc:[0.96875]
train_pass:147,batch_id:50,train_loss:[0.09233879],train_acc:[0.9765625]
train_pass:147,batch_id:100,train_loss:[0.11532735],train_acc:[0.9765625]
train_pass:148,batch_id:50,train_loss:[0.09610069],train_acc:[0.984375]
train_pass:148,batch_id:100,train_loss:[0.15216485],train_acc:[0.9609375]
train_pass:149,batch_id:50,train_loss:[0.1064433],train_acc:[0.9765625]
train_pass:149,batch_id:100,train_loss:[0.09701582],train_acc:[0.9765625]
train_pass:150,batch_id:50,train_loss:[0.08914109],train_acc:[0.984375]
train_pass:150,batch_id:100,train_loss:[0.13091019],train_acc:[0.9765625]
train_pass:151,batch_id:50,train_loss:[0.06567472],train_acc:[0.9921875]
train_pass:151,batch_id:100,train_loss:[0.1739328],train_acc:[0.96875]
train_pass:152,batch_id:50,train_loss:[0.08069877],train_acc:[0.984375]
train_pass:152,batch_id:100,train_loss:[0.10797305],train_acc:[0.96875]
train_pass:153,batch_id:50,train_loss:[0.04346751],train_acc:[0.9921875]
train_pass:153,batch_id:100,train_loss:[0.10588723],train_acc:[0.984375]
train_pass:154,batch_id:50,train_loss:[0.0613597],train_acc:[1.]
train_pass:154,batch_id:100,train_loss:[0.11337911],train_acc:[0.9765625]
train_pass:155,batch_id:50,train_loss:[0.06798866],train_acc:[0.9921875]
train_pass:155,batch_id:100,train_loss:[0.15141894],train_acc:[0.9609375]
train_pass:156,batch_id:50,train_loss:[0.06180099],train_acc:[1.]
train_pass:156,batch_id:100,train_loss:[0.12399013],train_acc:[0.984375]
train_pass:157,batch_id:50,train_loss:[0.04991179],train_acc:[0.9921875]
train_pass:157,batch_id:100,train_loss:[0.1096242],train_acc:[0.9921875]
train_pass:158,batch_id:50,train_loss:[0.05412419],train_acc:[0.9921875]
train_pass:158,batch_id:100,train_loss:[0.06701832],train_acc:[1.]
train_pass:159,batch_id:50,train_loss:[0.07638965],train_acc:[0.9921875]
train_pass:159,batch_id:100,train_loss:[0.08521272],train_acc:[0.9921875]
train_pass:160,batch_id:50,train_loss:[0.04654051],train_acc:[0.9921875]
train_pass:160,batch_id:100,train_loss:[0.13866688],train_acc:[0.984375]
train_pass:161,batch_id:50,train_loss:[0.05971061],train_acc:[0.984375]
train_pass:161,batch_id:100,train_loss:[0.12311228],train_acc:[0.9765625]
train_pass:162,batch_id:50,train_loss:[0.06772259],train_acc:[0.9921875]
train_pass:162,batch_id:100,train_loss:[0.14412442],train_acc:[0.984375]
train_pass:163,batch_id:50,train_loss:[0.04340161],train_acc:[1.]
train_pass:163,batch_id:100,train_loss:[0.0963496],train_acc:[0.9765625]
train_pass:164,batch_id:50,train_loss:[0.08197833],train_acc:[0.984375]
train_pass:164,batch_id:100,train_loss:[0.0930468],train_acc:[0.984375]
train_pass:165,batch_id:50,train_loss:[0.04039185],train_acc:[1.]
train_pass:165,batch_id:100,train_loss:[0.17944962],train_acc:[0.9609375]
train_pass:166,batch_id:50,train_loss:[0.05175571],train_acc:[0.9921875]
train_pass:166,batch_id:100,train_loss:[0.11720324],train_acc:[0.96875]
train_pass:167,batch_id:50,train_loss:[0.03519915],train_acc:[1.]
train_pass:167,batch_id:100,train_loss:[0.11005215],train_acc:[0.96875]
train_pass:168,batch_id:50,train_loss:[0.04607752],train_acc:[1.]
train_pass:168,batch_id:100,train_loss:[0.12375072],train_acc:[0.984375]
train_pass:169,batch_id:50,train_loss:[0.07095367],train_acc:[0.984375]
train_pass:169,batch_id:100,train_loss:[0.13741219],train_acc:[0.96875]
train_pass:170,batch_id:50,train_loss:[0.07138836],train_acc:[0.984375]
train_pass:170,batch_id:100,train_loss:[0.13749741],train_acc:[0.9609375]
train_pass:171,batch_id:50,train_loss:[0.06431117],train_acc:[0.9921875]
train_pass:171,batch_id:100,train_loss:[0.12443647],train_acc:[0.96875]
train_pass:172,batch_id:50,train_loss:[0.04086059],train_acc:[0.9921875]
train_pass:172,batch_id:100,train_loss:[0.10318123],train_acc:[0.9921875]
train_pass:173,batch_id:50,train_loss:[0.07122955],train_acc:[0.984375]
train_pass:173,batch_id:100,train_loss:[0.10401386],train_acc:[0.984375]
train_pass:174,batch_id:50,train_loss:[0.05009491],train_acc:[0.9921875]
train_pass:174,batch_id:100,train_loss:[0.15115623],train_acc:[0.96875]
train_pass:175,batch_id:50,train_loss:[0.03893668],train_acc:[1.]
train_pass:175,batch_id:100,train_loss:[0.12550813],train_acc:[0.9765625]
train_pass:176,batch_id:50,train_loss:[0.0717012],train_acc:[0.984375]
train_pass:176,batch_id:100,train_loss:[0.09846343],train_acc:[0.984375]
train_pass:177,batch_id:50,train_loss:[0.06575071],train_acc:[0.984375]
train_pass:177,batch_id:100,train_loss:[0.13192566],train_acc:[0.9765625]
train_pass:178,batch_id:50,train_loss:[0.02761446],train_acc:[1.]
train_pass:178,batch_id:100,train_loss:[0.10303407],train_acc:[0.9765625]
train_pass:179,batch_id:50,train_loss:[0.0583081],train_acc:[0.9921875]
train_pass:179,batch_id:100,train_loss:[0.09058276],train_acc:[0.9765625]
train_pass:180,batch_id:50,train_loss:[0.03952338],train_acc:[1.]
train_pass:180,batch_id:100,train_loss:[0.11566595],train_acc:[0.984375]
train_pass:181,batch_id:50,train_loss:[0.05403819],train_acc:[0.9921875]
train_pass:181,batch_id:100,train_loss:[0.15542471],train_acc:[0.96875]
train_pass:182,batch_id:50,train_loss:[0.03826994],train_acc:[1.]
train_pass:182,batch_id:100,train_loss:[0.14180422],train_acc:[0.96875]
train_pass:183,batch_id:50,train_loss:[0.03369839],train_acc:[1.]
train_pass:183,batch_id:100,train_loss:[0.06348802],train_acc:[1.]
train_pass:184,batch_id:50,train_loss:[0.02670265],train_acc:[1.]
train_pass:184,batch_id:100,train_loss:[0.05288633],train_acc:[1.]
train_pass:185,batch_id:50,train_loss:[0.04880817],train_acc:[0.9921875]
train_pass:185,batch_id:100,train_loss:[0.10053197],train_acc:[0.984375]
train_pass:186,batch_id:50,train_loss:[0.03704396],train_acc:[0.9921875]
train_pass:186,batch_id:100,train_loss:[0.08278318],train_acc:[1.]
train_pass:187,batch_id:50,train_loss:[0.04937952],train_acc:[1.]
train_pass:187,batch_id:100,train_loss:[0.14750439],train_acc:[0.96875]
train_pass:188,batch_id:50,train_loss:[0.05192464],train_acc:[0.9921875]
train_pass:188,batch_id:100,train_loss:[0.10958528],train_acc:[0.984375]
train_pass:189,batch_id:50,train_loss:[0.05124691],train_acc:[0.9921875]
train_pass:189,batch_id:100,train_loss:[0.09557712],train_acc:[0.9765625]
train_pass:190,batch_id:50,train_loss:[0.0403769],train_acc:[1.]
train_pass:190,batch_id:100,train_loss:[0.10443345],train_acc:[0.984375]
train_pass:191,batch_id:50,train_loss:[0.06767876],train_acc:[0.984375]
train_pass:191,batch_id:100,train_loss:[0.12424259],train_acc:[0.96875]
train_pass:192,batch_id:50,train_loss:[0.05626993],train_acc:[0.984375]
train_pass:192,batch_id:100,train_loss:[0.0816459],train_acc:[0.9921875]
train_pass:193,batch_id:50,train_loss:[0.03620303],train_acc:[0.9921875]
train_pass:193,batch_id:100,train_loss:[0.05804433],train_acc:[0.9921875]
train_pass:194,batch_id:50,train_loss:[0.03046268],train_acc:[1.]
train_pass:194,batch_id:100,train_loss:[0.05754005],train_acc:[0.9921875]
train_pass:195,batch_id:50,train_loss:[0.04335988],train_acc:[0.9921875]
train_pass:195,batch_id:100,train_loss:[0.11355679],train_acc:[0.9921875]
train_pass:196,batch_id:50,train_loss:[0.03198247],train_acc:[1.]
train_pass:196,batch_id:100,train_loss:[0.08329818],train_acc:[1.]
train_pass:197,batch_id:50,train_loss:[0.04527798],train_acc:[0.9921875]
train_pass:197,batch_id:100,train_loss:[0.10566716],train_acc:[0.9765625]
train_pass:198,batch_id:50,train_loss:[0.0458477],train_acc:[0.9921875]
train_pass:198,batch_id:100,train_loss:[0.1110507],train_acc:[0.9921875]
train_pass:199,batch_id:50,train_loss:[0.04464588],train_acc:[0.984375]
train_pass:199,batch_id:100,train_loss:[0.08060548],train_acc:[1.]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-NM3W1fup-1586355963536)(output_9_1.png)]
#模型校验
with fluid.dygraph.guard():
accs = []
model=MyLeNet()#模型实例化
model_dict,_=fluid.load_dygraph('MyLeNet')
model.load_dict(model_dict)#加载模型参数
model.eval()#评估模式
for batch_id,data in enumerate(test_reader()):#测试集
images=np.array([x[0].reshape(1,20,20) for x in data],np.float32)
labels = np.array([x[1] for x in data]).astype('int64')
labels = labels[:, np.newaxis]
image=fluid.dygraph.to_variable(images)
label=fluid.dygraph.to_variable(labels)
predict=model(image)#预测
acc=fluid.layers.accuracy(predict,label)
accs.append(acc.numpy()[0])
avg_acc = np.mean(accs)
print(avg_acc)
0.96331376
# 对车牌图片进行处理,分割出车牌中的每一个字符并保存
license_plate2 = cv2.imread('./车牌1.png')
#print('Original Dimensions : ',license_plate.shape)
#license_plate2 = cv2.imread('./车牌1.png')
#print('Original Dimensions2 : ',license_plate2.shape)
license_plate2 = cv2.resize(license_plate2, (722,170), interpolation = cv2.INTER_CUBIC)
#print('resized Dimensions : ',license_plate2.shape)
#gray_plate2 = cv2.cvtColor(license_plate2, cv2.COLOR_RGB2GRAY)
gray_plate = cv2.cvtColor(license_plate2, cv2.COLOR_RGB2GRAY)
ret, binary_plate = cv2.threshold(gray_plate, 175, 255, cv2.THRESH_BINARY)
print(ret, binary_plate)
result = []
for col in range(binary_plate.shape[1]):
result.append(0)
for row in range(binary_plate.shape[0]):
result[col] = result[col] + binary_plate[row][col]/255
character_dict = {}
num = 0
i = 0
while i < len(result):
if result[i] == 0:
i += 1
else:
index = i + 1
while result[index] != 0:
index += 1
character_dict[num] = [i, index-1]
num += 1
i = index
for i in range(8):
if i==2:
continue
padding = (170 - (character_dict[i][1] - character_dict[i][0])) / 2
ndarray = np.pad(binary_plate[:,character_dict[i][0]:character_dict[i][1]], ((0,0), (int(padding), int(padding))), 'constant', constant_values=(0,0))
ndarray = cv2.resize(ndarray, (20,20))
cv2.imwrite('./' + str(i) + '.png', ndarray)
def load_image(path):
img = paddle.dataset.image.load_image(file=path, is_color=False)
img = img.astype('float32')
img = img[np.newaxis, ] / 255.0
return img
175.0 [[0 0 0 ... 0 0 0]
[0 0 0 ... 0 0 0]
[0 0 0 ... 0 0 0]
...
[0 0 0 ... 0 0 0]
[0 0 0 ... 0 0 0]
[0 0 0 ... 0 0 0]]
#将标签进行转换
print('Label:',LABEL_temp)
match = {'A':'A','B':'B','C':'C','D':'D','E':'E','F':'F','G':'G','H':'H','I':'I','J':'J','K':'K','L':'L','M':'M','N':'N',
'O':'O','P':'P','Q':'Q','R':'R','S':'S','T':'T','U':'U','V':'V','W':'W','X':'X','Y':'Y','Z':'Z',
'yun':'云','cuan':'川','hei':'黑','zhe':'浙','ning':'宁','jin':'津','gan':'赣','hu':'沪','liao':'辽','jl':'吉','qing':'青','zang':'藏',
'e1':'鄂','meng':'蒙','gan1':'甘','qiong':'琼','shan':'陕','min':'闽','su':'苏','xin':'新','wan':'皖','jing':'京','xiang':'湘','gui':'贵',
'yu1':'渝','yu':'豫','ji':'冀','yue':'粤','gui1':'桂','sx':'晋','lu':'鲁',
'0':'0','1':'1','2':'2','3':'3','4':'4','5':'5','6':'6','7':'7','8':'8','9':'9'}
L = 0
LABEL ={}
for V in LABEL_temp.values():
LABEL[str(L)] = match[V]
L += 1
print(LABEL)
Label: {'0': 'zhe', '1': 'W', '2': 'D', '3': 'liao', '4': 'X', '5': '3', '6': 'T', '7': 'K', '8': 'V', '9': 'yu1', '10': '5', '11': 'jl', '12': 'gui1', '13': 'Z', '14': '8', '15': 'jing', '16': 'su', '17': 'Q', '18': 'xin', '19': 'G', '20': '1', '21': 'gan', '22': 'hei', '23': 'zang', '24': 'cuan', '25': 'H', '26': '7', '27': 'yue', '28': 'M', '29': 'gan1', '30': 'yun', '31': 'wan', '32': 'min', '33': 'yu', '34': 'L', '35': 'gui', '36': 'J', '37': '6', '38': 'N', '39': 'xiang', '40': '0', '41': 'lu', '42': 'sx', '43': '4', '44': 'jin', '45': 'S', '46': 'U', '47': 'Y', '48': '9', '49': 'F', '50': 'C', '51': 'E', '52': '2', '53': 'R', '54': 'e1', '55': 'B', '56': 'meng', '57': 'shan', '58': 'ji', '59': 'qing', '60': 'A', '61': 'P', '62': 'ning', '63': 'qiong', '64': 'hu'}
{'0': '浙', '1': 'W', '2': 'D', '3': '辽', '4': 'X', '5': '3', '6': 'T', '7': 'K', '8': 'V', '9': '渝', '10': '5', '11': '吉', '12': '桂', '13': 'Z', '14': '8', '15': '京', '16': '苏', '17': 'Q', '18': '新', '19': 'G', '20': '1', '21': '赣', '22': '黑', '23': '藏', '24': '川', '25': 'H', '26': '7', '27': '粤', '28': 'M', '29': '甘', '30': '云', '31': '皖', '32': '闽', '33': '豫', '34': 'L', '35': '贵', '36': 'J', '37': '6', '38': 'N', '39': '湘', '40': '0', '41': '鲁', '42': '晋', '43': '4', '44': '津', '45': 'S', '46': 'U', '47': 'Y', '48': '9', '49': 'F', '50': 'C', '51': 'E', '52': '2', '53': 'R', '54': '鄂', '55': 'B', '56': '蒙', '57': '陕', '58': '冀', '59': '青', '60': 'A', '61': 'P', '62': '宁', '63': '琼', '64': '沪'}
#构建预测动态图过程
with fluid.dygraph.guard():
model=MyLeNet()#模型实例化
model_dict,_=fluid.load_dygraph('MyLeNet')
model.load_dict(model_dict)#加载模型参数
model.eval()#评估模式
lab=[]
for i in range(8):
if i==2:
continue
infer_imgs = []
infer_imgs.append(load_image('./' + str(i) + '.png'))
infer_imgs = np.array(infer_imgs)
infer_imgs = fluid.dygraph.to_variable(infer_imgs)
result=model(infer_imgs)
lab.append(np.argmax(result.numpy()))
# print(lab)
display(Image.open('./车牌1.png'))
print('\n车牌识别结果为:',end='')
for i in range(len(lab)):
print(LABEL[str(lab[i])],end='')
车牌识别结果为:鄂JE7C76
请点击此处查看本环境基本用法.
Please click here for more detailed instructions.
更多请参考: