網路架構的形象展示
在構建完網路後, 我們得到乙個xx_train.prototxt檔案, 該檔案中記錄著每層網路的輸入輸出及規格等引數, 在位址 左側拖入xx_train.ptototxt檔案, 按enter+shift組合鍵即可檢視網路模型圖, 非常具體形象.
以lenet為例
lenet的網路架構:# lenet
.prototxt
name: "lenet"
layer }}
layer
param
convolution_param
bias_filler
}}layer
}layer
param
convolution_param
bias_filler
}}layer
}layer
param
inner_product_param
bias_filler
}}layer
layer
param
inner_product_param
bias_filler
}}layer
網路模型引數的視覺化
在**_solver.prototxt檔案中, 通過設定snapshot引數來指定訓練多少次後就儲存一下當前訓練的模型, 設定snapshot_prefix引數來指定模型儲存的路徑及檔名, 如xx_iter_5000.caffemodel.
在xx.caffemodel檔案中存有各層的引數, 即net.params, 但是沒有資料(net.blobs). 生成caffemodel檔案的過程還會生成乙個相應的solverstate檔案, 這個solverstate檔案與caffemodel相似, 但包含一些資料, 比如模型名稱\當前迭代次數等.
兩者的功能區別:
caffemodel是在測試階段用於分類的
solverstate是用來恢復訓練的, 為防止意外終止而儲存的快照.
以lenet為例
import numpy as np
import matplotlib.pyplot as plt
import os, sys
import caffe
caffe_root='/home/keysen/caffe/'
os.chdir(caffe_root)
sys.path.insert(0, caffe_root+'python')
#顯示的圖表大小為 8,圖形的插值是以最近為原則,影象顏色是灰色
plt.rcparams['figure.figsize']=(8,8)
plt.rcparams['image.interpolation']='nearest'
plt.rcparams['image.cmap']='gray'
#設定網路為測試階段,並載入網路模型prototxt和已訓練網路caffemodel檔案
net = caffe.net(caffe_root + 'examples/mnist/lenet_train_test.prototxt',
caffe_root + 'examples/mnist/lenet_iter_10000.caffemodel',
caffe.test)
[(k, v[0].data.shape) for k, v in net.params.items()]
output:#視覺化的輔助函式
#take an array of shape (n, height, width) or (n, height, width, channels)用乙個格式是(數量,高,寬)或(數量,高,寬,頻道)的陣列
#編寫乙個函式,用於顯示各層的引數
defshow_feature
(data, padsize=1, padval=0):
data -= data.min()
data /= data.max()
# force the number of filters to be square
n = int(np.ceil(np.sqrt(data.shape[0])))
padding = ((0, n ** 2 - data.shape[0]), (0, padsize), (0, padsize)) + ((0, 0),) * (data.ndim - 3)
data = np.pad(data, padding, mode='constant', constant_values=(padval, padval))
print data.shape
# tile the filters into an image
data = data.reshape((n, n) + data.shape[1:]).transpose((0, 2, 1, 3) + tuple(range(4, data.ndim + 1)))
print data.shape
data = data.reshape((n * data.shape[1], n * data.shape[3]) + data.shape[4:])
print data.shape
plt.imshow(data)
plt.axis('off')
plt.show()
[(『conv1』, (50, 1, 5, 5)),(『conv2』, (20, 50, 5, 5)),
(『ip1』, (512, 320)),
(『ip2』, (10, 512))]
#根據每一層的名稱,選擇需要視覺化的層,可以視覺化filter(引數)
# the parameters are a list of [weights, biases],各層的特徵
# 第乙個卷積層,引數規模為(20,1,5,5),即20個5*5的1通道filter
# 第二個卷積層的權值引數,共有50*20個filter,每個filter大小為5*5
Caffe學習筆記 Caffe模型
乙個完整的深度學習系統最核心的兩個方面是資料和模型。深度學習模型通常由三部分引數組成 可學習引數 learnable parameter 又稱可訓練引數 神經網路權係數 權重,其數值由模型初始化引數 誤差反向傳播過程控制,一般不可人工干預。結構引數 archetecture parameter 包括...
caffe學習 學習初探
關於安裝 關於安裝裝置 關於學習 推薦大神denny的caffe學習總結 目前只看了一小小部分,講的通俗易懂,膜拜學習ing 將大神的mnist例項 測試數字,即識別1 9 總結重新跑一下,遇到的問題 importerror no module named skimage.io cannot use...
Caffe學習(未完)
在 caffe 中如何計算卷積 問題彙總待補充 caffe是大神賈揚清在加州伯克利大學博士期間開發的深度學習框架,在學界和工業界得到廣泛應用。caffe是cnn模型的非常好的框架,方便 易用 torch7是機器學習乙個非常好的框架,但是,學習曲線比caffe要陡峭一些。torch7更靈活,能搞定更多...