Ejemplo n.º 1
0
    model.add(Activation('softmax'))
    model.compile(loss='categorical_crossentropy',
                  optimizer='adam',
                  metrics=['accuracy'])
    return model


# 构建网络
model = Getmodel_tensorflow(65)
model_ch = Getmodel_ch(31)

model_name = "char_rec.h5"
model_ch_name = "char_chi_sim.h5"
model_path = Path(cfg.COMMON.MODEL_DIR_PATH, model_name)
model_ch_path = Path(cfg.COMMON.MODEL_DIR_PATH, model_ch_name)
model.load_weights(model_path.__str__())
model_ch.load_weights(model_ch_path.__str__())
# model_ch.save_weights("./model/char_chi_sim.h5")
# model.save("./model/char_rec.h5")


def SimplePredict(image, pos):
    image = cv2.resize(image, (23, 23))
    image = cv2.equalizeHist(image)
    image = image.astype(np.float) / 255
    image -= image.mean()
    #image = np.expand_dims(image, 3)
    image = np.expand_dims(image, 2)
    if pos != 0:
        res = np.array(model.predict(np.array([image]))[0])
    else: