Ejemplo n.º 1
0
def accuracy(label, val, vocab, r_vocab, lpr_patterns):
    pred = decode_beams(val, r_vocab)
    label_len = len(label)
    acc, acc1 = 0, 0
    num = 0
    for i in range(label_len):
        if not lpr_pattern_check(label[i].decode('utf-8'),
                                 lpr_patterns):  # GT label fails
            print('GT label fails: ' + label[i].decode('utf-8'))
            continue
        best = pred[i]

        #the edit distance show the number of steps that takes to change a string to the other
        edd = edit_distance(encode(label[i].decode('utf-8'), vocab),
                            encode(best, vocab))

        #they return two accuracies
        if edd <= 1:
            acc1 += 1
        if label[i].decode('utf-8') == best:
            acc += 1
        else:
            if label[i].decode('utf-8') not in pred[i]:
                print('Check GT label: ' + label[i].decode('utf-8'))
            print(label[i].decode('utf-8') + ' -- ' + best +
                  ' Edit Distance: ' + str(edd))
        num += 1
    return float(acc), float(acc1), num
Ejemplo n.º 2
0
Archivo: utils.py Proyecto: Peiiii/lpr
def accuracy(label, val, vocab, r_vocab):
    pred = decode_beams(val, r_vocab)
    label_len = len(label)
    acc, acc1 = 0, 0
    num = 0
    for i in range(label_len):
        if not lpr_pattern_check(label[i].decode('utf-8')):  # GT label fails
            print('GT label fails: ' + label[i].decode('utf-8'))
            continue
        best = pred[i]
        edd = edit_distance(encode(label[i].decode('utf-8'), vocab),
                            encode(best, vocab))
        if edd <= 1:
            acc1 += 1
        if label[i].decode('utf-8') == best:
            acc += 1
        else:
            if label[i].decode('utf-8') not in pred[i]:
                print('Check GT label: ' + label[i].decode('utf-8'))
            print(label[i].decode('utf-8') + ' -- ' + best +
                  ' Edit Distance: ' + str(edd))
        num += 1
    return float(acc), float(acc1), num