File size: 1,397 Bytes
ad5b5e4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
import os
import os.path as osp
import csv
from collections import Counter
csv_file = './output/test/resnet50-224.csv'
output_prefix = './test/'
class_to_idx = {'Card': 0, 'Flyer': 1, 'Infographic': 2, 'Logo': 3, 'Poster': 4, 'T-shirt': 5}
idx_to_class = {v:k for k, v in class_to_idx.items()}
def read_csv_file(csv_file):
with open(csv_file, 'r') as f:
reader = csv.reader(f)
next(reader) # skip header
for row in reader:
filename, indexs, probs = row
indexs = list(filter(None, indexs[1:-1].split(' ')))
probs = list(filter(None, probs[1:-1].split(' ')))
# print(indexs, probs)
yield filename, int(indexs[0]), float(probs[0]), int(indexs[1]), float(probs[1])
def main():
print('''Result
| pic | gt | top1 | top1_prob | top2 | top2_prob |
|-|-|-|-|-|-|''')
category_counter = Counter()
for filename, top1, top1_prob, top2, top2_prob in read_csv_file(csv_file):
gt_category = osp.dirname(filename)
category_counter[gt_category] += 1
if category_counter[gt_category] > 20:
continue
# output filename as MD image
print(f'| <img src="{osp.join(output_prefix, filename)}" alt="{filename}" width="200"/> | {gt_category} | {idx_to_class[top1]} | {top1_prob} | {idx_to_class[top2]} | {top2_prob} |')
if __name__ == '__main__':
main() |