Ejemplo n.º 1
0
 def predict(self):
     file_list = []
     X, Y = get_image_data_ctc('./img_data/ctc_test/', file_list)
     y_pred = self.base_model.predict(X)
     shape = y_pred[:, :, :].shape  # 2:
     out = K.get_value(
         K.ctc_decode(y_pred[:, :, :],
                      input_length=np.ones(shape[0]) *
                      shape[1])[0][0])[:, :seq_len]  # 2:
     print()
     error_count = 0
     for i in range(len(X)):
         print(file_list[i])
         str_src = str(os.path.split(
             file_list[i])[-1]).split('.')[0].split('_')[-1]
         print(out[i])
         str_out = ''.join([str(char_set[x]) for x in out[i] if x != -1])
         print(str_src, str_out)
         if str_src != str_out:
             error_count += 1
             print('This is a error image---------------------------:',
                   error_count)
Ejemplo n.º 2
0
    def train(self, batch_size=32, nb_epoch=15, data_augmentation=False):

        X, Y = get_image_data_ctc(dir='./img_data/ctc/')
        print('train----------', X.shape, Y.shape)
        conv_shape = self.conv_shape

        maxin = 45000
        result = self.ctc_model.fit(
            [
                X[:maxin], Y[:maxin],
                np.array(np.ones(len(X)) * int(conv_shape[1]))[:maxin],
                np.array(np.ones(len(X)) * seq_len)[:maxin]
            ],
            Y[:maxin],
            batch_size=256,
            epochs=50,
            callbacks=[EarlyStopping(patience=10)
                       ],  # checkpointer, history,history, plotter,
            validation_data=([
                X[maxin:], Y[maxin:],
                np.array(np.ones(len(X)) * int(conv_shape[1]))[maxin:],
                np.array(np.ones(len(X)) * seq_len)[maxin:]
            ], Y[maxin:]),
        )