-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Fix] Fix wrong condition judgment in analyze_logs.py
and prevent empty curve.
#510
Conversation
Test with this log file. python tools/analysis_tools/analyze_logs.py plot_curve 20211028_115735.log.json --keys accuracy_top-1 |
Codecov Report
@@ Coverage Diff @@
## master #510 +/- ##
==========================================
+ Coverage 79.42% 79.48% +0.05%
==========================================
Files 106 106
Lines 5959 5975 +16
Branches 962 968 +6
==========================================
+ Hits 4733 4749 +16
Misses 1095 1095
Partials 131 131
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
Thanks for your contribution. |
20211028_115735.log.json.txt |
I have read your modification. if 'mAP' in metric: # <-- Here, it's the condition to find the metric in val steps
xs = np.arange(1, max(epochs) + 1)
ys = []
for epoch in epochs:
ys += log_dict[epoch][metric]
ax = plt.gca()
ax.set_xticks(xs)
plt.xlabel('epoch')
plt.plot(xs, ys, label=legend[i * num_metrics + j], marker='o')
else: # <-- Else, it will find the metric in train steps
xs = []
ys = []
num_iters_per_epoch = log_dict[epochs[0]]['iter'][-1]
for epoch in epochs:
iters = log_dict[epoch]['iter']
if log_dict[epoch]['mode'][-1] == 'val':
iters = iters[:-1]
xs.append(
np.array(iters) + (epoch - 1) * num_iters_per_epoch)
ys.append(np.array(log_dict[epoch][metric][:len(iters)]))
xs = np.concatenate(xs)
ys = np.concatenate(ys)
plt.xlabel('iter')
plt.plot(
xs, ys, label=legend[i * num_metrics + j], linewidth=0.5) The problem is not the last eval step is skipped, but we forget to add "accuracy" to the condition to find the metric in val steps. if 'mAP' in metric or 'accuracy' in metric: And the original code can only work when evaluate in every epoch. So please change the original code to: if 'mAP' in metric or 'accuracy' in metric:
xs = []
ys = []
for epoch in epochs:
xs.append(epoch)
ys.extend(log_dict[epoch][metric])
ax = plt.gca()
ax.set_xticks(xs)
plt.xlabel('epoch')
plt.plot(xs, ys, label=legend[i * num_metrics + j], marker='o') |
Yeah, you are right. I have modified the code according to your suggestion. I think the |
…han 1 Co-authored-by: Ma Zerun <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for your contribution 😃
analyze_logs.py
and prevent empty curve.
…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]>
Motivation
Make
analyze_log.py
works with single validation iteration. Currently, theanalyza_logs.py
useiters = iters[:-1]
to get rid of the last validation iteration, but in a very smallval
set, there maybe only one validation step. In such case, theanalyze_log.py
won't work, it use print out a blank figure. This PR fixed that.Modification
When there is only one item in the
iters
list, then don't slice it.Checklist
Before PR:
After PR: