當前位置: 首頁>>代碼示例>>Python>>正文


Python backend.ctc_decode方法代碼示例

本文整理匯總了Python中keras.backend.ctc_decode方法的典型用法代碼示例。如果您正苦於以下問題:Python backend.ctc_decode方法的具體用法?Python backend.ctc_decode怎麽用?Python backend.ctc_decode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在keras.backend的用法示例。


在下文中一共展示了backend.ctc_decode方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: ctc_complete_decoding_lambda_func

# 需要導入模塊: from keras import backend [as 別名]
# 或者: from keras.backend import ctc_decode [as 別名]
def ctc_complete_decoding_lambda_func(args, **arguments):
        """
        Complete CTC decoding using Keras (function K.ctc_decode)
        :param args: 
            y_pred, input_length
        :param arguments:
            greedy, beam_width, top_paths
        :return: 
            K.ctc_decode with dtype='float32'
        """

        # import tensorflow as tf # Require for loading a model saved

        y_pred, input_length = args
        my_params = arguments

        assert (K.backend() == 'tensorflow')

        return K.cast(K.ctc_decode(y_pred, tf.squeeze(input_length), greedy=my_params['greedy'],
                                   beam_width=my_params['beam_width'], top_paths=my_params['top_paths'])[0][0],
                      dtype='float32') 
開發者ID:ysoullard,項目名稱:CTCModel,代碼行數:23,代碼來源:CTCModel.py

示例2: predict

# 需要導入模塊: from keras import backend [as 別名]
# 或者: from keras.backend import ctc_decode [as 別名]
def predict(self, data_input, input_len):
        """
        預測結果
        :param data_input:
        :param input_len:
        :return: 返回語音識別後的拚音符號列表
        """
        batch_size = 1
        in_len = np.zeros((batch_size), dtype=np.int32)
        in_len[0] = input_len
        x_in = np.zeros((batch_size, 1600, self.AUDIO_FEATURE_LENGTH, 1), dtype=np.float)

        for i in range(batch_size):
            x_in[i, 0:len(data_input)] = data_input
        with self.graph.as_default():
            base_pred = self.base_model.predict(x=x_in)
        base_pred = base_pred[:, :, :]
        decoder = K.ctc_decode(base_pred, in_len, greedy=True, beam_width=100, top_paths=1)
        result = K.get_value(decoder[0][0])[0]
        return result 
開發者ID:shibing624,項目名稱:parrots,代碼行數:22,代碼來源:speech_recognition.py

示例3: evaluate

# 需要導入模塊: from keras import backend [as 別名]
# 或者: from keras.backend import ctc_decode [as 別名]
def evaluate(self):
        correct_predictions = 0
        correct_char_predictions = 0       

        x_val, y_val = self.val_generator[np.random.randint(0, int(self.val_generator.nb_samples / self.val_generator.batch_size))]
        #x_val, y_val = next(self.val_generator)

        y_pred = self.prediction_model.predict(x_val)

        shape = y_pred[:, 2:, :].shape
        ctc_decode = K.ctc_decode(y_pred[:, 2:, :], input_length=np.ones(shape[0])*shape[1])[0][0]
        ctc_out = K.get_value(ctc_decode)[:, :self.label_len]

        for i in range(self.val_generator.batch_size):
            print(ctc_out[i])
            result_str = ''.join([self.characters[c] for c in ctc_out[i]])            
            result_str = result_str.replace('-', '')
            if result_str == y_val[i]:
                correct_predictions += 1
            print(result_str, y_val[i])
            
            for c1, c2 in zip(result_str, y_val[i]):
                if c1 == c2:
                    correct_char_predictions += 1

        return correct_predictions / self.val_generator.batch_size, correct_char_predictions 
開發者ID:kurapan,項目名稱:CRNN,代碼行數:28,代碼來源:utils.py

示例4: predict_text

# 需要導入模塊: from keras import backend [as 別名]
# 或者: from keras.backend import ctc_decode [as 別名]
def predict_text(model, img):
    y_pred = model.predict(img[np.newaxis, :, :, :])
    shape = y_pred[:, 2:, :].shape
    ctc_decode = K.ctc_decode(y_pred[:, 2:, :], input_length=np.ones(shape[0])*shape[1])[0][0]
    ctc_out = K.get_value(ctc_decode)[:, :cfg.label_len]
    result_str = ''.join([cfg.characters[c] for c in ctc_out[0]])
    result_str = result_str.replace('-', '')
    return result_str 
開發者ID:kurapan,項目名稱:CRNN,代碼行數:10,代碼來源:eval.py

示例5: _decode

# 需要導入模塊: from keras import backend [as 別名]
# 或者: from keras.backend import ctc_decode [as 別名]
def _decode(y_pred, input_length, greedy=True, beam_width=100, top_paths=1):
    """Decodes the output of a softmax.
    Can use either greedy search (also known as best path)
    or a constrained dictionary search.
    # Arguments
        y_pred: tensor `(samples, time_steps, num_categories)`
            containing the prediction, or output of the softmax.
        input_length: tensor `(samples, )` containing the sequence length for
            each batch item in `y_pred`.
        greedy: perform much faster best-path search if `true`.
            This does not use a dictionary.
        beam_width: if `greedy` is `false`: a beam search decoder will be used
            with a beam of this width.
        top_paths: if `greedy` is `false`,
            how many of the most probable paths will be returned.
    # Returns
        Tuple:
            List: if `greedy` is `true`, returns a list of one element that
                contains the decoded sequence.
                If `false`, returns the `top_paths` most probable
                decoded sequences.
                Important: blank labels are returned as `-1`.
            Tensor `(top_paths, )` that contains
                the log probability of each decoded sequence.
    """
    decoded = K.ctc_decode(y_pred=y_pred, input_length=input_length,
                           greedy=greedy, beam_width=beam_width, top_paths=top_paths)
    paths = [path.eval(session=K.get_session()) for path in decoded[0]]
    logprobs  = decoded[1].eval(session=K.get_session())

    return (paths, logprobs) 
開發者ID:rizkiarm,項目名稱:LipNet,代碼行數:33,代碼來源:decoders.py

示例6: predict

# 需要導入模塊: from keras import backend [as 別名]
# 或者: from keras.backend import ctc_decode [as 別名]
def predict(self , data_input , input_len):
        batch_size = 1
        in_len = np.zeros((batch_size) , dtype=np.int32)
        in_len[0] = input_len
        x_in = np.zeros(shape=[batch_size , 2000 , self.FEATURE_LENGTH , 1] , dtype=np.float)
        for i in range(batch_size):
            x_in[i , 0 : len(data_input)] = data_input
        base_pred = self.base_model.predict(x=x_in)
        base_pred = base_pred[: , : , :]
        r = K.ctc_decode(base_pred , in_len , greedy=True , beam_width=100 , top_paths=1)
        r1 = K.get_value(r[0][0])
        r1 = r1[0]
        return r1 
開發者ID:zw76859420,項目名稱:ASR_WORD,代碼行數:15,代碼來源:speech_model_01.py

示例7: decode_predict_ctc

# 需要導入模塊: from keras import backend [as 別名]
# 或者: from keras.backend import ctc_decode [as 別名]
def decode_predict_ctc(out, chars, top_paths=1):
    results = []
    beam_width = 5
    if beam_width < top_paths:
        beam_width = top_paths
    for i in range(top_paths):
        lables = K.get_value(
            K.ctc_decode(
                out, input_length=np.ones(out.shape[0]) * out.shape[1],
                greedy=False, beam_width=beam_width, top_paths=top_paths
            )[0][i]
        )[0]
        text = labels_to_text(chars, lables)
        results.append(text)
    return results 
開發者ID:huyhoang17,項目名稱:Vietnamese_Handwriting_Recognition,代碼行數:17,代碼來源:utils.py

示例8: Predict

# 需要導入模塊: from keras import backend [as 別名]
# 或者: from keras.backend import ctc_decode [as 別名]
def Predict(self, data_input, input_len):
		'''
		預測結果
		返回語音識別後的拚音符號列表
		'''
		
		batch_size = 1 
		in_len = np.zeros((batch_size),dtype = np.int32)
		
		in_len[0] = input_len
		
		x_in = np.zeros((batch_size, 1600, self.AUDIO_FEATURE_LENGTH, 1), dtype=np.float)
		
		for i in range(batch_size):
			x_in[i,0:len(data_input)] = data_input
		
		
		base_pred = self.base_model.predict(x = x_in)
		
		#print('base_pred:\n', base_pred)
		
		#y_p = base_pred
		#for j in range(200):
		#	mean = np.sum(y_p[0][j]) / y_p[0][j].shape[0]
		#	print('max y_p:',np.max(y_p[0][j]),'min y_p:',np.min(y_p[0][j]),'mean y_p:',mean,'mid y_p:',y_p[0][j][100])
		#	print('argmin:',np.argmin(y_p[0][j]),'argmax:',np.argmax(y_p[0][j]))
		#	count=0
		#	for i in range(y_p[0][j].shape[0]):
		#		if(y_p[0][j][i] < mean):
		#			count += 1
		#	print('count:',count)
		
		base_pred =base_pred[:, :, :]
		#base_pred =base_pred[:, 2:, :]
		
		r = K.ctc_decode(base_pred, in_len, greedy = True, beam_width=100, top_paths=1)
		
		#print('r', r)
		r1 = r[0][0].eval(session=tf.compat.v1.Session())
		tf.compat.v1.reset_default_graph()
		return r1[0] 
開發者ID:nl8590687,項目名稱:ASRT_SpeechRecognition,代碼行數:43,代碼來源:SpeechModel251.py

示例9: Predict

# 需要導入模塊: from keras import backend [as 別名]
# 或者: from keras.backend import ctc_decode [as 別名]
def Predict(self, data_input, input_len):
		'''
		預測結果
		返回語音識別後的拚音符號列表
		'''
		
		batch_size = 1 
		in_len = np.zeros((batch_size),dtype = np.int32)
		
		in_len[0] = input_len
		
		x_in = np.zeros((batch_size, 1600, self.AUDIO_FEATURE_LENGTH, 1), dtype=np.float)
		
		for i in range(batch_size):
			x_in[i,0:len(data_input)] = data_input
		
		
		base_pred = self.base_model.predict(x = x_in)
		
		#print('base_pred:\n', base_pred)
		
		#y_p = base_pred
		#for j in range(200):
		#	mean = np.sum(y_p[0][j]) / y_p[0][j].shape[0]
		#	print('max y_p:',np.max(y_p[0][j]),'min y_p:',np.min(y_p[0][j]),'mean y_p:',mean,'mid y_p:',y_p[0][j][100])
		#	print('argmin:',np.argmin(y_p[0][j]),'argmax:',np.argmax(y_p[0][j]))
		#	count=0
		#	for i in range(y_p[0][j].shape[0]):
		#		if(y_p[0][j][i] < mean):
		#			count += 1
		#	print('count:',count)
		
		base_pred =base_pred[:, :, :]
		#base_pred =base_pred[:, 2:, :]
		
		r = K.ctc_decode(base_pred, in_len, greedy = True, beam_width=100, top_paths=1)
		
		#print('r', r)
		
		
		r1 = K.get_value(r[0][0])
		#print('r1', r1)
		
		
		#r2 = K.get_value(r[1])
		#print(r2)
		
		r1=r1[0]
		
		return r1
		pass 
開發者ID:nl8590687,項目名稱:ASRT_SpeechRecognition,代碼行數:53,代碼來源:SpeechModel261_p.py


注:本文中的keras.backend.ctc_decode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。