ファイル caffe.prototxt は、caffeのネットの構成を記述するための(protocol-bufferの)文法を定義するファイルである。
元々は型宣言のような形で厳密であるが、コメントを訳すと同時に内容を省略したり簡便に書き写したりしてみた。
Netの記述 (NetParameter)
name ネットの名前 layers 層(複数並べる)(LayerParameter) input 入力となるblobの指定(複数並べる) input_dim それぞれの入力blobのdim、各blobはnum, channels, height, widthの4つの次元を持つ。 たとえば、numが64(枚)、chが1(白黒)、heightとwidthが28(pixel)と28(pixel) force_backward = 5 [default = false] 層ごとにbackword propagationを行うか? falseの場合は文脈から自動的に決める。 state 現在のstate指定。phase(TRAINかTEST)とlevel(整数)とstate(文字列)の並びで指定できる。
Solverの記述 (SolverParameter)
// 学習用ネットtrain netはちょうど1つだけ記述し、以下のフィールドのどれか1つを用いて記述する // train_net_param, train_net, net_param, net // テスト用ネットtest netsは 、以下のフィールドのどれかを用いて記述する。(複数可→下記) // test_net_param, test_net, net_param, net // テスト用ネットが1つを超えて記述されるときは(たとえばnetフィールドとtest_netフィールド)、 // 上記のフィールドの順序((1) test_net_param, (2) test_net, (3) net_param/net.)に従って順次実行される。 // それぞれのtest_netについて、 test_iter が1つ指定されなければならない。 // それぞれのtest_netについて、1つのtest_level and/or 1つの test_stage を指定することができる。 net 学習用ネットのprotoファイル名、1つかそれ以上のテスト用ネットと一緒でも良い 。 net_param 学習ネット用パラメタのインライン記述、1つかそれ以上のテストネットと一緒でも良い。 train_net 学習用ネットのprotoファイル名 test_net テスト用ネットのprotoファイル名(0回以上繰り返し) train_net_param 学習用ネットの記述パラメタのインライン記述 test_net_param テスト用ネットの記述パラメタのインライン記述(0回以上繰り返し) // 学習/テストネットの状態state、指定しないか、ネットあたり1回だけのどちらか。 // 値はNetStateの内容、つまり3つ組 (phase, level, state) で、phaseはTRAINかTEST、levelは0,1,2..., stateは文字列 // デフォルトでは、すべての状態は solver = true。 // 学習状態 train_state では phase = TRAIN, すべてのテスト状態では phase = TEST。 // 他のデフォルト値は NetState のデフォルト値。 train_state 0か1回指定 test_state 0回以上指定 test_iter それぞれのテスト用ネットの繰り返し回数指定 (0回以上指定) test_interval [default = 0] 2つのテストphase間の繰り返し回数指定 test_compute_loss [default = false] (説明なし) test_initialization [default = true] trueなら最初の繰り返しの前にテストパスの初期化を行う これによってメモリの確保状況を確認し、lossの起動時の値を印刷する base_lr ベース学習レート(実数) // the number of iterations between displaying info. If display = 0, no info // will be displayed. display 情報を表示する間隔(繰り返しの回数)、0なら表示しない max_iter 繰り返しの最大数(上限) lr_policy 学習レート遅延のポリシー(名前の文字列) gamma 学習レート計算上のパラメタgamma power 学習レート計算上のパラメタpower momentum モーメント値(momentum) weight_decay 重み付けの遅延 regularization_type 重み遅延のレギュラ化のタイプ指定(L1かL2を指定) [default = "L2"] stepsize 学習レートのポリシーのステップのステップサイズ snapshot スナップショットを取る間隔 [default = 0](多分0だと取らない?) snapshot_prefix スナップショットファイルの置き場所(ファイル名prefix、文字列) snapshot_diff スナップショットをdiffモードで取る [default = false] // diffモードではデバッグが容易になるが、最終のプロトコルバッファ長がずっと大きくなる solver_mode solverがGPUかCPUか選択 [default = GPU] (このパラメタの値は文字列ではなく、enum型{CPU=0, GPU=1} device_id GPU使用時のdevice_id [default = 0]; random_seed [default = -1]、非負ならCaffeの乱数生成器の初期値指定で、実験繰り返し時に同一結果。負ならseedは時計の値 solver_type solverのタイプ [default = SGD]、enum{SGD=0, NESTEROV=1, ADAGRAD=2]のいずれか delta AdaGradを用いた際の数値安定化値(numerikal stability) [default = 1e-8] debug_info ネットの状態情報をプリントする [default = false] snapshot_after_train 学習が終わった後もスナップショットを取るか [default = true]、falseだと学習終了後は取らない
LayerTypeには以下のようなものがある
enum LayerType { NONE = 0; ABSVAL = 35; ACCURACY = 1; ARGMAX = 30; BNLL = 2; CONCAT = 3; CONTRASTIVE_LOSS = 37; CONVOLUTION = 4; DATA = 5; DROPOUT = 6; DUMMY_DATA = 32; EUCLIDEAN_LOSS = 7; ELTWISE = 25; FLATTEN = 8; HDF5_DATA = 9; HDF5_OUTPUT = 10; HINGE_LOSS = 28; IM2COL = 11; IMAGE_DATA = 12; INFOGAIN_LOSS = 13; INNER_PRODUCT = 14; LRN = 15; MEMORY_DATA = 29; MULTINOMIAL_LOGISTIC_LOSS = 16; MVN = 34; POOLING = 17; POWER = 26; RELU = 18; SIGMOID = 19; SIGMOID_CROSS_ENTROPY_LOSS = 27; SILENCE = 36; SOFTMAX = 20; SOFTMAX_LOSS = 21; SPLIT = 22; SLICE = 33; TANH = 23; WINDOW_DATA = 24; THRESHOLD = 31; }
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 height and width or as Y, X pairs. optional uint32 pad = 3 [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 = 4; // The kernel size (square) optional uint32 kernel_h = 11; // The kernel height optional uint32 kernel_w = 12; // The kernel width optional uint32 group = 5 [default = 1]; // The group size for group conv optional uint32 stride = 6 [default = 1]; // The stride (equal in Y, X) optional uint32 stride_h = 13; // The stride height optional uint32 stride_w = 14; // The stride width 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; } optional Engine engine = 15 [default = DEFAULT];
}
message DataParameter {
enum DB { LEVELDB = 0; LMDB = 1; } // Specify the data source. optional string source = 1; // Specify the batch size. optional uint32 batch_size = 4; // The rand_skip variable is for the data layer to skip a few data points // to avoid all asynchronous sgd clients to start at the same point. The skip // point would be set as rand_skip * rand(0,1). Note that rand_skip should not // be larger than the number of keys in the leveldb. optional uint32 rand_skip = 7 [default = 0]; optional DB backend = 8 [default = LEVELDB]; // DEPRECATED. See TransformationParameter. For data pre-processing, we can do // simple scaling and subtracting the data mean, if provided. Note that the // mean subtraction is always carried out before scaling. optional float scale = 2 [default = 1]; optional string mean_file = 3; // DEPRECATED. See TransformationParameter. Specify if we would like to randomly // crop an image. optional uint32 crop_size = 5 [default = 0]; // DEPRECATED. See TransformationParameter. Specify if we want to randomly mirror // data. optional bool mirror = 6 [default = false];
}
message ImageDataParameter {
// Specify the data source. optional string source = 1; // Specify the batch size. optional uint32 batch_size = 4; // The rand_skip variable is for the data layer to skip a few data points // to avoid all asynchronous sgd clients to start at the same point. The skip // point would be set as rand_skip * rand(0,1). Note that rand_skip should not // be larger than the number of keys in the leveldb. optional uint32 rand_skip = 7 [default = 0]; // Whether or not ImageLayer should shuffle the list of files at every epoch. optional bool shuffle = 8 [default = false]; // It will also resize images if new_height or new_width are not zero. optional uint32 new_height = 9 [default = 0]; optional uint32 new_width = 10 [default = 0]; // DEPRECATED. See TransformationParameter. For data pre-processing, we can do // simple scaling and subtracting the data mean, if provided. Note that the // mean subtraction is always carried out before scaling. optional float scale = 2 [default = 1]; optional string mean_file = 3; // DEPRECATED. See TransformationParameter. Specify if we would like to randomly // crop an image. optional uint32 crop_size = 5 [default = 0]; // DEPRECATED. See TransformationParameter. Specify if we want to randomly mirror // data. optional bool mirror = 6 [default = false];
}
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. 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];
}
message WindowDataParameter {
// Specify the data source. optional string source = 1; // For data pre-processing, we can do simple scaling and subtracting the // data mean, if provided. Note that the mean subtraction is always carried // out before scaling. optional float scale = 2 [default = 1]; optional string mean_file = 3; // Specify the batch size. optional uint32 batch_size = 4; // Specify if we would like to randomly crop an image. optional uint32 crop_size = 5 [default = 0]; // Specify if we want to randomly mirror data. optional bool mirror = 6 [default = false]; // Foreground (object) overlap threshold optional float fg_threshold = 7 [default = 0.5]; // Background (non-object) overlap threshold optional float bg_threshold = 8 [default = 0.5]; // Fraction of batch that should be foreground objects optional float fg_fraction = 9 [default = 0.25]; // Amount of contextual padding to add around a window // (used only by the window_data_layer) optional uint32 context_pad = 10 [default = 0]; // Mode for cropping out a detection window // warp: cropped window is warped to a fixed size and aspect ratio // square: the tightest square around the window is cropped optional string crop_mode = 11 [default = "warp"];
}
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 input weights for a given output in // Gaussian filler -- the default -1 means don't perform sparsification. optional int32 sparse = 7 [default = -1];
}
層(レイヤー)の記述 (LayerParameter)
bottom 下側のblobの名前(文字列) top 上側のblobの名前(文字列) name この層の名前(文字列) include この層がネットにいつ(どの状態stateで)取り込まれるかの指定 exclude この層がネットにいつ(どの状態stateで)取り込まれないかの指定 // 現在の状態(current NetState)で判定、複数のルール(ルールはNetStateRule参照)指定可、includeとexcludeの両方に指定(衝突)することは不可。 type 層のタイプ(上記のenumのうち1つ) blobs この層の数値的なパラメタを含むblobがある場合、ここで指定 repeated string param パラメータblobの名前(名前で指定できると繰り返し使用できて便利) blob_share_mode 共有重みが同じ形(STRICT、num, channel, height, widthが一致、デフォルト)か、 数のみ一致(PERMISSIVE、積num*channels*height*widthのみが一致)か blobs_lr globalな学習レートに掛ける(この層固有の?)率、1つのblobに指定したいならすべてのblobに指定する必要あり weight_decay globalな重み遅延に掛ける(この層固有の)率 loss_weight 対象となるそれぞれの上部blobに対する重み。それぞれの層で、各上位blobにデフォルト値(普通は0か1)を割り当てる accuracy_param accuracyを計算するとき、トップk個のスコアリングクラスと比較して正しいと数える、そのkの値。デフォルトは1 argmax_param trueだと(argmax,maxval)のペアを生成。デフォルトはfalse concat_param concat層だとconcatが起きる大きさdimensionを指定する必要。他のdimensionは下部blobと同じ必要。 デフォルト(値1)ではchannels dimensionでblobsをconcatenateする contrastive_loss_param 似ていない(dissimilar)ペアのマージン値(デフォルト1.0) convolution_param ConvolutionParameter(上記)の値 data_param DataParameter(上記)の値 dropout_param ドロップ率(デフォルト0.5) dummy_data_param これが使われる層はN個(N>=1)のダミーの上部blobを生成する。 eltwise_param エレメントワイズ操作の指定、PRODかSUMかMAX、SUM時にblobごとの係数指定、PROD時の傾き計算法指定 hdf5_data_param HDF5(階層的データをまとめたファイル形式)のパラメタ。ソースとバッチサイズを指定 hdf5_output_param HDF5の出力指定。ファイル名を指定 hinge_loss_param Hinge lossのNormがL1かL2かを指定 image_data_param イメージデータのパラメタの指定(上記) infogain_loss_param infogainマトリクスのソースを指定(文字列) inner_product_param 内積のパラメタ指定、この層の出力の数、バイアス項を持つか否か、重みのfiller、バイアスのfiller lrn_param LRNパラメタ。ローカルサイズ、アルファ値、ベータ値、NormRegionがチャネル間かチャネル内か。 memory_data_param メモリデータパラメタ。batch_size, channels, height, width mvn_param MVNのパラメタ。偏差を正規化するか(falseだと平均値のみ)、チャネル間で正規化するか(trueだとDNN-like MVN) pooling_param poolingのパラメタ(上記) power_param Power層はoutputs y = (shift + scale * x) ^ powerで計算するが、そのpower, scale, shiftの値 relu_param ReLUのパラメタ。(Rectifier nonlinearities improve neural network acoustic models. 2013) Allow non-zero slope for negative inputs to speed up optimization sigmoid_param sigmoid計算法?の選択 DEFAULTか CAFFEか CUDNN softmax_param softmax計算法?の選択 DEFAULTか CAFFEか CUDNN slice_param Slice層でどのdimensionを越えてスライスするか。accross num=0, accross channels=1、及びslice_point指定 tanh_param tanh計算法?の選択 DEFAULTか CAFFEか CUDNN threshold_param threshold値(デフォルト0) window_data_param ウィンドウデータのパラメタ(上記) transform_param データのプリプロセシングのパラメタ指定。プリプロセシングでは単純なscalingと平均値を引くことしかしない。 平均値減算は、scalingをしたのちに行う。 パラメタはスケールファクタscale、(ランダムな)ミラーをするか、(ランダムに)切り取りをするか(切り取りの大きさ指定) 平均値ファイル