-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalyze.py
154 lines (125 loc) · 5.11 KB
/
analyze.py
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
"""
Auxiliary script to analyze output data.
Options include comparing benchmark metrics, performing regression, plotting timeseries
performance, and more. Refer to the README for usage.
"""
import argparse
from userdefs import get_sample_methods
from yolov3 import parallelize
from retrain import utils
import analysis.benchmark as bench
from analysis import charts
def get_args(prefixes):
parser = argparse.ArgumentParser(description="Analyze training output data")
parser.add_argument(
"--config", required=True, help="configuration file for output data"
)
parser.add_argument(
"--prefix", choices=prefixes, default=None, help="prefix of model to test"
)
group = parser.add_mutually_exclusive_group()
group.add_argument("--avg", type=int, action="store", nargs="?", default=False)
group.add_argument("--roll_avg", type=int, default=None)
parser.add_argument("--batch_test", type=int, default=None)
parser.add_argument("--delta", type=int, default=4)
parser.add_argument("--tabulate", action="store_true", default=False)
parser.add_argument("--benchmark", action="store_true", default=False)
parser.add_argument("--visualize_conf", default=None)
parser.add_argument("--view_benchmark", default=None)
parser.add_argument("--filter_sample", action="store_true", default=False)
parser.add_argument("--compare_init", action="store_true", default=False)
parser.add_argument("--aggr_median", action="store_true", default=False)
metric_names = [
"prec",
"acc",
"recall",
"conf",
"conf_std",
"detect_conf_std",
"epochs_trained",
]
parser.add_argument("--metric", choices=metric_names, default="prec")
parser.add_argument("--metric2", choices=metric_names, default=None)
opt = parser.parse_args()
config = utils.parse_retrain_config(opt.config)
return opt, config
def benchmark_all(prefixes, config, opt):
# Benchmark the inference results before the start of each sample batch
# and as a time series
batch_args = list()
for prefix in prefixes:
batch_args.append((prefix, config, opt))
if not config["parallel"]:
bench.benchmark_next_batch(*batch_args[-1])
if config["parallel"]:
parallelize.run_parallel(bench.benchmark_next_batch, batch_args)
def benchmark_batch_test(prefixes, config, opt, num_batches):
batch_args = list()
for prefix in prefixes:
batch_args.append((prefix, config, opt, num_batches))
if not config["parallel"]:
bench.benchmark_batch_test_set(*batch_args[-1])
if config["parallel"]:
parallelize.run_parallel(bench.benchmark_batch_test_set, batch_args)
def get_benchmark_suffix(opt):
bench_suffix = "_*.csv"
if opt.batch_test is not None:
# Default is rolling average on batch test set
bench_suffix = "_test" + bench_suffix
if opt.avg:
# This provides the linear-spaced variant
bench_suffix = "_avg" + bench_suffix
elif opt.roll_avg is not None:
# Rolling average for batch splits and series
bench_suffix = "_roll" + bench_suffix
else:
# View batch splits; generated by default
bench_suffix = "_avg_1" + bench_suffix
return bench_suffix
def main():
prefixes = ["init"] + list(get_sample_methods().keys())
opt, config = get_args(prefixes)
bench_suffix = get_benchmark_suffix(opt)
if opt.benchmark:
if opt.prefix is not None:
prefixes = [opt.prefix]
bench.series_benchmark(config, opt, opt.prefix)
if opt.batch_test is None:
benchmark_all(prefixes, config, opt)
else:
benchmark_batch_test(prefixes, config, opt, opt.batch_test)
if opt.tabulate:
if opt.prefix is not None:
# Specify a sampling prefix to view all metrics (conf, prec, acc, recall train length)
# on a per-batch basis
charts.tabulate_batch_samples(
config,
opt.prefix,
filter_samp=opt.filter_sample,
bench_suffix=bench_suffix,
)
else:
# View the specified metric (with precision as default) for each batch,
# across all sampling methods
charts.compare_benchmarks(
config,
prefixes,
opt.metric,
opt.metric2,
bench_suffix,
compare_init=opt.compare_init,
filter_sample=opt.filter_sample,
use_median=opt.aggr_median,
)
elif opt.visualize_conf:
# Generate a PDF graph of the confidence distributions for a specified benchmark file
charts.visualize_conf(
opt.prefix, opt.visualize_conf, opt.filter_sample, config["pos_thres"]
)
elif opt.view_benchmark is not None:
charts.display_benchmark(opt.view_benchmark, config)
elif opt.prefix is not None:
charts.tabulate_batch_samples(config, opt.prefix, bench_suffix=bench_suffix)
charts.display_series(config, opt)
if __name__ == "__main__":
main()