Skip to content

Commit

Permalink
[Fix] Fix wrong condition judgment in analyze_logs.py and prevent e…
Browse files Browse the repository at this point in the history
…mpty curve. (open-mmlab#510)

* [Fix] Analyze logs with single training iteration

* [Fix] Make `plot_curve` with 'accuracy' metric

* [Fix] Assert length of training log records of each epoch is larger than 1

Co-authored-by: Ma Zerun <[email protected]>

Co-authored-by: Ma Zerun <[email protected]>
  • Loading branch information
imyhxy and mzr1996 authored Nov 3, 2021
1 parent 27a90cb commit 06dc4e2
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions tools/analysis_tools/analyze_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,9 @@ def plot_curve(log_dicts, args):
f'{args.json_logs[i]} does not contain metric {metric} '
f'in train mode')

if 'mAP' in metric:
xs = np.arange(1, max(epochs) + 1)
ys = []
for epoch in epochs:
ys += log_dict[epoch][metric]
if any(m in metric for m in ('mAP', 'accuracy')):
xs = epochs
ys = [log_dict[e][metric] for e in xs]
ax = plt.gca()
ax.set_xticks(xs)
plt.xlabel('epoch')
Expand All @@ -74,6 +72,9 @@ def plot_curve(log_dicts, args):
iters = log_dict[epoch]['iter']
if log_dict[epoch]['mode'][-1] == 'val':
iters = iters[:-1]
assert len(iters) > 0, (
'The training log is empty, please try to reduce the '
'interval of log in config file.')
xs.append(
np.array(iters) + (epoch - 1) * num_iters_per_epoch)
ys.append(np.array(log_dict[epoch][metric][:len(iters)]))
Expand Down

0 comments on commit 06dc4e2

Please sign in to comment.