代码拉取完成,页面将自动刷新
import re
import numpy as np
import matplotlib.pyplot as plt
from pylab import *
# args: log_name, match_rule, self_log_interval, smooth_log_interation
loss_file_name = "simple_loss"
title = "{}_Loss".format(loss_file_name)
f = open("../log/{}.log".format(loss_file_name))
pattern = re.compile(r'Loss:[ ]*\d+\.\d+')
self_inter = 10
smooth = 20
# read log file
lines = f.readlines()
print("Line: {}".format(len(lines)))
ys = []
k = 0
cnt = 0
sum_y = 0.
# read one by one
for line in lines:
obj = re.search(pattern, line)
if obj:
val = float(obj.group().split(':')[-1])
sum_y += val
k += 1
if k >= smooth:
ys.append(sum_y / k)
sum_y = 0.
k = 0
cnt += 1
if cnt % 10 == 0:
print("ys cnt: {}".format(cnt))
if k > 0:
ys.append(sum_y / k)
ys = np.array(ys)
xs = np.arange(len(ys)) * self_inter * smooth
print(xs)
print(ys)
plt.plot(xs, ys)
plt.title(title)
plt.xlabel("Iter")
plt.ylabel("Loss")
plt.savefig("../log/{}.png".format(title))
plt.show()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。