deep-text-recognition-benchmark icon indicating copy to clipboard operation
deep-text-recognition-benchmark copied to clipboard

Confidence score with 'CTC' prediction

Open rafaelagrc opened this issue 2 years ago • 1 comments

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)

rafaelagrc avatar Jul 08 '22 09:07 rafaelagrc

Facing the same issue

TripurAR avatar Mar 27 '23 10:03 TripurAR