def creat_model(self): input = Input(shape=(self.img_h, None, 1), name='the_input') y_pred = densenet.crnn2(input, self.n_class) basemodel = Model(inputs=input, outputs=y_pred) # basemodel.summary() labels = Input(name='the_labels', shape=[None], dtype='float32') input_length = Input(name='input_length', shape=[1], dtype='int64') label_length = Input(name='label_length', shape=[1], dtype='int64') loss_out = Lambda(self.ctc_lambda_func, output_shape=(1, ), name='ctc')( [y_pred, labels, input_length, label_length]) model = Model(inputs=[input, labels, input_length, label_length], outputs=loss_out) model.compile(loss={ 'ctc': lambda y_true, y_pred: y_pred }, optimizer='adam', metrics=['accuracy']) # model.summary() model.load_weights(self.model_path) return basemodel
def get_model(img_h, nclass): input = Input(shape=(img_h, img_w, 1), name='the_input') y_pred = densenet.crnn2(input, nclass) basemodel = Model(inputs=input, outputs=y_pred) basemodel.summary() labels = Input(name='the_labels', shape=[None], dtype='float32') input_length = Input(name='input_length', shape=[1], dtype='int64') label_length = Input(name='label_length', shape=[1], dtype='int64') loss_out = Lambda(ctc_lambda_func, output_shape=(1,), name='ctc')([y_pred, labels, input_length, label_length]) model = Model(inputs=[input, labels, input_length, label_length], outputs=loss_out) model.compile(loss={'ctc': lambda y_true, y_pred: y_pred}, optimizer='adam', metrics=['accuracy']) # model.compile(loss={'ctc': lambda y_true, y_pred: y_pred}, optimizer='RMSprop', metrics=['accuracy']) return basemodel, model