You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

typeDistinguish.py 1.7 kB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #coding=utf-8
  2. from keras.models import Sequential
  3. from keras.layers import Dense, Dropout, Activation, Flatten
  4. from keras.layers import Conv2D, MaxPool2D
  5. from keras.optimizers import SGD
  6. from keras import backend as K
  7. K.image_data_format()
  8. import cv2
  9. import numpy as np
  10. plateType = [u"蓝牌",u"单层黄牌",u"新能源车牌",u"白色",u"黑色-港澳"]
  11. def Getmodel_tensorflow(nb_classes):
  12. # nb_classes = len(charset)
  13. img_rows, img_cols = 9, 34
  14. # number of convolutional filters to use
  15. nb_filters = 32
  16. # size of pooling area for max pooling
  17. nb_pool = 2
  18. # convolution kernel size
  19. nb_conv = 3
  20. # x = np.load('x.npy')
  21. # y = np_utils.to_categorical(range(3062)*45*5*2, nb_classes)
  22. # weight = ((type_class - np.arange(type_class)) / type_class + 1) ** 3
  23. # weight = dict(zip(range(3063), weight / weight.mean())) # 调整权重,高频字优先
  24. model = Sequential()
  25. model.add(Conv2D(16, (5, 5),input_shape=(img_rows, img_cols,3)))
  26. model.add(Activation('relu'))
  27. model.add(MaxPool2D(pool_size=(nb_pool, nb_pool)))
  28. model.add(Flatten())
  29. model.add(Dense(64))
  30. model.add(Activation('relu'))
  31. model.add(Dropout(0.5))
  32. model.add(Dense(nb_classes))
  33. model.add(Activation('softmax'))
  34. model.compile(loss='categorical_crossentropy',
  35. optimizer='adam',
  36. metrics=['accuracy'])
  37. return model
  38. model = Getmodel_tensorflow(5)
  39. model.load_weights("./model/plate_type.h5")
  40. model.save("./model/plate_type.h5")
  41. def SimplePredict(image):
  42. image = cv2.resize(image, (34, 9))
  43. image = image.astype(np.float) / 255
  44. res = np.array(model.predict(np.array([image]))[0])
  45. return res.argmax()