Caffe原始碼解讀(一):caffe.proto(上)
阿新 • • 發佈:2019-02-05
caffe.proto檔案位於 ..\caffe-fast-rcnn\src\caffe\proto檔案目錄下 ,根目錄為 py_faster_rcnn資料夾
syntax = "proto2";
package caffe;
// repeated required optional
// 類似陣列 必要的 可選的
// Specifies the shape (dimensions) of a Blob.
message BlobShape {
repeated int64 dim = 1 [packed = true];
}
message BlobProto {
optional BlobShape shape = 7; //下文中替代4D描述符的結構
repeated float data = 5 [packed = true];
repeated float diff = 6 [packed = true];
repeated double double_data = 8 [packed = true];
repeated double double_diff = 9 [packed = true];
// 4D dimensions -- deprecated. Use "shape" instead.
// 4維的描述方式捨棄掉,改用"BlobShape"結構替代
optional int32 num = 1 [default = 0];
optional int32 channels = 2 [default = 0];
optional int32 height = 3 [default = 0];
optional int32 width = 4 [default = 0];
}
// The BlobProtoVector is simply a way to pass multiple blobproto instances
// around.
message BlobProtoVector {
repeated BlobProto blobs = 1;
}
//影象資料結構
message Datum {
optional int32 channels = 1;
optional int32 height = 2;
optional int32 width = 3;
// the actual image data, in bytes
//實際上以位元組儲存影象內容
optional bytes data = 4;
optional int32 label = 5;
// Optionally, the datum could also hold float data.
repeated float float_data = 6;
// If true data contains an encoded image that need to be decoded
optional bool encoded = 7 [default = false];
}
message FillerParameter {
// The filler type.
optional string type = 1 [default = 'constant'];
optional float value = 2 [default = 0]; // the value in constant filler
optional float min = 3 [default = 0]; // the min value in uniform filler
optional float max = 4 [default = 1]; // the max value in uniform filler
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.
//非零的輸出值以高斯濾波係數值的方式填充
//預設值為-1,不進行稀疏化
optional int32 sparse = 7 [default = -1];
// Normalize the filler variance by fan_in, fan_out, or their average.
// Applies to 'xavier' and 'msra' fillers.
//Protocol Buffer中的列舉和C++中類似
enum VarianceNorm {
FAN_IN = 0;
FAN_OUT = 1;
AVERAGE = 2;
}
optional VarianceNorm variance_norm = 8 [default = FAN_IN];
}
//網路引數
message NetParameter {
optional string name = 1; // consider giving the network a name
// The input blobs to the network.
repeated string input = 3;
// The shape of the input blobs.
repeated BlobShape input_shape = 8;
// 4D input dimensions -- deprecated. Use "shape" instead.
// If specified, for each input blob there should be four
// values specifying thenum, channels, height and width of the input blob.
// Thus, there should be a total of (4 * #input) numbers.
repeated int32 input_dim = 4;
// Whether the network will force every layer to carry out backward operation.
// If set False, then whether to carry out backward is determined
// automatically according to the net structure and learning rates.
//網路是否會迫使每一層都進行反向操作。
//如果設定為False,則根據網路結構和學習速率自動確定是否執行向後。
optional bool force_backward = 5 [default = false];
// The current "state" of the network, including thephase, level, and stage.
//當前的網路狀態有phase,level,stage三種狀態。
// Some layers may be included/excluded depending on this state and the states
// specified in the layers' include and exclude fields.
//根據此狀態和圖層的包含和非包含欄位中指定的狀態,可以包括/排除某些網路層。
optional NetState state = 6;
// Print debugging information about results while running Net::Forward,
// Net::Backward, and Net::Update.
//當執行前向網路,後向網路,更新網路的時候列印除錯資訊,預設不列印
optional bool debug_info = 7 [default = false];
// The layers that make up the net. Each of their configurations, including
// connectivity and behavior, is specified as a LayerParameter.
//很多層就構成了網.連線性和行為等配置引數構成了層引數.最後打印出來
repeated LayerParameter layer = 100; // ID 100 so layers are printed last.
// DEPRECATED: use 'layer' instead.
//此後改用'layer'結構
repeated V1LayerParameter layers = 2;
}
// NOTE
// Update the next available ID when you add a new SolverParameter field.
//注意
//當你新增新的求解器引數物件時,更新了新的可用ID
,為 ID 41 type
//
// SolverParameter next available ID: 41 (last added: type)
//求解器引數
message SolverParameter {
//////////////////////////////////////////////////////////////////////////////
// Specifying the train and test networks
//
// Exactly onetrain net must be specified using one of the following fields:
// train_net_param, train_net, net_param, net
// One or moretest nets may be specified using any of the following fields:
// test_net_param, test_net, net_param, net
// If more than one test net field is specified (e.g., both net and
// test_net are specified), they will be evaluated in the field order given
// above: (1) test_net_param, (2) test_net, (3) net_param/net.
//如果指定了多個測試網路欄位(例如,指定了net和test_net),則將以上面給出的欄位順序對它們求值:
//(1)test_net_param,(2)test_net,(3)net_param / net。
// A test_iter must be specified for each test_net.
// 必須為每個test_net 指定 test_iter
// A test_level and/or a test_stage may also be specified for each test_net.
// 還可以為每個test_net指定test_level和/或test_stage
//////////////////////////////////////////////////////////////////////////////
// Proto filename for the train net, possibly combined with one or more
// test nets.
//對於訓練網路的原型檔名可能由一個或者多個訓練網路組成。
optional string net = 24;
// Inline train net param, possibly combined with one or more test nets.
// 內聯訓練網路引數可能含有一個或者多個測試網路
optional NetParameter net_param = 25;
optional string train_net = 1; // Proto filename for the train net.
repeated string test_net = 2; // Proto filenames for the test nets.
optional NetParameter train_net_param = 21; // Inline train net params.
repeated NetParameter test_net_param = 22; // Inline test net params.
// The states for the train/test nets. Must be unspecified or
// specified once per net.
//要麼確定,要麼不確定,一旦確定,要麼全是測試網路要麼全是訓練網路
//
// By default, all states will have solver = true;
// train_state will have phase = TRAIN,
// and all test_state's will have phase = TEST.
// Other defaults are set according to the NetState defaults.
//預設的,所有求解器的狀態為真.訓練網路 phase
= TRAIN,測試網路phase
= TEST,
//其他情況有網路狀態的預設值決定
optional NetState train_state = 26;
repeated NetState test_state = 27;
// The number of iterations for each test net.
repeated int32 test_iter = 3;
// The number of iterations between two testing phases.
// 兩個測試階段之間的迭代次數。
optional int32 test_interval = 4 [default = 0];
optional bool test_compute_loss = 19 [default = false];
// If true, run an initial test pass before the first iteration,
// ensuring memory availability and printing the starting value of the loss.
// 若為真,在執行第一次迭代之前,先得執行初始化測試通過來確保有足夠儲存資源和列印初始值的loss資訊
optional bool test_initialization = 32 [default = true];
optional float base_lr = 5; // The base learning rate //基準學習率
// the number of iterations between displaying info. If display = 0, no info
// will be displayed.
// 顯示迭代之間展示資訊,如果display
= 0,則沒有資訊顯示
optional int32 display = 6;
// Display the loss averaged over the last average_loss iterations
// 顯示上次average_loss迭代的平均損失
optional int32 average_loss = 33 [default = 1];
optional int32 max_iter = 7; // the maximum number of iterations
// accumulate gradients over `iter_size` x `batch_size` instances
optional int32 iter_size = 36 [default = 1];
// The learning rate decay policy. The currently implemented learning rate
// policies are as follows:
// - fixed: always returnbase_lr.
// - step: returnbase_lr *gamma ^ (floor(iter
/ step))
// - exp: returnbase_lr *gamma ^
iter
// - inv: returnbase_lr * (1 +gamma *
iter) ^ (- power)
// - multistep: similar to step but it allows non uniform steps defined by
// stepvalue
// - poly: the effective learning rate follows a polynomial decay, to be
// zero by the max_iter. returnbase_lr (1 -iter/max_iter)
^ (power)
// - sigmoid: the effective learning rate follows a sigmod decay
// returnbase_lr ( 1/(1 + exp(-gamma * (iter
- stepsize))))
//
// where base_lr, max_iter, gamma, step, stepvalue and power are defined
// in the solver parameter protocol buffer, and iter is the current iteration.
optional string lr_policy = 8;
optional float gamma = 9; // The parameter to compute the learning rate.
optional float power = 10; // The parameter to compute the learning rate.
optional float momentum = 11; // The momentum value. //動量值?
optional float weight_decay = 12; // The weight decay. //權重衰減
// regularization types supported: L1 and L2
// controlled by weight_decay
//正則化方式支援:L1 和 L2
//由權值衰減變數控制
optional string regularization_type = 29 [default = "L2"]; //預設正則化方式為L2
// the stepsize for learning rate policy "step"
optional int32 stepsize = 13;
// the stepsize for learning rate policy "multistep"
repeated int32 stepvalue = 34;
// Set clip_gradients to >= 0 to clip parameter gradients to that L2 norm,
// whenever their actual L2 norm is larger.
// 設定clip_gradients大於零,只要它比實際的L2範數大,那麼它就等於L2範數
optional float clip_gradients = 35 [default = -1];
optional int32 snapshot = 14 [default = 0]; // The snapshot interval //snapshot:快照
optional string snapshot_prefix = 15; // The prefix for the snapshot. //prefix:字首
// whether to snapshot diff in the results or not. Snapshotting diff will help
// debugging but the final protocol buffer size will be much larger.
// 無論快照在結果中有無差值,快照的差值將會有助於除錯,但是最終的protocol buffer的尺寸會大很多
//
optional bool snapshot_diff = 16 [default = false];
enum SnapshotFormat {
HDF5 = 0;
BINARYPROTO = 1;
}
optional SnapshotFormat snapshot_format = 37 [default = BINARYPROTO];
// the mode solver will use: 0 for CPU and 1 for GPU. Use GPU in default.
enum SolverMode {
CPU = 0;
GPU = 1;
}
optional SolverMode solver_mode = 17 [default = GPU];
// the device_id will that be used in GPU mode. Use device_id = 0 in default.
optional int32 device_id = 18 [default = 0];
// If non-negative, the seed with which the Solver will initialize the Caffe
// random number generator -- useful for reproducible results. Otherwise,
// (and by default) initialize using a seed derived from the system clock.
optional int64 random_seed = 20 [default = -1];
// type of the solver
//求解器的型別 預設型別為SGD
optional string type = 40 [default = "SGD"]; //string 型別
// numerical stability for RMSProp, AdaGrad and AdaDelta and Adam
// 對於RMSProp, AdaGrad and
AdaDelta and Adam的數值穩定性預設閾值為 1e-8
optional float delta = 31 [default = 1e-8];
// parameters for the Adam solver
// 自適應動量求解器的衰減的預設取值為0.999
optional float momentum2 = 39 [default = 0.999];
// RMSProp decay value
// RMSProp的衰減值
// MeanSquare(t) = rms_decay*MeanSquare(t-1) + (1-rms_decay)*SquareGradient(t)
// 均方差的迭代求解關係
// MeanSquare(t) = rms_decay*MeanSquare(t-1) + (1-rms_decay)*SquareGradient(t)
optional float rms_decay = 38;
// If true, print information about the state of the net that may help with
// debugging learning problems.
// 是否列印除錯資訊,預設設定為否
optional bool debug_info = 23 [default = false];
// If false, don't save a snapshot after training finishes.
//如何設定為否,則不儲存每次訓練結束後的快照
optional bool snapshot_after_train = 28 [default = true];
// DEPRECATED: old solver enum types, use string instead
//捨棄舊的求解器列舉型別,使用string代替
enum SolverType {
SGD = 0;
NESTEROV = 1;
ADAGRAD = 2;
RMSPROP = 3;
ADADELTA = 4;
ADAM = 5;
}
// DEPRECATED: use type instead of solver_type
// 捨棄solver_type, 改用 type
optional SolverType solver_type = 30 [default = SGD];
}
// A message that stores the solver snapshots
message SolverState {
optional int32 iter = 1; // The current iteration //當前迭代
optional string learned_net = 2; // The file that stores the learned net. //儲存學習網路的檔案
repeated BlobProto history = 3; // The history for sgd solvers //sgd求解器的歷史記錄
optional int32 current_step = 4 [default = 0]; // The current step for learning rate //當前學習率的步進
}
//狀態列舉:訓練或者測試
enum Phase {
TRAIN = 0;
TEST = 1;
}
//網路狀態
message NetState {
optional Phase phase = 1 [default = TEST];
optional int32 level = 2 [default = 0];
repeated string stage = 3;
}
//Rule網路狀態
message NetStateRule {
// Set phase to require the NetState have a particular phase (TRAIN or TEST)
// to meet this rule.
optional Phase phase = 1;
// Set the minimum and/or maximum levels in which the layer should be used.
// Leave undefined to meet the rule regardless of level.
//設定Rule層需使用的最大與/或最小層,其他未定義的層需滿足rule規則。
optional int32 min_level = 2;
optional int32 max_level = 3;
// Customizable sets of stages to include or exclude.
//包含或排除使用者自定義集的狀態
// The net must have ALL of the specified stages and NONE of the specified
// "not_stage"s to meet the rule.
//網路必須含有所有具體的狀態,使用多層網路Rlue用於連線特定狀態
// (Use multiple NetStateRules to specify conjunctions of stages.)
repeated string stage = 4;
repeated string not_stage = 5;
}
// Specifies training parameters (multipliers on global learning constants,
// and the name and other settings used for weight sharing).
// 指定訓練引數(多層網路的全域性學習常數,以及用於權重分配的名稱和其他設定)。
message ParamSpec {
// The names of the parameter blobs -- useful for sharing parameters among
// layers, but never required otherwise. To share a parameter between two
// layers, give it a (non-empty) name.
// blobs引數的名稱-用於在圖層之間共享引數,但從不需要。為了共享一個引數給兩層網路,給它一個名字
optional string name = 1;
// Whether to require shared weights to have the same shape, or just the same
// count -- defaults to STRICT if unspecified.
// 無論是為了相同的shape而共享權值,或者僅僅只是計數。預設情況下如果未指定則為STRICT(限制)
//
optional DimCheckMode share_mode = 2;
enum DimCheckMode {
// STRICT (default) requires thatnum, channels, height, width each match.
//STRICT 限制 (預設)num,
channels, height, width為shape的四個引數,對應一一匹配
STRICT = 0;
// PERMISSIVE requires only the count (num*channels*height*width) to match.
// PERMISSIVE 允許 僅需要num*channels*height*width的數相同即可
PERMISSIVE = 1;
}
// The multiplier on the global learning rate for this parameter.
//該引數在全域性上的學習率的乘數
optional float lr_mult = 3 [default = 1.0];
// The multiplier on the global weight decay for this parameter.
// 該引數在全域性上的權值衰減的乘數