Unverified Commit e39d1984 authored by Ziyi Wu's avatar Ziyi Wu Committed by GitHub
Browse files

[Fix] Fix potential bug in using `analyze_logs` (#634)

* fix when killing before eval

* fix resume log
parent 63bdad98
...@@ -53,10 +53,21 @@ def plot_curve(log_dicts, args): ...@@ -53,10 +53,21 @@ def plot_curve(log_dicts, args):
f'{args.json_logs[i]} does not contain metric {metric}') f'{args.json_logs[i]} does not contain metric {metric}')
if args.mode == 'eval': if args.mode == 'eval':
xs = np.arange(args.interval, max(epochs) + 1, args.interval) # if current training is resumed from previous checkpoint
# we lost information in early epochs
# `xs` should start according to `min(epochs)`
x0 = min(epochs) + args.interval - min(epochs) % args.interval
xs = np.arange(x0, max(epochs) + 1, args.interval)
ys = [] ys = []
for epoch in epochs[args.interval - 1::args.interval]: for epoch in epochs[args.interval - 1::args.interval]:
ys += log_dict[epoch][metric] ys += log_dict[epoch][metric]
# if training is aborted before eval of the last epoch
# `xs` and `ys` will have different length and cause an error
# check if `ys[-1]` is empty here
if not log_dict[epoch][metric]:
xs = xs[:-1]
ax = plt.gca() ax = plt.gca()
ax.set_xticks(xs) ax.set_xticks(xs)
plt.xlabel('epoch') plt.xlabel('epoch')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment