日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人工智能 > Caffe >内容正文

Caffe

Caffe学习系列(19): 绘制loss和accuracy曲线

發布時間:2025/3/21 Caffe 155 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Caffe学习系列(19): 绘制loss和accuracy曲线 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

轉載自:

Caffe學習系列(19): 繪制loss和accuracy曲線 - denny402 - 博客園
http://www.cnblogs.com/denny402/p/5110204.html

如同前幾篇的可視化,這里采用的也是jupyter notebook來進行曲線繪制。

?

In?[1]: #加載必要的庫 import numpy as np import matplotlib.pyplot as plt %matplotlib inline import sys,os,caffe #設置當前目錄 caffe_root = '/home/bnu/caffe/' sys.path.insert(0, caffe_root + 'python') os.chdir(caffe_root) 設置求解器,和c++/caffe一樣,需要一個solver配置文件。 In?[2]: # set the solver prototxt caffe.set_device(0) caffe.set_mode_gpu() solver = caffe.SGDSolver('examples/cifar10/cifar10_quick_solver.prototxt') 如果不需要繪制曲線,只需要訓練出一個caffemodel, 直接調用solver.solve()就可以了。如果要繪制曲線,就需要把迭代過程中的值 保存下來,因此不能直接調用solver.solve(), 需要迭代。在迭代過程中,每迭代200次測試一次 In?[5]: %%time niter =4000 test_interval = 200 train_loss = np.zeros(niter) test_acc = np.zeros(int(np.ceil(niter / test_interval)))# the main solver loop for it in range(niter):solver.step(1) # SGD by Caffe# store the train losstrain_loss[it] = solver.net.blobs['loss'].datasolver.test_nets[0].forward(start='conv1')if it % test_interval == 0:acc=solver.test_nets[0].blobs['accuracy'].dataprint 'Iteration', it, 'testing...','accuracy:',acctest_acc[it // test_interval] = acc Iteration 0 testing... accuracy: 0.10000000149 Iteration 200 testing... accuracy: 0.419999986887 Iteration 400 testing... accuracy: 0.479999989271 Iteration 600 testing... accuracy: 0.540000021458 Iteration 800 testing... accuracy: 0.620000004768 Iteration 1000 testing... accuracy: 0.629999995232 Iteration 1200 testing... accuracy: 0.649999976158 Iteration 1400 testing... accuracy: 0.660000026226 Iteration 1600 testing... accuracy: 0.660000026226 Iteration 1800 testing... accuracy: 0.670000016689 Iteration 2000 testing... accuracy: 0.709999978542 Iteration 2200 testing... accuracy: 0.699999988079 Iteration 2400 testing... accuracy: 0.75 Iteration 2600 testing... accuracy: 0.740000009537 Iteration 2800 testing... accuracy: 0.769999980927 Iteration 3000 testing... accuracy: 0.75 Iteration 3200 testing... accuracy: 0.699999988079 Iteration 3400 testing... accuracy: 0.740000009537 Iteration 3600 testing... accuracy: 0.72000002861 Iteration 3800 testing... accuracy: 0.769999980927 CPU times: user 41.7 s, sys: 54.2 s, total: 1min 35s Wall time: 1min 18s 繪制train過程中的loss曲線,和測試過程中的accuracy曲線。 In?[6]: print test_acc _, ax1 = plt.subplots() ax2 = ax1.twinx() ax1.plot(np.arange(niter), train_loss) ax2.plot(test_interval * np.arange(len(test_acc)), test_acc, 'r') ax1.set_xlabel('iteration') ax1.set_ylabel('train loss') ax2.set_ylabel('test accuracy') [ 0.1 0.41999999 0.47999999 0.54000002 0.62 0.630.64999998 0.66000003 0.66000003 0.67000002 0.70999998 0.699999990.75 0.74000001 0.76999998 0.75 0.69999999 0.740000010.72000003 0.76999998] Out[6]: <matplotlib.text.Text at 0x7fd1297bfcd0>

《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀

總結

以上是生活随笔為你收集整理的Caffe学习系列(19): 绘制loss和accuracy曲线的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。