Skip to content

Commit

Permalink
Enhance the robustness of analyze_logs.py (#7407)
Browse files Browse the repository at this point in the history
  • Loading branch information
zytx121 authored Mar 16, 2022
1 parent 57f63bc commit a23b6b1
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions tools/analysis_tools/analyze_logs.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ def cal_train_time(log_dicts, args):
all_times.append(log_dict[epoch]['time'])
else:
all_times.append(log_dict[epoch]['time'][1:])
if not all_times:
raise KeyError(
'Please reduce the log interval in the config so that'
'interval is less than iterations of one epoch.')
all_times = np.array(all_times)
epoch_ave_time = all_times.mean(-1)
slowest_epoch = epoch_ave_time.argmax()
Expand Down Expand Up @@ -50,12 +54,21 @@ def plot_curve(log_dicts, args):
epochs = list(log_dict.keys())
for j, metric in enumerate(metrics):
print(f'plot curve of {args.json_logs[i]}, metric is {metric}')
if metric not in log_dict[epochs[0]]:
if metric not in log_dict[epochs[int(args.start_epoch) - 1]]:
if 'mAP' in metric:
raise KeyError(
f'{args.json_logs[i]} does not contain metric '
f'{metric}. Please check if "--no-validate" is '
'specified when you trained the model.')
raise KeyError(
f'{args.json_logs[i]} does not contain metric {metric}')
f'{args.json_logs[i]} does not contain metric {metric}. '
'Please reduce the log interval in the config so that '
'interval is less than iterations of one epoch.')

if 'mAP' in metric:
xs = np.arange(1, max(epochs) + 1)
xs = np.arange(
int(args.start_epoch),
max(epochs) + 1, int(args.eval_interval))
ys = []
for epoch in epochs:
ys += log_dict[epoch][metric]
Expand Down Expand Up @@ -104,6 +117,16 @@ def add_plot_parser(subparsers):
nargs='+',
default=['bbox_mAP'],
help='the metric that you want to plot')
parser_plt.add_argument(
'--start-epoch',
type=str,
default='1',
help='the epoch that you want to start')
parser_plt.add_argument(
'--eval-interval',
type=str,
default='1',
help='the eval interval when training')
parser_plt.add_argument('--title', type=str, help='title of figure')
parser_plt.add_argument(
'--legend',
Expand Down

0 comments on commit a23b6b1

Please sign in to comment.