本文主要介紹python設(shè)置文件保存路徑(python保存信息),下面一起看看python設(shè)置文件保存路徑(python保存信息)相關(guān)資訊。
你需要畫一個(gè)損失函數(shù)的圖,每一次迭代的損失函數(shù)的值都會(huì)顯示在log log中,所以你需要先把log log保存為log.txt文件,然后用這個(gè)文件來畫。
1.生成日志日志import mx net as mx import numpy as np import os import logging . get logger。set level(logging . debug)# training data logging . basic config(filename = os . path . join(os . getcwd, log.txt ),級(jí)別=日志記錄。debug) #將日志另存為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 # eval _ data = np . array([[7,2],[6,10],[12,2])eval _ label = np . array([1];林_注冊(cè)_標(biāo)簽 )eval _ iter = mx . io . ndarrayiter(eval _ data,eval_label,batch_size,shuffle = false)x = mx . sym . variable( ;數(shù)據(jù)與信息。;)y = mx . sym . variable( ;林_注冊(cè)_標(biāo)簽 )full _ connected _ layer = mx . sym . fully connected(data = x,name = fc1 ,num _ hidden = 1)lro = mx . sym . linearregressionoutput(data = fully _ connect:0.005,;mom: 0.9 },編號(hào)_紀(jì)元=20,eval _ metric = mse ,)model.predict(eval_iter)。asnumpymetric = mx . metric . msemodel . score(eval _ iter,metric)在上面的代碼中,logging . basic config(filename = os . path . join(os . getcwd, log.txt ),level = logging.debug) #將日志保存為log.txt是指將日志保存為log.txt文件。
2.log.txt文檔如下:info :root:紀(jì)元[0]train-mse = 0.470638 info : root:紀(jì)元[0]。時(shí)間成本= 0.047 info :root:e poch[0]validation-mse = 73.642301 info :root:e poch[1]train-mse = 0.082987 info :root:e poch[1]時(shí)間成本= 0.047 info :rootecho 0-@ comt = 0.063 info :root: epoch[2]validation-mse = 23.743375 info :root: epoch[3]train-mse = 0.024459 info :root: epoch[3]時(shí)間成本= 0.063 info : rootecho 0--;農(nóng)業(yè)與農(nóng)業(yè)。;)#在導(dǎo)入matplotlib.pyplot或pylab之前。使圖表在服務(wù)器端不打開。導(dǎo)入mapplotlib.pyplot作為plt導(dǎo)入numpyas npd:文件=打開( log.txt , r )list = [] #搜索行,包括fil:行的準(zhǔn)確性m = re . search( ;火車-ms: n = re . search( ;[0].[0-9] ;,林:列表。append(n . group)# extract precision number file . clos: main引用2從matplotlib導(dǎo)入rcparamsimport matplotlib。pyplot as plt import re # #顯示中文rc params[ ;字體。家庭 ]= ;無襯線字體。;rc params[ ;字體。無襯線字體。;]=imsun,泰晤士新羅馬 讀取日志文件logfil: text = line file . clos:。*[0-9] ;對(duì)于驗(yàn)證集中每一批的數(shù)據(jù),t:的i train _ loss . append(float(i . split( ;step-loss : ;)[1].( -準(zhǔn)確性和。;)[0]))train _ acc =[]for i in all_list: train _ acc . append(float(i . split( ;-accuracy : ;)[1].( - val_loss: val _ loss . append(float(i . split( ;-val _ loss : ;)[1] .( -val _ accuracy : ;)[0]))val _ acc =[]for i in all_list: val _ acc . append(float(i . split( ;-val _ accuracy : ;)[1])# # plot plt . plot(train _ loss,label = 火車_損失 )plt.plot (val _ loss,label = val _ loss )plt.plot (train _ acc,label = 火車_ acc )plt.plot(。
日志另存為
了解更多python設(shè)置文件保存路徑(python保存信息)相關(guān)內(nèi)容請(qǐng)關(guān)注本站點(diǎn)。