caffe 實戰系列:proto檔案格式以及含義解析:如何定義網路,如何設定網路引數(以AlexNet為例) 2016.3.30
(0)前言:
初學者往往不知道如何配置網路,或者面對這些引數卻無從下手不知道是什麼含義,下面我根據分析原始碼的經驗給出AlexNet的具體解釋,希望能夠給初學者一些定義網路上面的幫助此外還能夠知道如何找網路的引數,這些引數是如何設定的。 以AlexNet為例: 首先給出配置例項: name: "AlexNet" layer { # 資料層 name: "data" type: "Data" top: "data" top: "label" include { phase: TRAIN #include 表明這是在訓練階段才包括進去 } transform_param { # 對資料進行預處理,分別為做映象,設定crop的大小為227,以及減去均值檔案 mirror: true crop_size: 227 mean_file: "data/ilsvrc12/imagenet_mean.binaryproto" } data_param { # 設定資料的來源 source: "examples/imagenet/ilsvrc12_train_lmdb" batch_size: 256 backend: LMDB } } layer { name: "data" type: "Data" top: "data" top: "label" include { # 規定只在測試的時候使用該層 phase: TEST } transform_param { # 測試的時候就不做映象了 mirror: false crop_size: 227 mean_file: "data/ilsvrc12/imagenet_mean.binaryproto" } data_param { source: "examples/imagenet/ilsvrc12_val_lmdb" batch_size: 50 backend: LMDB } } layer { # 卷積層 name: "conv1" type: "Convolution" bottom: "data" top: "conv1" param { # 通用的有關於學習的引數,學習率和權重衰減率,這裡是兩個學習率是因為定義了卷積組,且大小為2,所以是兩個引數 lr_mult: 1 decay_mult: 1 } param { lr_mult: 2 decay_mult: 0 } convolution_param { # 卷積層的引數,卷積核以及偏置 num_output: 96 kernel_size: 11 stride: 4 # 但是conv1卻又沒有定義group:2,下面的卷積層倒是都定義了,所以這有點奇怪。 weight_filler { type: "gaussian" std: 0.01 } bias_filler { type: "constant" value: 0 } } } layer { # relu層 name: "relu1" type: "ReLU" bottom: "conv1" top: "conv1" } layer { # norm層 name: "norm1" type: "LRN" bottom: "conv1" top: "norm1" lrn_param { local_size: 5 alpha: 0.0001 beta: 0.75 } } layer { # 池化層 name: "pool1" type: "Pooling" bottom: "norm1" top: "pool1" pooling_param { pool: MAX kernel_size: 3 stride: 2 } } layer { name: "conv2" type: "Convolution" bottom: "pool1" top: "conv2" param { lr_mult: 1 decay_mult: 1 } param { lr_mult: 2 decay_mult: 0 } convolution_param { num_output: 256 pad: 2 kernel_size: 5 group: 2# 卷積組的大小為2 weight_filler { type: "gaussian" std: 0.01 } bias_filler { type: "constant" value: 0.1 } } } layer { name: "relu2" type: "ReLU" bottom: "conv2" top: "conv2" } layer { name: "norm2" type: "LRN" bottom: "conv2" top: "norm2" lrn_param { local_size: 5 alpha: 0.0001 beta: 0.75 } } layer { name: "pool2" type: "Pooling" bottom: "norm2" top: "pool2" pooling_param { pool: MAX kernel_size: 3 stride: 2 } } layer { name: "conv3" type: "Convolution" bottom: "pool2" top: "conv3" param { lr_mult: 1 decay_mult: 1 } param { lr_mult: 2 decay_mult: 0 } convolution_param { num_output: 384 pad: 1 kernel_size: 3 weight_filler { type: "gaussian" std: 0.01 } bias_filler { type: "constant" value: 0 } } } layer { name: "relu3" type: "ReLU" bottom: "conv3" top: "conv3" } layer { name: "conv4" type: "Convolution" bottom: "conv3" top: "conv4" param { lr_mult: 1 decay_mult: 1 } param { lr_mult: 2 decay_mult: 0 } convolution_param { num_output: 384 pad: 1 kernel_size: 3 group: 2# 卷積組的大小為2 weight_filler { type: "gaussian" std: 0.01 } bias_filler { type: "constant" value: 0.1 } } } layer { name: "relu4" type: "ReLU" bottom: "conv4" top: "conv4" } layer { name: "conv5" type: "Convolution" bottom: "conv4" top: "conv5" param { lr_mult: 1 decay_mult: 1 } param { lr_mult: 2 decay_mult: 0 } convolution_param { num_output: 256 pad: 1 kernel_size: 3 group: 2# 卷積組的大小為2 weight_filler { type: "gaussian" std: 0.01 } bias_filler { type: "constant" value: 0.1 } } } layer { name: "relu5" type: "ReLU" bottom: "conv5" top: "conv5" } layer { name: "pool5" type: "Pooling" bottom: "conv5" top: "pool5" pooling_param { pool: MAX kernel_size: 3 stride: 2 } } layer { name: "fc6" type: "InnerProduct" bottom: "pool5" top: "fc6" param { lr_mult: 1 decay_mult: 1 } param { lr_mult: 2 decay_mult: 0 } inner_product_param { num_output: 4096 weight_filler { type: "gaussian" std: 0.005 } bias_filler { type: "constant" value: 0.1 } } } layer { name: "relu6" type: "ReLU" bottom: "fc6" top: "fc6" } layer { name: "drop6" type: "Dropout" bottom: "fc6" top: "fc6" dropout_param { dropout_ratio: 0.5 } } layer { name: "fc7" type: "InnerProduct" bottom: "fc6" top: "fc7" param { lr_mult: 1 decay_mult: 1 } param { lr_mult: 2 decay_mult: 0 } inner_product_param { num_output: 4096 weight_filler { type: "gaussian" std: 0.005 } bias_filler { type: "constant" value: 0.1 } } } layer { name: "relu7" type: "ReLU" bottom: "fc7" top: "fc7" } layer { name: "drop7" type: "Dropout" bottom: "fc7" top: "fc7" dropout_param { dropout_ratio: 0.5 } } layer { name: "fc8" type: "InnerProduct" bottom: "fc7" top: "fc8" param { lr_mult: 1 decay_mult: 1 } param { lr_mult: 2 decay_mult: 0 } inner_product_param { num_output: 1000 weight_filler { type: "gaussian" std: 0.01 } bias_filler { type: "constant" value: 0 } } } layer { name: "accuracy" type: "Accuracy" bottom: "fc8" bottom: "label" top: "accuracy" include {# 測試階段才包括該層 phase: TEST } } layer { name: "loss" type: "SoftmaxWithLoss" bottom: "fc8" bottom: "label" top: "loss" }(1)資料輸入層預處理的引數transform_param的定義:
(2)資料輸入層中資料來源的引數data_param 定義
(3)卷積層中有關於學習的引數
(4)卷積層中有關於卷積的引數
接下來介紹與卷積相關的引數,即在卷積層定義的convolution_param。 這貨的定義是這樣的: message ConvolutionParameter { optional uint32 num_output = 1; // The number of outputs for the layer optional bool bias_term = 2 [default = true]; // whether to have bias terms // Pad, kernel size, and stride are all given as a single value for equal // dimensions in all spatial dimensions, or once per spatial dimension. // 是否padding repeated uint32 pad = 3; // The padding size; defaults to 0 // 核大小 repeated uint32 kernel_size = 4; // The kernel size // 步長 repeated uint32 stride = 6; // The stride; defaults to 1 // For 2D convolution only, the *_h and *_w versions may also be used to // specify both spatial dimensions. // 對於二維卷積來說是可以設定pad、kernel以及步長的寬度和高度不一樣的 optional uint32 pad_h = 9 [default = 0]; // The padding height (2D only) optional uint32 pad_w = 10 [default = 0]; // The padding width (2D only) optional uint32 kernel_h = 11; // The kernel height (2D only) optional uint32 kernel_w = 12; // The kernel width (2D only) optional uint32 stride_h = 13; // The stride height (2D only) optional uint32 stride_w = 14; // The stride width (2D only) // 每一個卷積組的大小 optional uint32 group = 5 [default = 1]; // The group size for group conv // 這就是初始化權重和偏置的引數啦 optional FillerParameter weight_filler = 7; // The filler for the weight optional FillerParameter bias_filler = 8; // The filler for the bias enum Engine { DEFAULT = 0; CAFFE = 1; CUDNN = 2; } // 使用CPU還是GPU計算 optional Engine engine = 15 [default = DEFAULT]; // The axis to interpret as "channels" when performing convolution. // Preceding dimensions are treated as independent inputs; // succeeding dimensions are treated as "spatial". // With (N, C, H, W) inputs, and axis == 1 (the default), we perform // N independent 2D convolutions, sliding C-channel (or (C/g)-channels, for // groups g>1) filters across the spatial axes (H, W) of the input. // With (N, C, D, H, W) inputs, and axis == 1, we perform // N independent 3D convolutions, sliding (C/g)-channels // filters across the spatial axes (D, H, W) of the input. // 通道數,如果該值是1,那麼如果資料是(N,C,H,W) // 那麼就進行N個獨立的二維卷積 // 如果資料是(N,C,D,H,W),那麼就進行三維卷積 optional int32 axis = 16 [default = 1]; // Whether to force use of the general ND convolution, even if a specific // implementation for blobs of the appropriate number of spatial dimensions // is available. (Currently, there is only a 2D-specific convolution // implementation; for input blobs with num_axes != 2, this option is // ignored and the ND implementation will be used.) // 強制使用通用的N維卷積方法 // 如果num_axes!=2就會使用N維卷積 optional bool force_nd_im2col = 17 [default = false]; }(5)卷積層中有關於初始化的引數
下面給出卷積層初始化的引數: message FillerParameter { // The filler type. // 初始化型別 optional string type = 1 [default = 'constant']; // 如果是常數初始化的話需要該值 optional float value = 2 [default = 0]; // the value in constant filler // 如果是均勻分佈初始化則需要min和max optional float min = 3 [default = 0]; // the min value in uniform filler optional float max = 4 [default = 1]; // the max value in uniform filler // 如果是高斯分佈初始化則需要mean和std optional float mean = 5 [default = 0]; // the mean value in Gaussian filler optional float std = 6 [default = 1]; // the std value in Gaussian filler // The expected number of non-zero output weights for a given input in // Gaussian filler -- the default -1 means don't perform sparsification. // 是否需要稀疏特性 optional int32 sparse = 7 [default = -1]; // Normalize the filler variance by fan_in, fan_out, or their average. // Applies to 'xavier' and 'msra' fillers. // 對於xavier和msra兩種權重初始化需要設定歸一化的型別是 // 使用扇入還是扇出還是扇入+扇出進行歸一化 enum VarianceNorm { FAN_IN = 0; FAN_OUT = 1; AVERAGE = 2; } optional VarianceNorm variance_norm = 8 [default = FAN_IN]; }(6)區域性歸一化層引數lrn_param的定義
(該層實際上證明已經沒啥用了,所以就不解釋了,一般也不用) // Message that stores parameters used by LRNLayer message LRNParameter { optional uint32 local_size = 1 [default = 5]; optional float alpha = 2 [default = 1.]; optional float beta = 3 [default = 0.75]; enum NormRegion { ACROSS_CHANNELS = 0; WITHIN_CHANNEL = 1; } optional NormRegion norm_region = 4 [default = ACROSS_CHANNELS]; optional float k = 5 [default = 1.]; }(7)全連線層
Caffe中也稱之為內積層,也有學習相關的引數以及初始化的引數:分別為param和inner_product_param 下面給出inner_product_param的定義,我們看到裡面定義了FillerParameter型別的weight_filler和bias_filler 另外還定義了axis,預設為1. message InnerProductParameter { optional uint32 num_output = 1; // The number of outputs for the layer optional bool bias_term = 2 [default = true]; // whether to have bias terms optional FillerParameter weight_filler = 3; // The filler for the weight optional FillerParameter bias_filler = 4; // The filler for the bias // The first axis to be lumped into a single inner product computation; // all preceding axes are retained in the output. // May be negative to index from the end (e.g., -1 for the last axis). optional int32 axis = 5 [default = 1]; }
(8)池化層的引數
pooling_param的定義如下:
message PoolingParameter {
enum PoolMethod { // 幾種池化方法
MAX = 0;
AVE = 1;
STOCHASTIC = 2;
}
optional PoolMethod pool = 1 [default = MAX]; // The pooling method
// Pad, kernel size, and stride are all given as a single value for equal
// dimensions in height and width or as Y, X pairs.
// 如果使用pad引數則認為是正方形的,如果使用pad_h和pad_w則認為是矩形的
// 同理kernel_size也是、stride也是
optional uint32 pad = 4 [default = 0]; // The padding size (equal in Y, X)
optional uint32 pad_h = 9 [default = 0]; // The padding height
optional uint32 pad_w = 10 [default = 0]; // The padding width
optional uint32 kernel_size = 2; // The kernel size (square)
optional uint32 kernel_h = 5; // The kernel height
optional uint32 kernel_w = 6; // The kernel width
optional uint32 stride = 3 [default = 1]; // The stride (equal in Y, X)
optional uint32 stride_h = 7; // The stride height
optional uint32 stride_w = 8; // The stride width
enum Engine {
DEFAULT = 0;
CAFFE = 1;
CUDNN = 2;
}
optional Engine engine = 11 [default = DEFAULT];
// If global_pooling then it will pool over the size of the bottom by doing
// kernel_h = bottom->height and kernel_w = bottom->width
optional bool global_pooling = 12 [default = false];
}
(9)dropout層的引數
dropout_param的定義如下: message DropoutParameter { optional float dropout_ratio = 1 [default = 0.5]; // dropout ratio } 就一個引數,就是丟棄的資料的概率(10)總結
各個引數的含義可以參考caffe.proto,碰到不懂的引數,或者考慮使用一些引數的時候也可以去找找你所用的層的引數是不是有。 此外:RELU沒有引數相關推薦
caffe 實戰系列:proto檔案格式以及含義解析:如何定義網路,如何設定網路引數(以AlexNet為例) 2016.3.30
(0)前言: 初學者往往不知道如何配置網路,或者面對這些引數卻無從下手不知道是什麼含義,下面我根據分析原始碼的經驗給出AlexNet的具體解釋,希望能夠給初學者一些定義網路上面的幫助此外還能夠知道如何找網路的引數,這些引數是如何設定的。 以AlexNet為例: 首先給出配
天地圖專題七:行政區域標記,熱力圖(以廣西為例)
天地圖方面的文章已很久不寫。 主要是因為上一個專案結束,基本就不用天地圖了。用百度地圖的可能更大一些。 最近上個專案甲方想搞一個類似熱力圖,熱點圖的東西。在天地圖API上沒有找到類似的直接畫熱力圖的介面,只好用了一些替代的方法。 天地圖行政區域,行政區劃直接介面也沒找到,用
Caffe實戰系列:最簡潔的Caffe安裝教程(以ubuntu14.04為例)
網上充斥各種安裝方法,但是都很繁瑣,特別是安裝顯示卡驅動以及依賴項,對於初學者不是很方便。我覺得采用包管理工具更方便因此寫下本文。 (1)首先安裝ssh,這樣能夠使用winscp和putty或者secure crt進行遠端連線,方便在windows下載東西傳到linu
Caffe實戰系列:實現自己Caffe網路層
#include "caffe/layers/image_scale_layer.hpp" #include "caffe/util/math_functions.hpp" #include <opencv2/opencv.hpp> namespace caffe { template <t
caffe 實戰系列:如何寫自己的資料層(以Deep Spatial Net為例)
一、前言 想寫自己的層,首先必須得在caffe.proto中定義自己層的引數,以便於在proto配置檔案中對引數進行配置啦什麼的,其次你還要在caffe.proto宣告你的層的引數是可選的,然後你得在caffe的include目錄下新增你自己層的hpp標頭檔案,以及在c
PDF檔案格式轉換攻略:PDF格式轉換圖片格式
關於PDF檔案格式的轉換大家有了解多少嗎?就比如將PDF格式轉換成圖片格式,可能之前大家對於PDF件大家都有了解到,辦公中我們經常遇到過。現在小編在這裡教大家如何將PDF格式轉換成圖片格式,有興趣的夥伴可以學著嘗試一下! 1、操作之前可以將轉換成圖片格式的PDF檔案另存到電腦桌面上,這樣便於在後面的操作。
WAV格式音訊檔案標頭檔案格式以及C++讀取
起始地址 佔用空間 本地址數字的含義 00H 4byte RIFF,資源交換檔案標誌。 04H 4byte 從下一個地址開始到檔案尾的總位元組數。高位位元組在後面,這
C++語言基礎 例程 案例:bmp檔案格式剖析
用程式讀出BMP檔案資訊//readbmp.h #ifndef READBMP_H_INCLUDED #define READBMP_H_INCLUDED typedef unsigned char BYTE; typedef unsigned short int UINT
INI檔案格式以及Java編碼實現讀取
/** * 去除ini檔案中的註釋,以";"或"#"開頭,順便去除UTF-8等檔案的BOM頭 * @param source * @return */ private static String removeIniComments(String source){ String resu
iOS 檢視ipa包中的檔案格式以及圖片
今天很好奇,為什麼現在提交appStore直接點一個submit按鈕就一切OK了呢,仔細研究一下ipa裡邊到底有什麼。export了一個ipa包,把字尾改為zip,雙擊解壓,解壓之後的資料夾如下圖: 由此我們可以看到解壓後Payload目錄下,是一個
pytorch系列 ---5以 linear_regression為例講解神經網路實現基本步驟以及解讀nn.Linear函式
本文主要講述最簡單的線性迴歸函式: y = w
TSM檔案格式及例項解析(四)——string的排列
目錄 引: 資料 簡析 Indexes: blocks: 關聯string 小結: TSM檔案格式現已基本明瞭,某些壓縮演算法有空再去研究一下。 引: 現在想知道未壓縮的檔案格式是怎樣。 但是翻遍官方配置文件 https://docs.influx
Docker系列之五:Volume 卷的使用——以Redis為例
簡介 卷在Docker裡非常重要,在系統之三中提到過,Docker利用聯合載入技術在root檔案系統層上載入更多的只讀檔案系統,這裡簡稱聯合檔案系統(Union File System),卷是在一個或者多個容器內被選定的目錄,可以繞過這個聯合檔案系統為Docker提供持久資
linux驅動由淺入深系列:塊裝置驅動之三(塊裝置驅動結構分析,以mmc為例)
linux驅動由淺入深系列:塊裝置驅動之一(高通eMMC分割槽例項)前一篇文章介紹了塊裝置驅動在linux框架張的位置關係,本文來分析一下驅動本身。塊裝置驅動的模型還是基本基於字元裝置驅動的,可以簡單理解為塊裝置僅僅增加了操作緩衝區,對使用者操作請求進行佇列重排。因此只在有了
idea軟體編碼已經設定好了為utf-8,但是svn中down下來的檔案格式本身不是utf-8的,此時開啟後會出現中文亂碼解決方法
我是個idea的忠實使用者,新公司的專案都是用eclipse做的,通過svn拉下程式碼後發現,註釋的內容裡,中文內容都是亂碼。問過專案負責人,說可能是GBK編碼。 但是,我通過idea的setting設定了編碼,試了5種編碼都沒用,中文內容還是亂碼。最後還是自己試出來解決方案。 詳細的原因請參考
CNCF CNI系列之一:淺談kubernetes的網路與CNI(以flannel為例)
一、前言kubernetes作為container的orchestration框架,主要的功能是在更高的層次對kubernetes服務和承載服務的實體(container)的部署、配置、可靠性進行管理,對應有namespace、POD、deployment、service等k
Caffe:如何執行一個pre-train過的神經網路——以VGG16為例
實驗環境: Ubuntu 14.04 所需環境: Caffe(GPU) Python2.7 JUPYTER NOTEBOOK 所需依賴包: numpy matplotlib skimage h5py 本次實驗採用的網路介紹: 在ICIR論
SUMO文件:軌跡檔案生成(以ns2為例)
Tutorials/Trace File Generation 這部分很多研究車輛網的網友提到,在這裡寫一下。 1、簡介 這部分教程描述瞭如何生成車輛軌跡檔案。除了sumo以外,工具Tools/TraceExporter將被使用。檔案需要python的執行,目前軌跡
博科SAN交換機學習筆記之二:配置檔案備份與韌體升級 作者 LiaoJL | 轉載時請務必以超連結形式標明文章原文連結和作者資訊及本版權宣告。 原文連結:http://www.liaojl.co
配置檔案恢復 當需要備份中恢復交換機配置時,可以通過configdownload命令將博科交換機的配置從遠端伺服器恢復到交換機。博科交換機支援將舊版本的配置檔案匯入新版本韌體的交換機,例如將v6.2.0的配置檔案匯入v6.3.0韌體版本的交換機,或者將v6.4.1 配置檔案匯入 v7.0.0 版本的交換機。
現代作業系統應用開發:UWP——檔案管理(二):FileManagement
背景簡介 我們的UWP程式想要讀寫本地的檔案的時候,往往會遇到許可權問題,這裡存在著兩個解決方法: 第一,電腦上的KnownFolder允許UWP程式直接訪問;這裡的KnowFolder指的是下面圖片中的資料夾: 關於這種方法可以參考第一篇部落格