clovaai / deep-text-recognition-benchmark

Text recognition (optical character recognition) with deep learning methods, ICCV 2019
Apache License 2.0
3.77k stars 1.11k forks source link

Confidence score with 'CTC' prediction #354

Open rafaelagrc opened 2 years ago

rafaelagrc commented 2 years ago

Hi. Does anyone know how to extract the confidence score of the prediction in a model trained with the 'CTC' module? I only found the example with 'Attn' in this repo:

confidence_score_list = []
for gt, pred, pred_max_prob in zip(labels, preds_str, preds_max_prob):
    if 'Attn' in opt.Prediction:
        gt = gt[:gt.find('[s]')]
        pred_EOS = pred.find('[s]')
        pred = pred[:pred_EOS]  # prune after "end of sentence" token ([s])
        pred_max_prob = pred_max_prob[:pred_EOS]

 # calculate confidence score (= multiply of pred_max_prob)
try:
    confidence_score = pred_max_prob.cumprod(dim=0)[-1]
except:
    confidence_score = 0  # for empty pred case, when prune after "end of sentence" token ([s])
confidence_score_list.append(confidence_score)
TripurAR commented 1 year ago

Facing the same issue