python保存log日志,实现用log日志画图-创新互联-成都快上网建站

python保存log日志,实现用log日志画图-创新互联

在神经网络训练中,我们常常需要画出loss function的变化图,log日志里会显示每一次迭代的loss function的值,于是我们先把log日志保存为log.txt文档,再利用这个文档来画图。   

创新互联公司-专业网站定制、快速模板网站建设、高性价比皮山网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式皮山网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖皮山地区。费用合理售后完善,十多年实体公司更值得信赖。

1,先来产生一个log日志。

import mxnet as mx
import numpy as np
import os
import logging
logging.getLogger().setLevel(logging.DEBUG)

# Training data
logging.basicConfig(filename = os.path.join(os.getcwd(), 'log.txt'), level = logging.DEBUG) # 把log日志保存为log.txt
train_data = np.random.uniform(0, 1, [100, 2])
train_label = np.array([train_data[i][0] + 2 * train_data[i][1] for i in range(100)])
batch_size = 1
num_epoch=5
# Evaluation Data
eval_data = np.array([[7,2],[6,10],[12,2]])
eval_label = np.array([11,26,16])
train_iter = mx.io.NDArrayIter(train_data,train_label, batch_size, shuffle=True,label_name='lin_reg_label')
eval_iter = mx.io.NDArrayIter(eval_data, eval_label, batch_size, shuffle=False)
X = mx.sym.Variable('data')
Y = mx.sym.Variable('lin_reg_label')
fully_connected_layer = mx.sym.FullyConnected(data=X, name='fc1', num_hidden = 1)
lro = mx.sym.LinearRegressionOutput(data=fully_connected_layer, label=Y, name="lro")
model = mx.mod.Module(
  symbol = lro ,
  data_names=['data'],
  label_names = ['lin_reg_label'] # network structure
)
model.fit(train_iter, eval_iter,
      optimizer_params={'learning_rate':0.005, 'momentum': 0.9},
      num_epoch=20,
      eval_metric='mse',)
model.predict(eval_iter).asnumpy()
metric = mx.metric.MSE()
model.score(eval_iter, metric)

本文题目:python保存log日志,实现用log日志画图-创新互联
浏览地址:http://kswjz.com/article/pcesp.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流