|
|
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) |
|
|
for row in reader: |
|
|
filename, indexs, probs = row |
|
|
indexs = list(filter(None, indexs[1:-1].split(' '))) |
|
|
probs = list(filter(None, probs[1:-1].split(' '))) |
|
|
|
|
|
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 |
|
|
|
|
|
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() |