forked from TianyouChen/HyperLPR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypeDistinguish.py
56 lines (45 loc) · 1.66 KB
/
typeDistinguish.py
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#coding=utf-8
from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation, Flatten
from keras.layers import Conv2D, MaxPool2D
from keras.optimizers import SGD
from keras import backend as K
K.image_data_format()
import cv2
import numpy as np
plateType = ["蓝牌","单层黄牌","新能源车牌","白色","黑色-港澳"]
def Getmodel_tensorflow(nb_classes):
# nb_classes = len(charset)
img_rows, img_cols = 9, 34
# number of convolutional filters to use
nb_filters = 32
# size of pooling area for max pooling
nb_pool = 2
# convolution kernel size
nb_conv = 3
# x = np.load('x.npy')
# y = np_utils.to_categorical(range(3062)*45*5*2, nb_classes)
# weight = ((type_class - np.arange(type_class)) / type_class + 1) ** 3
# weight = dict(zip(range(3063), weight / weight.mean())) # 调整权重,高频字优先
model = Sequential()
model.add(Conv2D(16, (5, 5),input_shape=(img_rows, img_cols,3)))
model.add(Activation('relu'))
model.add(MaxPool2D(pool_size=(nb_pool, nb_pool)))
model.add(Flatten())
model.add(Dense(64))
model.add(Activation('relu'))
model.add(Dropout(0.5))
model.add(Dense(nb_classes))
model.add(Activation('softmax'))
model.compile(loss='categorical_crossentropy',
optimizer='adam',
metrics=['accuracy'])
return model
model = Getmodel_tensorflow(5)
model.load_weights("./model/plate_type.h5")
model.save("./model/plate_type.h5")
def SimplePredict(image):
image = cv2.resize(image, (34, 9))
image = image.astype(np.float) / 255
res = np.array(model.predict(np.array([image]))[0])
return res.argmax()