Created
February 21, 2018 04:52
-
-
Save NotFounds/72d4d2280e45e4e316f4eaf081746b0f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
import numpy as np | |
import json | |
FileName = 'log' | |
def read_json(path = './log.json'): | |
file = open(path, 'r') | |
return json.load(file) | |
def plot_chainer_log(json_obj, y_keys, linestyles, colors, x_key='epoch'): | |
dict = {} | |
x = [] | |
for key in y_keys: | |
dict[key] = [] | |
for obj in json_obj: | |
x.append(obj[x_key]) | |
for key in y_keys: | |
dict[key].append(obj[key]) | |
for key, sty, clr in zip(y_keys, linestyles, colors): | |
plt.plot(x, dict[key], label=key, color=clr, linestyle=sty) | |
plt.xlabel = x_key | |
axes = plt.gca() | |
#axes.set_ylim([0, 1.0]) | |
plt.grid(which='major', color='gray', linestyle='-') | |
plt.grid(which='minor', color='gray', linestyle='-') | |
plt.legend(loc='lower right') | |
plot_chainer_log(read_json(FileName + '.json'), y_keys=['main/loss', 'validation/main/loss'], linestyles=['solid', 'solid'], colors=['black', 'darkgray']) | |
plt.legend(loc='upper right') | |
#plt.show() | |
plt.savefig(FileName + '.png') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment