roatienza / deep-text-recognition-benchmark

PyTorch code of my ICDAR 2021 paper Vision Transformer for Fast and Efficient Scene Text Recognition (ViTSTR)
Apache License 2.0
293 stars 59 forks source link

How to calculate Top-5 accuracy? #25

Open penghusile opened 2 years ago

penghusile commented 2 years ago

If I change _, preds_index = preds.topk(1, dim=-1, largest=True, sorted=True) to _, preds_index = preds.topk(k=5, dim=-1, largest=True, sorted=True), the program raise error


dataset_root:    data_lmdb_release/evaluation/CUTE80     dataset: /
sub-directory:  /.       num samples: 288
Traceback (most recent call last):
  File "test.py", line 318, in <module>
    test(opt)
  File "test.py", line 271, in test
    benchmark_all_eval(model, criterion, converter, opt)
  File "test.py", line 57, in benchmark_all_eval
    _, accuracy_by_best_model, norm_ED_by_best_model, _, _, _, infer_time, length_of_data = validation(
  File "test.py", line 151, in validation
    preds_str = converter.decode(preds_index[:,1], length_for_pred)
  File "/home/WeiHongxi/PengHusile/Server/ViTSTR/utils.py", line 197, in decode
    text = ''.join([self.character[i] for i in text_index[index, :]])
IndexError: too many indices for tensor of dimension 1```

or the accuracy turn to 0%