|
1 | 1 | import sys
|
| 2 | +import csv |
2 | 3 |
|
3 | 4 | path = sys.argv[1]
|
4 | 5 |
|
5 |
| -c, s = 0, 0. |
| 6 | +mIoU_all_sum = 0. |
6 | 7 |
|
7 |
| -avg_first = 0. |
8 |
| -avg_last = 0. |
9 |
| -nb_first_classes = 0 |
10 |
| -col_index = -1 |
| 8 | +bg = 0. |
| 9 | +avg_old = 0. |
| 10 | +avg_new = 0. |
| 11 | +num_old_classes = 0 |
| 12 | +col_index = 0 |
11 | 13 |
|
12 | 14 | with open(path, 'r') as f:
|
13 |
| - for line_index, line in enumerate(f): |
14 |
| - split = line.split(',') |
15 |
| - a = split[-1] |
16 |
| - a = float(a) |
17 |
| - s += a |
18 |
| - c += 1 |
19 |
| - step = line.split(',')[0] |
20 |
| - |
21 |
| - if line_index == 0: |
22 |
| - for col_index in range(1, len(split)): |
23 |
| - if split[col_index] == "x": break |
24 |
| - elif col_index > -1: |
25 |
| - if len(split[1:col_index]) == 0: |
26 |
| - avg_first = 0. |
| 15 | + data = list(csv.reader(f)) |
| 16 | + num_rows = len(data) |
| 17 | + for step, x in enumerate(data): |
| 18 | + mIoU_all = float(x[-1]) |
| 19 | + mIoU_all_sum += mIoU_all |
| 20 | + assert step == int(x[0]), 'Results for step {} missed.'.format(step) |
| 21 | + |
| 22 | + if step == 0: |
| 23 | + for col_index in range(1, len(x)): |
| 24 | + if x[col_index] in ('x', 'X'): |
| 25 | + break |
| 26 | + num_old_classes = col_index - 2 |
| 27 | + num_new_classes = len(x) - num_old_classes - 3 |
| 28 | + elif step == num_rows - 1: |
| 29 | + if len(x[2:col_index]) == 0: |
| 30 | + avg_old = 0. |
27 | 31 | else:
|
28 |
| - avg_first = sum([float(i) for i in split[1:col_index] if i not in ('x', 'X')]) / len(split[1:col_index]) |
29 |
| - if len(split[col_index:-1]) == 0: |
30 |
| - avg_last = 0. |
| 32 | + avg_old = sum([float(i) for i in x[2:col_index]]) / num_old_classes |
| 33 | + if len(x[col_index:-1]) == 0: |
| 34 | + avg_new = 0. |
31 | 35 | else:
|
32 |
| - avg_last = sum([float(i) for i in split[col_index:-1] if i not in ('x', 'X')]) / len(split[col_index:-1]) |
33 |
| - |
34 |
| - |
35 |
| - |
36 |
| -print(f"Last Step: {step}") |
37 |
| -print(f"Final Mean IoU {round(100 * a, 2)}") |
38 |
| -print(f'Average Mean IoU {round(100 * s / c, 2)}') |
39 |
| -print(f'Mean IoU first {round(100 * avg_first, 2)}') |
40 |
| -print(f'Mean IoU last {round(100 * avg_last, 2)}') |
| 36 | + avg_new = sum([float(i) for i in x[col_index:-1]]) / num_new_classes |
| 37 | + bg = float(x[1]) |
| 38 | + |
| 39 | +print("{:<12}: {:>5d}".format("Final Step", step)) |
| 40 | +print("{:<12}: {:>2.2f}".format("IoU BG", 100 * bg)) |
| 41 | +print("{:<12}: {:>2.2f}".format("mIoU old", 100 * avg_old)) |
| 42 | +print("{:<12}: {:>2.2f}".format("mIoU new", 100 * avg_new)) |
| 43 | +print("{:<12}: {:>2.2f}".format("mIoU all", 100 * mIoU_all)) |
| 44 | +print("{:<12}: {:>2.2f}".format("mIoU Avg", 100 * mIoU_all_sum / num_rows)) |
0 commit comments