5
5
import mmcv
6
6
from gather_models import get_final_results
7
7
8
+ try :
9
+ import xlrd
10
+ except ImportError :
11
+ xlrd = None
12
+ try :
13
+ import xlutils
14
+ from xlutils .copy import copy
15
+ except ImportError :
16
+ xlutils = None
17
+
8
18
9
19
def parse_args ():
10
20
parser = argparse .ArgumentParser (
@@ -19,6 +29,10 @@ def parse_args():
19
29
'--out' , type = str , help = 'output path of gathered metrics to be stored' )
20
30
parser .add_argument (
21
31
'--not-show' , action = 'store_true' , help = 'not show metrics' )
32
+ parser .add_argument (
33
+ '--excel' , type = str , help = 'input path of excel to be recorded' )
34
+ parser .add_argument (
35
+ '--ncol' , type = int , help = 'Number of column to be modified or appended' )
22
36
23
37
args = parser .parse_args ()
24
38
return args
@@ -27,6 +41,26 @@ def parse_args():
27
41
if __name__ == '__main__' :
28
42
args = parse_args ()
29
43
44
+ if args .excel :
45
+ assert args .ncol , 'Please specify "--excel" and "--ncol" ' \
46
+ 'at the same time'
47
+ if xlrd is None :
48
+ raise RuntimeError (
49
+ 'xlrd is not installed,'
50
+ 'Please use “pip install xlrd==1.2.0” to install' )
51
+ if xlutils is None :
52
+ raise RuntimeError (
53
+ 'xlutils is not installed,'
54
+ 'Please use “pip install xlutils==2.0.0” to install' )
55
+ readbook = xlrd .open_workbook (args .excel )
56
+ sheet = readbook .sheet_by_name ('Sheet1' )
57
+ sheet_info = {}
58
+ total_nrows = sheet .nrows
59
+ for i in range (3 , sheet .nrows ):
60
+ sheet_info [sheet .row_values (i )[0 ]] = i
61
+ xlrw = copy (readbook )
62
+ table = xlrw .get_sheet (0 )
63
+
30
64
root_path = args .root
31
65
metrics_out = args .out
32
66
benchmark_json_path = args .benchmark_json
@@ -40,7 +74,7 @@ def parse_args():
40
74
if osp .exists (result_path ):
41
75
# 1 read config
42
76
cfg = mmcv .Config .fromfile (config )
43
- total_epochs = cfg .total_epochs
77
+ total_epochs = cfg .runner . max_epochs
44
78
final_results = cfg .evaluation .metric
45
79
if not isinstance (final_results , list ):
46
80
final_results = [final_results ]
@@ -64,7 +98,30 @@ def parse_args():
64
98
if model_performance is None :
65
99
print (f'log file error: { log_json_path } ' )
66
100
continue
101
+ for performance in model_performance :
102
+ if performance in ['AR@1000' , 'bbox_mAP' , 'segm_mAP' ]:
103
+ metric = round (model_performance [performance ] * 100 , 1 )
104
+ model_performance [performance ] = metric
67
105
result_dict [config ] = model_performance
106
+
107
+ # update and append excel content
108
+ if args .excel :
109
+ if 'AR@1000' in model_performance :
110
+ metrics = f'{ model_performance ["AR@1000" ]} (AR@1000)'
111
+ elif 'segm_mAP' in model_performance :
112
+ metrics = f'{ model_performance ["bbox_mAP" ]} /' \
113
+ f'{ model_performance ["segm_mAP" ]} '
114
+ else :
115
+ metrics = f'{ model_performance ["bbox_mAP" ]} '
116
+
117
+ row_num = sheet_info .get (config , None )
118
+ if row_num :
119
+ table .write (row_num , args .ncol , metrics )
120
+ else :
121
+ table .write (total_nrows , 0 , config )
122
+ table .write (total_nrows , args .ncol , metrics )
123
+ total_nrows += 1
124
+
68
125
else :
69
126
print (f'{ config } not exist: { ckpt_path } ' )
70
127
else :
@@ -79,3 +136,7 @@ def parse_args():
79
136
for config_name , metrics in result_dict .items ():
80
137
print (config_name , metrics )
81
138
print ('===================================' )
139
+ if args .excel :
140
+ filename , sufflx = osp .splitext (args .excel )
141
+ xlrw .save (f'{ filename } _o{ sufflx } ' )
142
+ print (f'>>> Output { filename } _o{ sufflx } ' )
0 commit comments