Python keras.backend.ctc_batch_cost() Examples

The following are 30 code examples of keras.backend.ctc_batch_cost(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module keras.backend , or try the search function .
Example #1
Source File: model.py    From KerasDeepSpeech with GNU Affero General Public License v3.0 7 votes vote down vote up
def ctc_lambda_func(args):
    y_pred, labels, input_length, label_length = args

    # hack for load_model
    import tensorflow as tf

    ''' from TF: Input requirements
    1. sequence_length(b) <= time for all b
    2. max(labels.indices(labels.indices[:, 1] == b, 2)) <= sequence_length(b) for all b.
    '''

    # print("CTC lambda inputs / shape")
    # print("y_pred:",y_pred.shape)  # (?, 778, 30)
    # print("labels:",labels.shape)  # (?, 80)
    # print("input_length:",input_length.shape)  # (?, 1)
    # print("label_length:",label_length.shape)  # (?, 1)


    return K.ctc_batch_cost(labels, y_pred, input_length, label_length) 
Example #2
Source File: speech_recognition.py    From parrots with Apache License 2.0 5 votes vote down vote up
def ctc_lambda_func(self, args):
        y_pred, labels, input_length, label_length = args

        y_pred = y_pred[:, :, :]
        return K.ctc_batch_cost(labels, y_pred, input_length, label_length) 
Example #3
Source File: loss.py    From Vietnamese_Handwriting_Recognition with MIT License 5 votes vote down vote up
def ctc_lambda_func(args):
    y_pred, labels, input_length, label_length = args
    # the 2 is critical here since the first couple outputs of the RNN
    # tend to be garbage:
    y_pred = y_pred[:, 2:, :]
    return K.ctc_batch_cost(labels, y_pred, input_length, label_length) 
Example #4
Source File: custom_training.py    From pottan-ocr with MIT License 5 votes vote down vote up
def ctc_lambda_func( args ):
    prediction, labels, prediction_lengths, label_lengths = args
    #  prediction = prediction[:, 2:, :]
    return K.ctc_batch_cost( labels, K.softmax( prediction ), prediction_lengths, label_lengths ) 
Example #5
Source File: train.py    From pottan-ocr with MIT License 5 votes vote down vote up
def ctc_lambda_func( args ):
    y_pred, labels, label_lengths = args
    y_pred_len = [ [y_pred.shape[1] ] ] * batchSize
    #  y_pred = y_pred[:, 2:, :]
    return K.ctc_batch_cost( labels, K.softmax( y_pred ), y_pred_len, label_lengths ) 
Example #6
Source File: main.py    From hyperlpr-train with Apache License 2.0 5 votes vote down vote up
def ctc_lambda_func(args):
    y_pred, labels, input_length, label_length = args
    y_pred = y_pred[:, :, 0, :]
    return K.ctc_batch_cost(labels, y_pred, input_length, label_length) 
Example #7
Source File: model.py    From DeepANPR with MIT License 5 votes vote down vote up
def ctc_lambda_func(args):
    y_pred, labels, input_length, label_length = args
    # the 2 is critical here since the first couple outputs of the RNN
    # tend to be garbage:
    y_pred = y_pred[:, 2:, :]
    return K.ctc_batch_cost(labels, y_pred, input_length, label_length) 
Example #8
Source File: model.py    From DeepANPR with MIT License 5 votes vote down vote up
def ctc_lambda_func(args):
    y_pred, labels, input_length, label_length = args
    # the 2 is critical here since the first couple outputs of the RNN
    # tend to be garbage:
    y_pred = y_pred[:, 2:, :]
    return K.ctc_batch_cost(labels, y_pred, input_length, label_length) 
Example #9
Source File: model.py    From DeepANPR with MIT License 5 votes vote down vote up
def ctc_lambda_func(args):
    y_pred, labels, input_length, label_length = args
    # the 2 is critical here since the first couple outputs of the RNN
    # tend to be garbage:
    y_pred = y_pred[:, 2:, :]
    return K.ctc_batch_cost(labels, y_pred, input_length, label_length) 
Example #10
Source File: model.py    From DeepANPR with MIT License 5 votes vote down vote up
def ctc_lambda_func(args):
    y_pred, labels, input_length, label_length = args
    # the 2 is critical here since the first couple outputs of the RNN
    # tend to be garbage:
    y_pred = y_pred[:, 2:, :]
    return K.ctc_batch_cost(labels, y_pred, input_length, label_length) 
Example #11
Source File: train.py    From chinese_ocr with MIT License 5 votes vote down vote up
def ctc_lambda_func(args):
    y_pred, labels, input_length, label_length = args
    return K.ctc_batch_cost(labels, y_pred, input_length, label_length) 
Example #12
Source File: train.py    From chinese_ocr with Apache License 2.0 5 votes vote down vote up
def ctc_lambda_func(args):
    y_pred, labels, input_length, label_length = args
    return K.ctc_batch_cost(labels, y_pred, input_length, label_length) 
Example #13
Source File: SpeechModel261_p.py    From ASRT_SpeechRecognition with GNU General Public License v3.0 5 votes vote down vote up
def ctc_lambda_func(self, args):
		y_pred, labels, input_length, label_length = args
		
		y_pred = y_pred[:, :, :]
		#y_pred = y_pred[:, 2:, :]
		return K.ctc_batch_cost(labels, y_pred, input_length, label_length) 
Example #14
Source File: SpeechModel251.py    From ASRT_SpeechRecognition with GNU General Public License v3.0 5 votes vote down vote up
def ctc_lambda_func(self, args):
		y_pred, labels, input_length, label_length = args
		
		y_pred = y_pred[:, :, :]
		#y_pred = y_pred[:, 2:, :]
		return K.ctc_batch_cost(labels, y_pred, input_length, label_length) 
Example #15
Source File: SpeechModel252.py    From ASRT_SpeechRecognition with GNU General Public License v3.0 5 votes vote down vote up
def ctc_lambda_func(self, args):
		y_pred, labels, input_length, label_length = args
		
		y_pred = y_pred[:, :, :]
		#y_pred = y_pred[:, 2:, :]
		return K.ctc_batch_cost(labels, y_pred, input_length, label_length) 
Example #16
Source File: SpeechModel251_p.py    From ASRT_SpeechRecognition with GNU General Public License v3.0 5 votes vote down vote up
def ctc_lambda_func(self, args):
		y_pred, labels, input_length, label_length = args
		
		y_pred = y_pred[:, :, :]
		#y_pred = y_pred[:, 2:, :]
		return K.ctc_batch_cost(labels, y_pred, input_length, label_length) 
Example #17
Source File: SpeechModel24.py    From ASRT_SpeechRecognition with GNU General Public License v3.0 5 votes vote down vote up
def ctc_lambda_func(self, args):
		y_pred, labels, input_length, label_length = args
		
		y_pred = y_pred[:, :, :]
		#y_pred = y_pred[:, 2:, :]
		return K.ctc_batch_cost(labels, y_pred, input_length, label_length) 
Example #18
Source File: SpeechModel25.py    From ASRT_SpeechRecognition with GNU General Public License v3.0 5 votes vote down vote up
def ctc_lambda_func(self, args):
		y_pred, labels, input_length, label_length = args
		
		y_pred = y_pred[:, :, :]
		#y_pred = y_pred[:, 2:, :]
		return K.ctc_batch_cost(labels, y_pred, input_length, label_length) 
Example #19
Source File: SpeechModel261.py    From ASRT_SpeechRecognition with GNU General Public License v3.0 5 votes vote down vote up
def ctc_lambda_func(self, args):
		y_pred, labels, input_length, label_length = args
		
		y_pred = y_pred[:, :, :]
		#y_pred = y_pred[:, 2:, :]
		return K.ctc_batch_cost(labels, y_pred, input_length, label_length) 
Example #20
Source File: SpeechModel26.py    From ASRT_SpeechRecognition with GNU General Public License v3.0 5 votes vote down vote up
def ctc_lambda_func(self, args):
		y_pred, labels, input_length, label_length = args
		
		y_pred = y_pred[:, :, :]
		#y_pred = y_pred[:, 2:, :]
		return K.ctc_batch_cost(labels, y_pred, input_length, label_length) 
Example #21
Source File: core.py    From text-detection-ocr with Apache License 2.0 5 votes vote down vote up
def _ctc_loss(args):
    labels, y_pred, input_length, label_length = args
    return K.ctc_batch_cost(labels, y_pred, input_length, label_length) 
Example #22
Source File: net.py    From speechless with MIT License 5 votes vote down vote up
def _ctc_lambda(args):
        prediction_batch, label_batch, prediction_lengths, label_lengths = args
        return backend.ctc_batch_cost(y_true=label_batch, y_pred=prediction_batch,
                                      input_length=prediction_lengths, label_length=label_lengths) 
Example #23
Source File: speech_model_02.py    From ASR_WORD with GNU Affero General Public License v3.0 5 votes vote down vote up
def ctc_lambda_func(self, args):
        y_pred, labels, input_length, label_length = args
        y_pred = y_pred[:, :, :]
        return K.ctc_batch_cost(y_true=labels, y_pred=y_pred, input_length=input_length, label_length=label_length) 
Example #24
Source File: speech_model_01.py    From ASR_WORD with GNU Affero General Public License v3.0 5 votes vote down vote up
def ctc_lambda_func(self, args):
        y_pred, labels, input_length, label_length = args
        y_pred = y_pred[:, :, :]
        return K.ctc_batch_cost(y_true=labels, y_pred=y_pred, input_length=input_length, label_length=label_length) 
Example #25
Source File: loss.py    From LipNet with MIT License 5 votes vote down vote up
def ctc_lambda_func(args):
    y_pred, labels, input_length, label_length = args
    # From Keras example image_ocr.py:
    # the 2 is critical here since the first couple outputs of the RNN
    # tend to be garbage:
    # y_pred = y_pred[:, 2:, :]
    y_pred = y_pred[:, :, :]
    return K.ctc_batch_cost(labels, y_pred, input_length, label_length) 
Example #26
Source File: densenet-ocr.py    From deep_learning with MIT License 5 votes vote down vote up
def ctc_lambda_func(args):
    y_pred,labels,input_length,label_length = args
    return K.ctc_batch_cost(labels, y_pred, input_length, label_length) 
Example #27
Source File: image_ocr.py    From pCVR with Apache License 2.0 5 votes vote down vote up
def ctc_lambda_func(args):
    y_pred, labels, input_length, label_length = args
    # the 2 is critical here since the first couple outputs of the RNN
    # tend to be garbage:
    y_pred = y_pred[:, 2:, :]
    return K.ctc_batch_cost(labels, y_pred, input_length, label_length)


# For a real OCR application, this should be beam search with a dictionary
# and language model.  For this example, best path is sufficient. 
Example #28
Source File: image_ocr.py    From DeepLearning_Wavelet-LSTM with MIT License 5 votes vote down vote up
def ctc_lambda_func(args):
    y_pred, labels, input_length, label_length = args
    # the 2 is critical here since the first couple outputs of the RNN
    # tend to be garbage:
    y_pred = y_pred[:, 2:, :]
    return K.ctc_batch_cost(labels, y_pred, input_length, label_length)


# For a real OCR application, this should be beam search with a dictionary
# and language model.  For this example, best path is sufficient. 
Example #29
Source File: interspeech_model.py    From Quaternion-Convolutional-Neural-Networks-for-End-to-End-Automatic-Speech-Recognition with GNU General Public License v3.0 5 votes vote down vote up
def ctc_lambda_func(args):
    y_pred, labels, input_length, label_length = args
    return K.ctc_batch_cost(labels, y_pred, input_length, label_length)

#
# Get Model
# 
Example #30
Source File: e2emodel.py    From lpr with Apache License 2.0 5 votes vote down vote up
def ctc_lambda_func(args):
    y_pred, labels, input_length, label_length = args
    y_pred = y_pred[:, 2:, :]
    return K.ctc_batch_cost(labels, y_pred, input_length, label_length)