diff --git a/dan/ocr/evaluate.py b/dan/ocr/evaluate.py index 0ee69128876855b9e4a7c37aa10729d7874a8f49..52308d3b74069c54b87c712bc5d48eb45f58c268 100644 --- a/dan/ocr/evaluate.py +++ b/dan/ocr/evaluate.py @@ -94,7 +94,7 @@ def print_worst_predictions(all_inferences: Dict[str, List[Inference]]): inference.prediction, ) alignment_str = f'{alignment["query_aligned"]}\n{alignment["matched_aligned"]}\n{alignment["target_aligned"]}' - table.add_row([inference.image, inference.wer, alignment_str]) + table.add_row([inference.image, round(inference.wer * 100, 2), alignment_str]) print(f"\n#### {NB_WORST_PREDICTIONS} worst prediction(s)\n") print(table) @@ -126,7 +126,14 @@ def eval_nerval( if not (ground_truths and predictions): continue - scores = evaluate(ground_truths, predictions, threshold) + scores = { + key: { + k: round(value * 100, 2) if k in ["P", "R", "F1"] else value + for k, value in values.items() + } + for key, values in evaluate(ground_truths, predictions, threshold).items() + } + print(f"\n##### {split_name}\n") print_results(scores) diff --git a/tests/data/evaluate/metrics_table.md b/tests/data/evaluate/metrics_table.md index b48adcf4ff179799905337dd89fdf4a260e0a94d..27bf53ad329cbd0441b030695b322728ce62b3f0 100644 --- a/tests/data/evaluate/metrics_table.md +++ b/tests/data/evaluate/metrics_table.md @@ -12,55 +12,55 @@ | tag | predicted | matched | Precision | Recall | F1 | Support | |:---------:|:---------:|:-------:|:---------:|:------:|:-----:|:-------:| -| Surname | 2 | 2 | 1.0 | 1.0 | 1.0 | 2 | +| Surname | 2 | 2 | 100.0 | 100.0 | 100.0 | 2 | | Patron | 2 | 0 | 0.0 | 0.0 | 0 | 1 | -| Operai | 2 | 2 | 1.0 | 1.0 | 1.0 | 2 | -| Louche | 2 | 1 | 0.5 | 0.5 | 0.5 | 2 | -| Koala | 2 | 2 | 1.0 | 1.0 | 1.0 | 2 | -| Firstname | 2 | 2 | 1.0 | 1.0 | 1.0 | 2 | -| Chalumeau | 1 | 1 | 1.0 | 1.0 | 1.0 | 1 | -| Batiment | 2 | 2 | 1.0 | 1.0 | 1.0 | 2 | -| All | 15 | 12 | 0.8 | 0.857 | 0.828 | 14 | +| Operai | 2 | 2 | 100.0 | 100.0 | 100.0 | 2 | +| Louche | 2 | 1 | 50.0 | 50.0 | 50.0 | 2 | +| Koala | 2 | 2 | 100.0 | 100.0 | 100.0 | 2 | +| Firstname | 2 | 2 | 100.0 | 100.0 | 100.0 | 2 | +| Chalumeau | 1 | 1 | 100.0 | 100.0 | 100.0 | 1 | +| Batiment | 2 | 2 | 100.0 | 100.0 | 100.0 | 2 | +| All | 15 | 12 | 80.0 | 85.71 | 82.76 | 14 | ##### val -| tag | predicted | matched | Precision | Recall | F1 | Support | -|:---------:|:---------:|:-------:|:---------:|:------:|:----:|:-------:| -| Surname | 1 | 0 | 0.0 | 0.0 | 0 | 1 | -| Patron | 1 | 1 | 1.0 | 1.0 | 1.0 | 1 | -| Operai | 1 | 0 | 0.0 | 0.0 | 0 | 1 | -| Louche | 1 | 1 | 1.0 | 1.0 | 1.0 | 1 | -| Koala | 1 | 1 | 1.0 | 1.0 | 1.0 | 1 | -| Firstname | 1 | 1 | 1.0 | 1.0 | 1.0 | 1 | -| Chalumeau | 1 | 1 | 1.0 | 1.0 | 1.0 | 1 | -| Batiment | 1 | 1 | 1.0 | 1.0 | 1.0 | 1 | -| All | 8 | 6 | 0.75 | 0.75 | 0.75 | 8 | +| tag | predicted | matched | Precision | Recall | F1 | Support | +|:---------:|:---------:|:-------:|:---------:|:------:|:-----:|:-------:| +| Surname | 1 | 0 | 0.0 | 0.0 | 0 | 1 | +| Patron | 1 | 1 | 100.0 | 100.0 | 100.0 | 1 | +| Operai | 1 | 0 | 0.0 | 0.0 | 0 | 1 | +| Louche | 1 | 1 | 100.0 | 100.0 | 100.0 | 1 | +| Koala | 1 | 1 | 100.0 | 100.0 | 100.0 | 1 | +| Firstname | 1 | 1 | 100.0 | 100.0 | 100.0 | 1 | +| Chalumeau | 1 | 1 | 100.0 | 100.0 | 100.0 | 1 | +| Batiment | 1 | 1 | 100.0 | 100.0 | 100.0 | 1 | +| All | 8 | 6 | 75.0 | 75.0 | 75.0 | 8 | ##### test | tag | predicted | matched | Precision | Recall | F1 | Support | |:---------:|:---------:|:-------:|:---------:|:------:|:-----:|:-------:| -| Surname | 1 | 1 | 1.0 | 1.0 | 1.0 | 1 | -| Louche | 1 | 1 | 1.0 | 1.0 | 1.0 | 1 | -| Koala | 1 | 1 | 1.0 | 1.0 | 1.0 | 1 | -| Firstname | 1 | 1 | 1.0 | 1.0 | 1.0 | 1 | +| Surname | 1 | 1 | 100.0 | 100.0 | 100.0 | 1 | +| Louche | 1 | 1 | 100.0 | 100.0 | 100.0 | 1 | +| Koala | 1 | 1 | 100.0 | 100.0 | 100.0 | 1 | +| Firstname | 1 | 1 | 100.0 | 100.0 | 100.0 | 1 | | Chalumeau | 1 | 0 | 0.0 | 0.0 | 0 | 1 | -| Batiment | 1 | 1 | 1.0 | 1.0 | 1.0 | 1 | -| All | 6 | 5 | 0.833 | 0.833 | 0.833 | 6 | +| Batiment | 1 | 1 | 100.0 | 100.0 | 100.0 | 1 | +| All | 6 | 5 | 83.33 | 83.33 | 83.33 | 6 | #### 5 worst prediction(s) -| Image name | WER | Alignment between ground truth - prediction | -|:----------------------------------------:|:------:|:---------------------------------------------------------:| -| 2c242f5c-e979-43c4-b6f2-a6d4815b651d.png | 0.5 | ⓈA â’»Charles â’·11 â“P â’¸C â“€F â“„A â“…14331 | -| | | |.||||||||||||||||||||||||.||||.|| | -| | | Ⓢd â’»Charles â’·11 â“P â’¸C â“€F â“„d â“…14 31 | -| 0dfe8bcd-ed0b-453e-bf19-cc697012296e.png | 0.2667 | ⓈTemplié â’»Marcelle â’·93 â“J â“€ch â“„E dachyle------- | -| | | ||||||||||||||||||||||||.|||||||||||.||.------- | -| | | ⓈTemplié â’»Marcelle â’·93 â“S â“€ch â“„E dactylo â“…18376 | -| ffdec445-7f14-4f5f-be44-68d0844d0df1.png | 0.1429 | ⓈNaudin â’»Marie â’·53 â“S â’¸V â“€Belle mère | -| | | |||||||||||||||||||||||.|||||||||||| | -| | | ⓈNaudin â’»Marie â’·53 â“S â’¸v â“€Belle mère | -| 0a56e8b3-95cd-4fa5-a17b-5b0ff9e6ea84.png | 0.125 | ⓈBellisson â’»Georges â’·91 â“P â’¸M â“€Ch â“„Plombier â“…-------12241 | -| | | |||||||||||||||||||||||||||||||||||||||||||||-------||||| | -| | | ⓈBellisson â’»Georges â’·91 â“P â’¸M â“€Ch â“„Plombier â“…Patron?12241 | +| Image name | WER | Alignment between ground truth - prediction | +|:----------------------------------------:|:-----:|:---------------------------------------------------------:| +| 2c242f5c-e979-43c4-b6f2-a6d4815b651d.png | 50.0 | ⓈA â’»Charles â’·11 â“P â’¸C â“€F â“„A â“…14331 | +| | | |.||||||||||||||||||||||||.||||.|| | +| | | Ⓢd â’»Charles â’·11 â“P â’¸C â“€F â“„d â“…14 31 | +| 0dfe8bcd-ed0b-453e-bf19-cc697012296e.png | 26.67 | ⓈTemplié â’»Marcelle â’·93 â“J â“€ch â“„E dachyle------- | +| | | ||||||||||||||||||||||||.|||||||||||.||.------- | +| | | ⓈTemplié â’»Marcelle â’·93 â“S â“€ch â“„E dactylo â“…18376 | +| ffdec445-7f14-4f5f-be44-68d0844d0df1.png | 14.29 | ⓈNaudin â’»Marie â’·53 â“S â’¸V â“€Belle mère | +| | | |||||||||||||||||||||||.|||||||||||| | +| | | ⓈNaudin â’»Marie â’·53 â“S â’¸v â“€Belle mère | +| 0a56e8b3-95cd-4fa5-a17b-5b0ff9e6ea84.png | 12.5 | ⓈBellisson â’»Georges â’·91 â“P â’¸M â“€Ch â“„Plombier â“…-------12241 | +| | | |||||||||||||||||||||||||||||||||||||||||||||-------||||| | +| | | ⓈBellisson â’»Georges â’·91 â“P â’¸M â“€Ch â“„Plombier â“…Patron?12241 |