def decode_predict_ctc(out, 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 = GSQL.labels_to_text(lables)
      results.append(text)
    return results    
def decode_batch(test_func, word_batch):
    out = test_func([word_batch])[0]
    ret = []
    for j in range(out.shape[0]):
        out_best = list(np.argmax(out[j, 2:], 1))
        out_best = [k for k, g in itertools.groupby(out_best)]
        
        outstr = GENERATOR.labels_to_text(out_best)
       
        ret.append(outstr)
    return ret
def decode_batch(test_func, word_batch):
    out = test_func([word_batch])[0]
    ret = []
    for j in range(out.shape[0]):
        out_best = list(np.argmax(out[j, 2:], 1))
        out_best = [k for k, g in itertools.groupby(out_best)]
        if generator_choice == "GSQL":
            outstr = GSQL.labels_to_text(out_best)
        else:
            assert(False)
        ret.append(outstr)
    return ret
Exemplo n.º 4
0
def decode_predict_ctc(out, top_paths = 1):
    results = []
    beam_width = 5
    if beam_width < top_paths:
      beam_width = top_paths
    for i in range(top_paths):
        t0 = time.time()
        v1 = np.ones(out.shape[0])
        t1 = time.time()
        v2 = v1*out.shape[1]
        t2 = time.time()
        v3 = K.ctc_decode(out, input_length=v2, greedy=False, beam_width=beam_width, top_paths=top_paths)[0][i]
        t3 = time.time()
        lables = K.get_value(v3)[0]
        t4 = time.time()
        #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 = GSQL.labels_to_text(lables)
        
        results.append(text)
        
        print("why slow down" t4-t3)
    return results