Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to draw loss function in big data's Development

Shulou Source: shulou.com Published: 2022-06-01 13:02:18 09月17日 Update

This article will explain in detail how to draw the loss function in the development of big data. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

Contents under the folder:

Folder layout:

-- drawing the loss function curve-drwaLossFunction.py-- loadFromPickle.py-- drwaLossCurve_tensorboard.py-- drwaLossCurve_matplotlib.py

File: drwaLossFunction.py

# get the training generation and the corresponding loss value import osimport pickledef createPickleFiles ():''is used to generate three pickle files, which are used to save the training generation, confidence loss and location loss respectively.''myFolderPath = r'logs'files = os.listdir (myFolderPath) # list type element is the file name string type files.sort (key=lambda x:int (x [5:x.index (' -')]) Reverse=False) # sort by training generation loss4loc = list () # record location loss loss4cof = list () # record confidence loss record4epoch = list () # record training generation for item in files:info = item.split ('-') record4epoch.append (int (info [0] [5:])) loss4loc.append (float (info [1] [3:])) loss4cof.append (float (info [2] [4) :-4]) with open ('draw loss function curve / temporary file-EPOCH.pickle' 'wb') as file4epoch:pickle.dump (record4epoch,file4epoch) # Save generation information with open (' draw loss function curve / temporary file-LOSS4CONFIDENT.pickle','wb') as file4conf:pickle.dump (loss4cof,file4conf) # save confidence loss information with open ('draw loss function curve / temporary file-LOSS4LOCATION.pickle','wb') as file4loc:pickle.dump (loss4loc File4loc) # Save location loss information if _ _ name__ = ='_ main__':createPickleFiles ()

File: loadFromPickle.py

# load generation and corresponding loss import pickledef getInfo () from pickle file:''return three lists for saving generation, loss of confidence and loss of location' 'info = list () fileNames = [' draw loss function curve / temporary file-EPOCH.pickle',' draw loss function curve / temporary file-LOSS4CONFIDENT.pickle' 'draw loss function curve / temporary file-LOSS4LOCATION.pickle'] # name of three files for name in fileNames:with open (name,' rb') as f:item = pickle.load (f) info.append (item) return info if _ _ name__ ='_ main__':info = getInfo () # print (info [0]) # Generation # print (info [1]) # confidence loss # print (info [2]) # location loss

File: drwaLossCurve_tensorboard.py

From torch.utils.tensorboard import SummaryWriterimport loadFromPickleimport drwaLossFunctiondrwaLossFunction.createPickleFiles () info = loadFromPickle.getInfo () writer = SummaryWriter ('draw loss function curve / draw separately') for epoch, conf, loc in zip (* info): writer.add_scalar ('loss of confidence', conf, epoch) writer.add_scalar ('location loss', loc, epoch) writer.close () writer = SummaryWriter ('draw loss function curve / comparison of the three') for epoch, conf Loc in zip (* info): writer.add_scalars ('loss function', {'conf':conf,'loc':loc,'conf + loc': conf + loc}, epoch) writer.close () #''# tensorboard-- logdir= draws the loss function curve #''

File: drwaLossCurve_matplotlib.py

# use matplotlib to draw the loss function curve import drwaLossFunctionimport loadFromPickleimport matplotlibimport matplotlib.pyplot as plt matplotlib.rcParams ['font.family'] =' SimHei' # 'SimHei' #' STSong'matplotlib.rcParams ['font.size'] = 15 # modify the font size plt.rcParams [' axes.unicode_minus'] = False # to display the negative sign drwaLossFunction.createPickleFiles () info = loadFromPickle.getInfo () epoch, conf, loc = infoplt.plot (epoch, loc,'rx-.') normally Label=' location loss') plt.plot (epoch, conf, 'go-', label=' confidence loss') plt.xlabel ('training Generation: epoch') plt.ylabel (' loss value: loss') plt.legend (loc='upper right', frameon=True) plt.show () on "how to draw loss functions in big data's Development" this article ends here Hope that the above content can be helpful to you, so that you can learn more knowledge, if you think the article is good, please share it for more people to see.

Tags: Loss file function curve generation confidence positioning training three information article data development content folder more type good practical algebra Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker NVidia Linux Huawei Apple