DL之CNN:基于CRNN_OCR算法(keras,CNN+RNN)利用数据集(torch,mdb格式)训练来实现新图片上不定长度字符串进行识别—训练过程
from keras.callbacks import ModelCheckpoint, ReduceLROnPlateau
nclass = len(characters) + 1
model, basemodel = get_model_train(height=imgH, nclass=nclass)
import os
if os.path.exists('./models/pretrain_models/keras.hdf5'):
basemodel.load_weights('./models/pretrain_models/keras.hdf5')
checkpointer = ModelCheckpoint(filepath="./models/ intermediate_model/model{epoch:02d}-{val_loss:.4f}.hdf5", monitor='val_loss',
verbose=0, save_weights_only=False, save_best_only=True)
rlu = ReduceLROnPlateau(monitor='val_loss', factor=0.1, patience=1, verbose=0, mode='auto', epsilon=0.0001,
cooldown=0, min_lr=0)
model.fit_generator(gen(train_loader, flag='train'),
steps_per_epoch=1024,
epochs=10000,
validation_data=gen(test_loader, flag='test'),
callbacks=[checkpointer, rlu],
validation_steps=1024)
#保存两个h5文件
model.save_weights('./models/final_model/final_model_weights.h5')
model.save('./models/final_model/final_model.h5')
联系客服