1 Star 0 Fork 0

87ssfantasy/pytorch-deep-image-matting

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
loss_draw.py 1.04 KB
一键复制 编辑 原始数据 按行查看 历史
liuliang 提交于 2019-01-22 16:52 +08:00 . tidy code
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()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ssfantasy/pytorch-deep-image-matting.git
git@gitee.com:ssfantasy/pytorch-deep-image-matting.git
ssfantasy
pytorch-deep-image-matting
pytorch-deep-image-matting
master

搜索帮助