代码拉取完成,页面将自动刷新
import os
import numpy as np
import matplotlib.pyplot as plt
from src.graph_globals import global_params
from src.graphs import graph, multi_line, get_cmap
from src.picklefuncs import load_data
def get_headers(fp):
#read header
with open(fp, 'r') as f:
header = f.readline()
headers = header.split(',')
#remove last header escape char
headers[-1] = headers[-1][:-1]
print(headers)
return headers
def get_data(fp):
data = np.loadtxt(fp, delimiter=',', skiprows=1).T
if data.ndim == 1:
return [ [d for d in data] ]
else:
return [d for d in data]
def graph_data(data, labels, metric):
f, ax = plt.subplots(1,1)
#get distinct colours in a cmap
cmap = get_cmap(len(labels))
colours = [ cmap(i) for i in range(len(labels)) ]
graph( ax, data, multi_line( ax, data, colours, labels),
xtitle='Time',
ytitle_pad = (metric, 60),
title='Training Updates Progress',
legend=(0.92, 0.92),
grid=True)
#f.suptitle(metric_title)
#display graph
plt.show()
def graph_metric(path, metric):
newest_fp = [fp for fp in sorted(os.listdir(path)) if metric in fp][-1]
print(metric)
print(newest_fp)
fp = path+newest_fp
labels = get_headers(fp)
data = get_data(fp)
print(data)
graph_data(data, labels, metric)
def main():
global_params()
path = 'tmp/'
metrics = ['replay', 'updates', 'nexp']
for m in metrics:
graph_metric(path, m)
'''
newest_fp = sorted(os.listdir(path))[-1]
fp = path+newest_fp
labels = get_headers(fp)
data = get_data(fp)
graph_data(data, labels)
'''
if __name__ == '__main__':
main()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。