caffe proto文件,和配置文件

要看caffe源码,我认为首先应该看的就是caffe.proto。 
它位于…\src\caffe\proto目录下,在这个文件夹下还有一个.pb.cc和一个.pb.h文件,这两个文件都是由caffe.proto编译而来的。 
在caffe.proto中定义了很多结构化数据,包括:

  • BlobProto
  • BlobShape
  • BlobProtoVector
  • Datum
  • FillerParameter
  • NetParameter
  • SolverParameter
  • SolverState
  • NetStateRule
  • ParamSpec
  • LayerParameter
  • TransformationParameter
  • optional AccuracyParameter accuracy_param = 102;
      optional ArgMaxParameter argmax_param = 103;
      optional ConcatParameter concat_param = 104;
      optional ContrastiveLossParameter contrastive_loss_param = 105;
      optional ConvolutionParameter convolution_param = 106;
      optional DataParameter data_param = 107;
      optional DropoutParameter dropout_param = 108;
      optional DummyDataParameter dummy_data_param = 109;
      optional EltwiseParameter eltwise_param = 110;
      optional ExpParameter exp_param = 111;
      optional HDF5DataParameter hdf5_data_param = 112;
      optional HDF5OutputParameter hdf5_output_param = 113;
      optional HingeLossParameter hinge_loss_param = 114;
      optional ImageDataParameter image_data_param = 115;
      optional InfogainLossParameter infogain_loss_param = 116;
      optional InnerProductParameter inner_product_param = 117;
      optional LRNParameter lrn_param = 118;
      optional MemoryDataParameter memory_data_param = 119;
      optional MVNParameter mvn_param = 120;
      optional PoolingParameter pooling_param = 121;
      optional PowerParameter power_param = 122;
      optional PReLUParameter prelu_param = 131;
      optional PythonParameter python_param = 130;
      optional ReLUParameter relu_param = 123;
      optional SigmoidParameter sigmoid_param = 124;
      optional SoftmaxParameter softmax_param = 125;
      optional SliceParameter slice_param = 126;
      optional TanHParameter tanh_param = 127;
      optional ThresholdParameter threshold_param = 128;
      optional WindowDataParameter window_data_param = 129;
  • V0LayerParameter

正文

一、什么是protocol buffer

以下内容摘自:Google Protocol Buffer 的使用和原理 
强烈推荐另外一篇极好的博文是:Protocol Buffer技术详解(C++实例)

简介

什么是 Google Protocol Buffer? 假如您在网上搜索,应该会得到类似这样的文字介绍: 
Google Protocol Buffer( 简称 Protobuf) 是 Google 公司内部的混合语言数据标准,目前已经正在使用的有超过 48,162 种报文格式定义和超过 12,183 个 .proto 文件。他们用于 RPC 系统和持续数据存储系统。 
Protocol Buffers 是一种轻便高效的结构化数据存储格式,可以用于结构化数据串行化,或者说序列化。它很适合做数据存储或 RPC 数据交换格式。可用于通讯协议、数据存储等领域的语言无关、平台无关、可扩展的序列化结构数据格式。目前提供了 C++、Java、Python 三种语言的 API。 
或许您和我一样,在第一次看完这些介绍后还是不明白 Protobuf 究竟是什么,那么我想一个简单的例子应该比较有助于理解它。

一个简单的例子

安装 Google Protocol Buffer 
在网站 http://code.google.com/p/protobuf/downloads/list上可以下载 Protobuf 的源代码。然后解压编译安装便可以使用它了。 
安装步骤如下所示:

<code class="hljs go has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"> tar -xzf protobuf<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">-2.1</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.0</span>.tar.gz 
 cd protobuf<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">-2.1</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.0</span> 
 ./configure --prefix=$INSTALL_DIR 
 <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">make</span> 
 <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">make</span> check 
 <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">make</span> install</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li></ul>

关于简单例子的描述

我打算使用 Protobuf 和 C++ 开发一个十分简单的例子程序。 
该程序由两部分组成。第一部分被称为 Writer,第二部分叫做 Reader。 
Writer 负责将一些结构化的数据写入一个磁盘文件,Reader 则负责从该磁盘文件中读取结构化数据并打印到屏幕上。 
准备用于演示的结构化数据是 HelloWorld,它包含两个基本数据:

  • ID,为一个整数类型的数据
  • Str,这是一个字符串

书写 .proto 文件

首先我们需要编写一个 proto 文件,定义我们程序中需要处理的结构化数据,在 protobuf 的术语中,结构化数据被称为 Message。proto 文件非常类似 java 或者 C 语言的数据定义。代码清单 1 显示了例子应用中的 proto 文件内容。 
清单 1. proto 文件

<code class="hljs go has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">package</span> lm; 
 message helloworld 
 { 
    required <span class="hljs-typename" style="color: rgb(102, 0, 102); box-sizing: border-box;">int32</span>     id =<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;"> 1</span>;  <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">// ID </span>
    required <span class="hljs-typename" style="color: rgb(102, 0, 102); box-sizing: border-box;">string</span>    str =<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;"> 2</span>;  <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">// str </span>
    optional <span class="hljs-typename" style="color: rgb(102, 0, 102); box-sizing: border-box;">int32</span>     opt =<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;"> 3</span>;  <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//optional field </span>
 }</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li></ul>

一个比较好的习惯是认真对待 proto 文件的文件名。比如将命名规则定于 
packageName.MessageName.proto 
在上例中,package 名字叫做 lm,定义了一个消息 helloworld,该消息有三个成员,类型为 int32 的 id,另一个为类型为 string 的成员 str。opt 是一个可选的成员,即消息中可以不包含该成员。

编译 .proto 文件

写好 proto 文件之后就可以用 Protobuf 编译器将该文件编译成目标语言了。本例中我们将使用 C++。 
假设您的 proto 文件存放在 $SRC_DIR 下面,您也想把生成的文件放在同一个目录下,则可以使用如下命令:

<code class="hljs lasso has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">protoc <span class="hljs-attribute" style="box-sizing: border-box;">-I</span><span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">=</span><span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$SRC_DIR</span> <span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">--</span>cpp_out<span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">=</span><span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$DST_DIR</span> <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$SRC_DIR</span>/addressbook<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">.</span>proto</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>

命令将生成两个文件: 
lm.helloworld.pb.h , 定义了 C++ 类的头文件 
lm.helloworld.pb.cc , C++ 类的实现文件 
在生成的头文件中,定义了一个 C++ 类 helloworld,后面的 Writer 和 Reader 将使用这个类来对消息进行操作。诸如对消息的成员进行赋值,将消息序列化等等都有相应的方法。

编写 writer 和 Reader

如前所述,Writer将把一个结构化数据写入磁盘,以便其他人来读取。假如我们不使用 Protobuf,其实也有许多的选择。一个可能的方法是将数据转换为字符串,然后将字符串写入磁盘。转换为字符串的方法可以使用sprintf(),这非常简单。数字123可以变成字符串“123”。 
这样做似乎没有什么不妥,但是仔细考虑一下就会发现,这样的做法对写 Reader 的那个人的要求比较高,Reader 的作者必须了 Writer 的细节。比如”123”可以是单个数字 123,但也可以是三个数字 1,2 和 3,等等。这么说来,我们还必须让 Writer 定义一种分隔符一样的字符,以便 Reader 可以正确读取。但分隔符也许还会引起其他的什么问题。最后我们发现一个简单的 Helloworld 也需要写许多处理消息格式的代码。 
如果使用 Protobuf,那么这些细节就可以不需要应用程序来考虑了。 
使用 Protobuf,Writer 的工作很简单,需要处理的结构化数据由 .proto 文件描述,经过上一节中的编译过程后,该数据化结构对应了一个 C++ 的类,并定义在 lm.helloworld.pb.h 中。对于本例,类名为 lm::helloworld。 
Writer 需要 include 该头文件,然后便可以使用这个类了。 
现在,在 Writer 代码中,将要存入磁盘的结构化数据由一个 lm::helloworld 类的对象表示,它提供了一系列的 get/set 函数用来修改和读取结构化数据中的数据成员,或者叫 field。 
当我们需要将该结构化数据保存到磁盘上时,类 lm::helloworld 已经提供相应的方法来把一个复杂的数据变成一个字节序列,我们可以将这个字节序列写入磁盘。 
对于想要读取这个数据的程序来说,也只需要使用类 lm::helloworld 的相应反序列化方法来将这个字节序列重新转换会结构化数据。这同我们开始时那个“123”的想法类似,不过 Protobuf 想的远远比我们那个粗糙的字符串转换要全面,因此,我们不如放心将这类事情交给 Protobuf 吧。 
程序清单 2 演示了 Writer 的主要代码,您一定会觉得很简单吧? 
清单 2. Writer 的主要代码

<code class="hljs lasso has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"> <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">#include</span> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"lm.helloworld.pb.h"</span>
…

 int main(<span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">void</span>) 
 { 

  lm<span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box;">::helloworld</span> msg1; 
  msg1<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">.</span>set_id(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">101</span>); 
  msg1<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">.</span>set_str(“hello”); 

  <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">// Write the new address book back to disk. </span>
  fstream output(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"./log"</span>, ios<span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box;">::out</span> <span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">|</span> ios<span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box;">::trunc</span> <span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">|</span> ios<span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box;">::binary</span>); 

  <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> (<span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">!</span>msg1<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">.</span>SerializeToOstream(<span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">&</span>output)) { 
      cerr <span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;"><<</span> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"Failed to write msg."</span> <span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;"><<</span> endl; 
      <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">return</span> <span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">-</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>; 
  }         
  <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">return</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>; 
 }</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li><li style="box-sizing: border-box; padding: 0px 5px;">16</li><li style="box-sizing: border-box; padding: 0px 5px;">17</li><li style="box-sizing: border-box; padding: 0px 5px;">18</li><li style="box-sizing: border-box; padding: 0px 5px;">19</li></ul>

Msg1 是一个 helloworld 类的对象,set_id() 用来设置 id 的值。SerializeToOstream 将对象序列化后写入一个 fstream 流。 
代码清单 3 列出了 reader 的主要代码。 
清单 3. Reader

<code class="hljs cpp has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"> <span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">#include "lm.helloworld.pb.h" </span>
…
 <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">void</span> ListMsg(<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">const</span> lm::helloworld & msg) { 
  <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">cout</span> << msg.id() << endl; 
  <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">cout</span> << msg.str() << endl; 
 } 

 <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> main(<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> argc, <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">char</span>* argv[]) { 

  lm::helloworld msg1; 

  { 
    fstream input(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"./log"</span>, ios::in | ios::binary); 
    <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> (!msg1.ParseFromIstream(&input)) { 
      <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">cerr</span> << <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"Failed to parse address book."</span> << endl; 
      <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">return</span> -<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>; 
    } 
  } 

  ListMsg(msg1); 
  … 
 }</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li><li style="box-sizing: border-box; padding: 0px 5px;">16</li><li style="box-sizing: border-box; padding: 0px 5px;">17</li><li style="box-sizing: border-box; padding: 0px 5px;">18</li><li style="box-sizing: border-box; padding: 0px 5px;">19</li><li style="box-sizing: border-box; padding: 0px 5px;">20</li><li style="box-sizing: border-box; padding: 0px 5px;">21</li><li style="box-sizing: border-box; padding: 0px 5px;">22</li></ul>

同样,Reader 声明类 helloworld 的对象 msg1,然后利用 ParseFromIstream 从一个 fstream 流中读取信息并反序列化。此后,ListMsg 中采用 get 方法读取消息的内部信息,并进行打印输出操作。 
运行结果 
运行 Writer 和 Reader 的结果如下:

<code class="hljs tex has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-command" style="box-sizing: border-box; color: rgb(0, 0, 136);">\></span>writer 
<span class="hljs-command" style="box-sizing: border-box; color: rgb(0, 0, 136);">\></span>reader 
101 
Hello</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li></ul>

Reader 读取文件 log 中的序列化信息并打印到屏幕上。本文中所有的例子代码都可以在附件中下载。您可以亲身体验一下。 
这个例子本身并无意义,但只要您稍加修改就可以将它变成更加有用的程序。比如将磁盘替换为网络 socket,那么就可以实现基于网络的数据交换任务。而存储和交换正是 Protobuf 最有效的应用领域。

二、caffe.proto中的几个重要数据类型

看完了上面关于protocol buffer的介绍,大家应该可以知道其实caffe.pb.cc里面的东西都是从caffe.proto编译而来的,无非就是一些关于这些数据结构(类)的标准化操作,比如

<code class="hljs cs has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">  <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">void</span> CopyFrom();
  <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">void</span> MergeFrom();
  <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">void</span> CopyFrom();
  <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">void</span> MergeFrom;
  <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">void</span> Clear();
  <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">bool</span> IsInitialized() <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">const</span>;
  <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> ByteSize() <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">const</span>;
  <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">bool</span> MergePartialFromCodedStream();
  <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">void</span> SerializeWithCachedSizes() <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">const</span>;
  SerializeWithCachedSizesToArray() <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">const</span>;
  <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> GetCachedSize()
  <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">void</span> SharedCtor();
  <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">void</span> SharedDtor();
  <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">void</span> SetCachedSize() <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">const</span>;</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li></ul>

<0> BlobProto

<code class="hljs vala has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">message BlobProto {<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//blob的属性以及blob中的数据(data\diff)</span>
  optional <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int32</span> num = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span> [<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">default</span> = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>];
  optional <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int32</span> channels = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span> [<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">default</span> = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>];
  optional <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int32</span> height = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span> [<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">default</span> = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>];
  optional <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int32</span> width = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">4</span> [<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">default</span> = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>];
  repeated <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">float</span> data = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">5</span> [packed = <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">true</span>];
  repeated <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">float</span> diff = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">6</span> [packed = <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">true</span>];
}</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li></ul>

<1> Datum

<code class="hljs vala has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">  message Datum {
  optional <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int32</span> channels = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>;
  optional <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int32</span> height = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>;
  optional <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int32</span> width = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span>;
  optional bytes data = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">4</span>;<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//真实的图像数据,以字节存储(bytes)</span>
  optional <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int32</span> label = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">5</span>;
  repeated <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">float</span> float_data = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">6</span>;<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//datum也能存float类型的数据(float)</span>
}</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li></ul>

<2> LayerParameter

<code class="hljs cs has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">message LayerParameter {
  repeated <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">string</span> bottom = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>; <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//输入的blob的名字(string)</span>
  repeated <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">string</span> top = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span>; <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//输出的blob的名字(string)</span>
  optional <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">string</span> name = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">4</span>; <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//层的名字</span>
  <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">enum</span> LayerType { <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//层的枚举(enum,和c++中的enum一样)</span>
    NONE = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>;
    ACCURACY = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>;
    BNLL = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>;
    CONCAT = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span>;
    CONVOLUTION = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">4</span>;
    DATA = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">5</span>;
    DROPOUT = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">6</span>;
    EUCLIDEAN_LOSS = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">7</span>;
    ELTWISE_PRODUCT = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">25</span>;
    FLATTEN = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">8</span>;
    HDF5_DATA = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">9</span>;
    HDF5_OUTPUT = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">10</span>;
    HINGE_LOSS = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">28</span>;
    IM2COL = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">11</span>;
    IMAGE_DATA = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">12</span>;
    INFOGAIN_LOSS = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">13</span>;
    INNER_PRODUCT = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">14</span>;
    LRN = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">15</span>;
    MEMORY_DATA = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">29</span>;
    MULTINOMIAL_LOGISTIC_LOSS = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">16</span>;
    POOLING = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">17</span>;
    POWER = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">26</span>;
    RELU = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">18</span>;
    SIGMOID = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">19</span>;
    SIGMOID_CROSS_ENTROPY_LOSS = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">27</span>;
    SOFTMAX = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">20</span>;
    SOFTMAX_LOSS = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">21</span>;
    SPLIT = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">22</span>;
    TANH = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">23</span>;
    WINDOW_DATA = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">24</span>;
  }
  optional LayerType type = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">5</span>; <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">// 层的类型</span>
  repeated BlobProto blobs = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">6</span>; <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//blobs的数值参数</span>
  repeated <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">float</span> blobs_lr = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">7</span>; <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//学习速率(repeated),如果你想那个设置一个blob的学习速率,你需要设置所有blob的学习速率。</span>
  repeated <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">float</span> weight_decay = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">8</span>; <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//权值衰减(repeated)</span>

  <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">// 相对于某一特定层的参数(optional)</span>
  optional ConcatParameter concat_param = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">9</span>;
  optional ConvolutionParameter convolution_param = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">10</span>;
  optional DataParameter data_param = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">11</span>;
  optional DropoutParameter dropout_param = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">12</span>;
  optional HDF5DataParameter hdf5_data_param = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">13</span>;
  optional HDF5OutputParameter hdf5_output_param = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">14</span>;
  optional ImageDataParameter image_data_param = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">15</span>;
  optional InfogainLossParameter infogain_loss_param = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">16</span>;
  optional InnerProductParameter inner_product_param = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">17</span>;
  optional LRNParameter lrn_param = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">18</span>;
  optional MemoryDataParameter memory_data_param = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">22</span>;
  optional PoolingParameter pooling_param = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">19</span>;
  optional PowerParameter power_param = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">21</span>;
  optional WindowDataParameter window_data_param = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">20</span>;
  optional V0LayerParameter layer = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>;
}</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li><li style="box-sizing: border-box; padding: 0px 5px;">16</li><li style="box-sizing: border-box; padding: 0px 5px;">17</li><li style="box-sizing: border-box; padding: 0px 5px;">18</li><li style="box-sizing: border-box; padding: 0px 5px;">19</li><li style="box-sizing: border-box; padding: 0px 5px;">20</li><li style="box-sizing: border-box; padding: 0px 5px;">21</li><li style="box-sizing: border-box; padding: 0px 5px;">22</li><li style="box-sizing: border-box; padding: 0px 5px;">23</li><li style="box-sizing: border-box; padding: 0px 5px;">24</li><li style="box-sizing: border-box; padding: 0px 5px;">25</li><li style="box-sizing: border-box; padding: 0px 5px;">26</li><li style="box-sizing: border-box; padding: 0px 5px;">27</li><li style="box-sizing: border-box; padding: 0px 5px;">28</li><li style="box-sizing: border-box; padding: 0px 5px;">29</li><li style="box-sizing: border-box; padding: 0px 5px;">30</li><li style="box-sizing: border-box; padding: 0px 5px;">31</li><li style="box-sizing: border-box; padding: 0px 5px;">32</li><li style="box-sizing: border-box; padding: 0px 5px;">33</li><li style="box-sizing: border-box; padding: 0px 5px;">34</li><li style="box-sizing: border-box; padding: 0px 5px;">35</li><li style="box-sizing: border-box; padding: 0px 5px;">36</li><li style="box-sizing: border-box; padding: 0px 5px;">37</li><li style="box-sizing: border-box; padding: 0px 5px;">38</li><li style="box-sizing: border-box; padding: 0px 5px;">39</li><li style="box-sizing: border-box; padding: 0px 5px;">40</li><li style="box-sizing: border-box; padding: 0px 5px;">41</li><li style="box-sizing: border-box; padding: 0px 5px;">42</li><li style="box-sizing: border-box; padding: 0px 5px;">43</li><li style="box-sizing: border-box; padding: 0px 5px;">44</li><li style="box-sizing: border-box; padding: 0px 5px;">45</li><li style="box-sizing: border-box; padding: 0px 5px;">46</li><li style="box-sizing: border-box; padding: 0px 5px;">47</li><li style="box-sizing: border-box; padding: 0px 5px;">48</li><li style="box-sizing: border-box; padding: 0px 5px;">49</li><li style="box-sizing: border-box; padding: 0px 5px;">50</li><li style="box-sizing: border-box; padding: 0px 5px;">51</li><li style="box-sizing: border-box; padding: 0px 5px;">52</li><li style="box-sizing: border-box; padding: 0px 5px;">53</li><li style="box-sizing: border-box; padding: 0px 5px;">54</li><li style="box-sizing: border-box; padding: 0px 5px;">55</li><li style="box-sizing: border-box; padding: 0px 5px;">56</li><li style="box-sizing: border-box; padding: 0px 5px;">57</li><li style="box-sizing: border-box; padding: 0px 5px;">58</li></ul>

<3> NetParameter

<code class="hljs vala has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">message NetParameter {
  optional <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">string</span> name = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>;<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//网络的名字</span>
  repeated LayerParameter layers = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>; <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//repeated类似于数组</span>
  repeated <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">string</span> input = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span>;<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//输入层blob的名字</span>
  repeated <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int32</span> input_dim = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">4</span>;<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//输入层blob的维度,应该等于(4*#input)</span>
  optional <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">bool</span> force_backward = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">5</span> [<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">default</span> = <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">false</span>];<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//网络是否进行反向传播。如果设置为否,则由网络的结构和学习速率来决定是否进行反向传播。</span>
}</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li></ul>

<4> SolverParameter

<code class="hljs vala has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">message SolverParameter {
  optional <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">string</span> train_net = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>; <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">// 训练网络的proto file</span>
  optional <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">string</span> test_net = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>; <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">// 测试网络的proto file</span>
  optional <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int32</span> test_iter = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span> [<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">default</span> = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>]; <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">// 每次测试时的迭代次数</span>
  optional <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int32</span> test_interval = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">4</span> [<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">default</span> = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>]; <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">// 两次测试的间隔迭代次数</span>
  optional <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">bool</span> test_compute_loss = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">19</span> [<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">default</span> = <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">false</span>];
  optional <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">float</span> base_lr = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">5</span>; <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">// 基本学习率</span>
  optional <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int32</span> display = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">6</span>; <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">// 两次显示的间隔迭代次数</span>
  optional <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int32</span> max_iter = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">7</span>; <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">// 最大迭代次数</span>
  optional <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">string</span> lr_policy = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">8</span>; <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">// 学习速率衰减方式</span>
  optional <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">float</span> gamma = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">9</span>; <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">// 关于梯度下降的一个参数</span>
  optional <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">float</span> power = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">10</span>; <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">// 计算学习率的一个参数</span>
  optional <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">float</span> momentum = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">11</span>; <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">// 动量</span>
  optional <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">float</span> weight_decay = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">12</span>; <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">// 权值衰减</span>
  optional <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int32</span> stepsize = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">13</span>; <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">// 学习速率的衰减步长</span>
  optional <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int32</span> snapshot = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">14</span> [<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">default</span> = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>]; <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">// snapshot的间隔</span>
  optional <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">string</span> snapshot_prefix = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">15</span>; <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">// snapshot的前缀</span>
  optional <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">bool</span> snapshot_diff = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">16</span> [<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">default</span> = <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">false</span>]; <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">// 是否对于 diff 进行 snapshot</span>
  <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">enum</span> SolverMode {
   <span class="hljs-constant" style="box-sizing: border-box;"> CPU </span>= <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>;
   <span class="hljs-constant" style="box-sizing: border-box;"> GPU </span>= <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>;
  }
  optional SolverMode solver_mode = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">17</span> [<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">default</span> = GPU]; <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">// solver的模式,默认为GPU</span>
  optional <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int32</span> device_id = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">18</span> [<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">default</span> = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>]; <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">// GPU的ID</span>
  optional <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int64</span> random_seed = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">20</span> [<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">default</span> = -<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>]; <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">// 随机数种子</span>
}</code>

你可能感兴趣的:(caffe proto文件,和配置文件)