fix insert_splits for new layer param format
authorJeff Donahue <jeff.donahue@gmail.com>
Mon, 17 Mar 2014 10:45:09 +0000 (03:45 -0700)
committerJeff Donahue <jeff.donahue@gmail.com>
Fri, 28 Mar 2014 06:42:28 +0000 (23:42 -0700)
include/caffe/util/insert_splits.hpp
src/caffe/net.cpp
src/caffe/test/test_split_layer.cpp
src/caffe/util/insert_splits.cpp

index 4f4ddc4..e25cdd7 100644 (file)
@@ -14,16 +14,16 @@ namespace caffe {
 
 // Copy NetParameters with SplitLayers added to replace any shared bottom
 // blobs with unique bottom blobs provided by the SplitLayer.
-void insert_splits(const NetParameter& param, NetParameter* param_split);
+void InsertSplits(const NetParameter& param, NetParameter* param_split);
 
-void configure_split_layer(const string& layer_name, const string& blob_name,
+void ConfigureSplitLayer(const string& layer_name, const string& blob_name,
     const int blob_idx, const int split_count,
     LayerParameter* split_layer_param);
 
-string get_split_layer_name(const string& layer_name, const string& blob_name,
+string SplitLayerName(const string& layer_name, const string& blob_name,
     const int blob_idx);
 
-string get_split_blob_name(const string& layer_name, const string& blob_name,
+string SplitBlobName(const string& layer_name, const string& blob_name,
     const int blob_idx, const int split_idx);
 
 }  // namespace caffe
index a16afdc..06db0ab 100644 (file)
@@ -50,7 +50,7 @@ template <typename Dtype>
 void Net<Dtype>::Init(const NetParameter& in_param) {
   // Create a copy of in_param with splits added where necessary.
   NetParameter param;
-  insert_splits(in_param, &param);
+  InsertSplits(in_param, &param);
   // Basically, build all the layers and set up its connections.
   name_ = param.name();
   map<string, int> blob_name_to_idx;
index 2c7c986..6d3d612 100644 (file)
@@ -160,7 +160,7 @@ class SplitLayerInsertionTest : public ::testing::Test {
  protected:
   void RunInsertionTest(
       const string& input_param_string, const string& output_param_string) {
-    // Test that insert_splits called on the proto specified by
+    // Test that InsertSplits called on the proto specified by
     // input_param_string results in the proto specified by
     // output_param_string.
     NetParameter input_param;
@@ -170,12 +170,12 @@ class SplitLayerInsertionTest : public ::testing::Test {
     CHECK(google::protobuf::TextFormat::ParseFromString(
         output_param_string, &expected_output_param));
     NetParameter actual_output_param;
-    insert_splits(input_param, &actual_output_param);
+    InsertSplits(input_param, &actual_output_param);
     EXPECT_EQ(expected_output_param.DebugString(),
         actual_output_param.DebugString());
     // Also test idempotence.
     NetParameter double_split_insert_param;
-    insert_splits(actual_output_param, &double_split_insert_param);
+    InsertSplits(actual_output_param, &double_split_insert_param);
     EXPECT_EQ(actual_output_param.DebugString(),
        double_split_insert_param.DebugString());
   }
@@ -188,26 +188,20 @@ TYPED_TEST(SplitLayerInsertionTest, TestNoInsertion1) {
   const string& input_proto =
       "name: 'TestNetwork' "
       "layers: { "
-      "  layer { "
-      "    name: 'data' "
-      "    type: 'data' "
-      "  } "
+      "  name: 'data' "
+      "  type: 'data' "
       "  top: 'data' "
       "  top: 'label' "
       "} "
       "layers: { "
-      "  layer { "
-      "    name: 'innerprod' "
-      "    type: 'inner_product' "
-      "  } "
+      "  name: 'innerprod' "
+      "  type: 'inner_product' "
       "  bottom: 'data' "
       "  top: 'innerprod' "
       "} "
       "layers: { "
-      "  layer { "
-      "    name: 'loss' "
-      "    type: 'softmax_with_loss' "
-      "  } "
+      "  name: 'loss' "
+      "  type: 'softmax_with_loss' "
       "  bottom: 'innerprod' "
       "  bottom: 'label' "
       "} ";
@@ -218,43 +212,33 @@ TYPED_TEST(SplitLayerInsertionTest, TestNoInsertion2) {
   const string& input_proto =
       "name: 'TestNetwork' "
       "layers: { "
-      "  layer { "
-      "    name: 'data' "
-      "    type: 'data' "
-      "  } "
+      "  name: 'data' "
+      "  type: 'data' "
       "  top: 'data' "
       "  top: 'label' "
       "} "
       "layers: { "
-      "  layer { "
-      "    name: 'data_split' "
-      "    type: 'split' "
-      "  } "
+      "  name: 'data_split' "
+      "  type: 'split' "
       "  bottom: 'data' "
       "  top: 'data_split_0' "
       "  top: 'data_split_1' "
       "} "
       "layers: { "
-      "  layer { "
-      "    name: 'innerprod1' "
-      "    type: 'inner_product' "
-      "  } "
+      "  name: 'innerprod1' "
+      "  type: 'inner_product' "
       "  bottom: 'data_split_0' "
       "  top: 'innerprod1' "
       "} "
       "layers: { "
-      "  layer { "
-      "    name: 'innerprod2' "
-      "    type: 'inner_product' "
-      "  } "
+      "  name: 'innerprod2' "
+      "  type: 'inner_product' "
       "  bottom: 'data_split_1' "
       "  top: 'innerprod2' "
       "} "
       "layers: { "
-      "  layer { "
-      "    name: 'loss' "
-      "    type: 'euclidean_loss' "
-      "  } "
+      "  name: 'loss' "
+      "  type: 'euclidean_loss' "
       "  bottom: 'innerprod1' "
       "  bottom: 'innerprod2' "
       "} ";
@@ -265,24 +249,24 @@ TYPED_TEST(SplitLayerInsertionTest, TestNoInsertionImageNet) {
   const string& input_proto =
       "name: 'CaffeNet' "
       "layers { "
-      "  layer { "
-      "    name: 'data' "
-      "    type: 'data' "
+      "  name: 'data' "
+      "  type: 'data' "
+      "  data_param { "
       "    source: '/home/jiayq/Data/ILSVRC12/train-leveldb' "
-      "    meanfile: '/home/jiayq/Data/ILSVRC12/image_mean.binaryproto' "
-      "    batchsize: 256 "
-      "    cropsize: 227 "
+      "    mean_file: '/home/jiayq/Data/ILSVRC12/image_mean.binaryproto' "
+      "    batch_size: 256 "
+      "    crop_size: 227 "
       "    mirror: true "
       "  } "
       "  top: 'data' "
       "  top: 'label' "
       "} "
       "layers { "
-      "  layer { "
-      "    name: 'conv1' "
-      "    type: 'conv' "
+      "  name: 'conv1' "
+      "  type: 'conv' "
+      "  convolution_param { "
       "    num_output: 96 "
-      "    kernelsize: 11 "
+      "    kernel_size: 11 "
       "    stride: 4 "
       "    weight_filler { "
       "      type: 'gaussian' "
@@ -292,37 +276,35 @@ TYPED_TEST(SplitLayerInsertionTest, TestNoInsertionImageNet) {
       "      type: 'constant' "
       "      value: 0. "
       "    } "
-      "    blobs_lr: 1. "
-      "    blobs_lr: 2. "
-      "    weight_decay: 1. "
-      "    weight_decay: 0. "
       "  } "
+      "  blobs_lr: 1. "
+      "  blobs_lr: 2. "
+      "  weight_decay: 1. "
+      "  weight_decay: 0. "
       "  bottom: 'data' "
       "  top: 'conv1' "
       "} "
       "layers { "
-      "  layer { "
-      "    name: 'relu1' "
-      "    type: 'relu' "
-      "  } "
+      "  name: 'relu1' "
+      "  type: 'relu' "
       "  bottom: 'conv1' "
       "  top: 'conv1' "
       "} "
       "layers { "
-      "  layer { "
-      "    name: 'pool1' "
-      "    type: 'pool' "
+      "  name: 'pool1' "
+      "  type: 'pool' "
+      "  pooling_param { "
       "    pool: MAX "
-      "    kernelsize: 3 "
+      "    kernel_size: 3 "
       "    stride: 2 "
       "  } "
       "  bottom: 'conv1' "
       "  top: 'pool1' "
       "} "
       "layers { "
-      "  layer { "
-      "    name: 'norm1' "
-      "    type: 'lrn' "
+      "  name: 'norm1' "
+      "  type: 'lrn' "
+      "  lrn_param { "
       "    local_size: 5 "
       "    alpha: 0.0001 "
       "    beta: 0.75 "
@@ -331,21 +313,13 @@ TYPED_TEST(SplitLayerInsertionTest, TestNoInsertionImageNet) {
       "  top: 'norm1' "
       "} "
       "layers { "
-      "  layer { "
-      "    name: 'pad2' "
-      "    type: 'padding' "
-      "    pad: 2 "
-      "  } "
-      "  bottom: 'norm1' "
-      "  top: 'pad2' "
-      "} "
-      "layers { "
-      "  layer { "
-      "    name: 'conv2' "
-      "    type: 'conv' "
+      "  name: 'conv2' "
+      "  type: 'conv' "
+      "  convolution_param { "
       "    num_output: 256 "
       "    group: 2 "
-      "    kernelsize: 5 "
+      "    kernel_size: 5 "
+      "    pad: 2 "
       "    weight_filler { "
       "      type: 'gaussian' "
       "      std: 0.01 "
@@ -354,37 +328,35 @@ TYPED_TEST(SplitLayerInsertionTest, TestNoInsertionImageNet) {
       "      type: 'constant' "
       "      value: 1. "
       "    } "
-      "    blobs_lr: 1. "
-      "    blobs_lr: 2. "
-      "    weight_decay: 1. "
-      "    weight_decay: 0. "
       "  } "
-      "  bottom: 'pad2' "
+      "  blobs_lr: 1. "
+      "  blobs_lr: 2. "
+      "  weight_decay: 1. "
+      "  weight_decay: 0. "
+      "  bottom: 'norm1' "
       "  top: 'conv2' "
       "} "
       "layers { "
-      "  layer { "
-      "    name: 'relu2' "
-      "    type: 'relu' "
-      "  } "
+      "  name: 'relu2' "
+      "  type: 'relu' "
       "  bottom: 'conv2' "
       "  top: 'conv2' "
       "} "
       "layers { "
-      "  layer { "
-      "    name: 'pool2' "
-      "    type: 'pool' "
+      "  name: 'pool2' "
+      "  type: 'pool' "
+      "  pooling_param { "
       "    pool: MAX "
-      "    kernelsize: 3 "
+      "    kernel_size: 3 "
       "    stride: 2 "
       "  } "
       "  bottom: 'conv2' "
       "  top: 'pool2' "
       "} "
       "layers { "
-      "  layer { "
-      "    name: 'norm2' "
-      "    type: 'lrn' "
+      "  name: 'norm2' "
+      "  type: 'lrn' "
+      "  lrn_param { "
       "    local_size: 5 "
       "    alpha: 0.0001 "
       "    beta: 0.75 "
@@ -393,20 +365,12 @@ TYPED_TEST(SplitLayerInsertionTest, TestNoInsertionImageNet) {
       "  top: 'norm2' "
       "} "
       "layers { "
-      "  layer { "
-      "    name: 'pad3' "
-      "    type: 'padding' "
-      "    pad: 1 "
-      "  } "
-      "  bottom: 'norm2' "
-      "  top: 'pad3' "
-      "} "
-      "layers { "
-      "  layer { "
-      "    name: 'conv3' "
-      "    type: 'conv' "
+      "  name: 'conv3' "
+      "  type: 'conv' "
+      "  convolution_param { "
       "    num_output: 384 "
-      "    kernelsize: 3 "
+      "    kernel_size: 3 "
+      "    pad: 1 "
       "    weight_filler { "
       "      type: 'gaussian' "
       "      std: 0.01 "
@@ -415,38 +379,28 @@ TYPED_TEST(SplitLayerInsertionTest, TestNoInsertionImageNet) {
       "      type: 'constant' "
       "      value: 0. "
       "    } "
-      "    blobs_lr: 1. "
-      "    blobs_lr: 2. "
-      "    weight_decay: 1. "
-      "    weight_decay: 0. "
       "  } "
-      "  bottom: 'pad3' "
+      "  blobs_lr: 1. "
+      "  blobs_lr: 2. "
+      "  weight_decay: 1. "
+      "  weight_decay: 0. "
+      "  bottom: 'norm2' "
       "  top: 'conv3' "
       "} "
       "layers { "
-      "  layer { "
-      "    name: 'relu3' "
-      "    type: 'relu' "
-      "  } "
+      "  name: 'relu3' "
+      "  type: 'relu' "
       "  bottom: 'conv3' "
       "  top: 'conv3' "
       "} "
       "layers { "
-      "  layer { "
-      "    name: 'pad4' "
-      "    type: 'padding' "
-      "    pad: 1 "
-      "  } "
-      "  bottom: 'conv3' "
-      "  top: 'pad4' "
-      "} "
-      "layers { "
-      "  layer { "
-      "    name: 'conv4' "
-      "    type: 'conv' "
+      "  name: 'conv4' "
+      "  type: 'conv' "
+      "  convolution_param { "
       "    num_output: 384 "
       "    group: 2 "
-      "    kernelsize: 3 "
+      "    kernel_size: 3 "
+      "    pad: 1 "
       "    weight_filler { "
       "      type: 'gaussian' "
       "      std: 0.01 "
@@ -455,38 +409,28 @@ TYPED_TEST(SplitLayerInsertionTest, TestNoInsertionImageNet) {
       "      type: 'constant' "
       "      value: 1. "
       "    } "
-      "    blobs_lr: 1. "
-      "    blobs_lr: 2. "
-      "    weight_decay: 1. "
-      "    weight_decay: 0. "
       "  } "
-      "  bottom: 'pad4' "
+      "  blobs_lr: 1. "
+      "  blobs_lr: 2. "
+      "  weight_decay: 1. "
+      "  weight_decay: 0. "
+      "  bottom: 'conv3' "
       "  top: 'conv4' "
       "} "
       "layers { "
-      "  layer { "
-      "    name: 'relu4' "
-      "    type: 'relu' "
-      "  } "
+      "  name: 'relu4' "
+      "  type: 'relu' "
       "  bottom: 'conv4' "
       "  top: 'conv4' "
       "} "
       "layers { "
-      "  layer { "
-      "    name: 'pad5' "
-      "    type: 'padding' "
-      "    pad: 1 "
-      "  } "
-      "  bottom: 'conv4' "
-      "  top: 'pad5' "
-      "} "
-      "layers { "
-      "  layer { "
-      "    name: 'conv5' "
-      "    type: 'conv' "
+      "  name: 'conv5' "
+      "  type: 'conv' "
+      "  convolution_param { "
       "    num_output: 256 "
       "    group: 2 "
-      "    kernelsize: 3 "
+      "    kernel_size: 3 "
+      "    pad: 1 "
       "    weight_filler { "
       "      type: 'gaussian' "
       "      std: 0.01 "
@@ -495,27 +439,25 @@ TYPED_TEST(SplitLayerInsertionTest, TestNoInsertionImageNet) {
       "      type: 'constant' "
       "      value: 1. "
       "    } "
-      "    blobs_lr: 1. "
-      "    blobs_lr: 2. "
-      "    weight_decay: 1. "
-      "    weight_decay: 0. "
       "  } "
-      "  bottom: 'pad5' "
+      "  blobs_lr: 1. "
+      "  blobs_lr: 2. "
+      "  weight_decay: 1. "
+      "  weight_decay: 0. "
+      "  bottom: 'conv4' "
       "  top: 'conv5' "
       "} "
       "layers { "
-      "  layer { "
-      "    name: 'relu5' "
-      "    type: 'relu' "
-      "  } "
+      "  name: 'relu5' "
+      "  type: 'relu' "
       "  bottom: 'conv5' "
       "  top: 'conv5' "
       "} "
       "layers { "
-      "  layer { "
-      "    name: 'pool5' "
-      "    type: 'pool' "
-      "    kernelsize: 3 "
+      "  name: 'pool5' "
+      "  type: 'pool' "
+      "  pooling_param { "
+      "    kernel_size: 3 "
       "    pool: MAX "
       "    stride: 2 "
       "  } "
@@ -523,9 +465,9 @@ TYPED_TEST(SplitLayerInsertionTest, TestNoInsertionImageNet) {
       "  top: 'pool5' "
       "} "
       "layers { "
-      "  layer { "
-      "    name: 'fc6' "
-      "    type: 'innerproduct' "
+      "  name: 'fc6' "
+      "  type: 'innerproduct' "
+      "  inner_product_param { "
       "    num_output: 4096 "
       "    weight_filler { "
       "      type: 'gaussian' "
@@ -535,35 +477,33 @@ TYPED_TEST(SplitLayerInsertionTest, TestNoInsertionImageNet) {
       "      type: 'constant' "
       "      value: 1. "
       "    } "
-      "    blobs_lr: 1. "
-      "    blobs_lr: 2. "
-      "    weight_decay: 1. "
-      "    weight_decay: 0. "
       "  } "
+      "  blobs_lr: 1. "
+      "  blobs_lr: 2. "
+      "  weight_decay: 1. "
+      "  weight_decay: 0. "
       "  bottom: 'pool5' "
       "  top: 'fc6' "
       "} "
       "layers { "
-      "  layer { "
-      "    name: 'relu6' "
-      "    type: 'relu' "
-      "  } "
+      "  name: 'relu6' "
+      "  type: 'relu' "
       "  bottom: 'fc6' "
       "  top: 'fc6' "
       "} "
       "layers { "
-      "  layer { "
-      "    name: 'drop6' "
-      "    type: 'dropout' "
+      "  name: 'drop6' "
+      "  type: 'dropout' "
+      "  dropout_param { "
       "    dropout_ratio: 0.5 "
       "  } "
       "  bottom: 'fc6' "
       "  top: 'fc6' "
       "} "
       "layers { "
-      "  layer { "
-      "    name: 'fc7' "
-      "    type: 'innerproduct' "
+      "  name: 'fc7' "
+      "  type: 'innerproduct' "
+      "  inner_product_param { "
       "    num_output: 4096 "
       "    weight_filler { "
       "      type: 'gaussian' "
@@ -573,35 +513,33 @@ TYPED_TEST(SplitLayerInsertionTest, TestNoInsertionImageNet) {
       "      type: 'constant' "
       "      value: 1. "
       "    } "
-      "    blobs_lr: 1. "
-      "    blobs_lr: 2. "
-      "    weight_decay: 1. "
-      "    weight_decay: 0. "
       "  } "
+      "  blobs_lr: 1. "
+      "  blobs_lr: 2. "
+      "  weight_decay: 1. "
+      "  weight_decay: 0. "
       "  bottom: 'fc6' "
       "  top: 'fc7' "
       "} "
       "layers { "
-      "  layer { "
-      "    name: 'relu7' "
-      "    type: 'relu' "
-      "  } "
+      "  name: 'relu7' "
+      "  type: 'relu' "
       "  bottom: 'fc7' "
       "  top: 'fc7' "
       "} "
       "layers { "
-      "  layer { "
-      "    name: 'drop7' "
-      "    type: 'dropout' "
+      "  name: 'drop7' "
+      "  type: 'dropout' "
+      "  dropout_param { "
       "    dropout_ratio: 0.5 "
       "  } "
       "  bottom: 'fc7' "
       "  top: 'fc7' "
       "} "
       "layers { "
-      "  layer { "
-      "    name: 'fc8' "
-      "    type: 'innerproduct' "
+      "  name: 'fc8' "
+      "  type: 'innerproduct' "
+      "  inner_product_param { "
       "    num_output: 1000 "
       "    weight_filler { "
       "      type: 'gaussian' "
@@ -611,57 +549,47 @@ TYPED_TEST(SplitLayerInsertionTest, TestNoInsertionImageNet) {
       "      type: 'constant' "
       "      value: 0 "
       "    } "
-      "    blobs_lr: 1. "
-      "    blobs_lr: 2. "
-      "    weight_decay: 1. "
-      "    weight_decay: 0. "
       "  } "
+      "  blobs_lr: 1. "
+      "  blobs_lr: 2. "
+      "  weight_decay: 1. "
+      "  weight_decay: 0. "
       "  bottom: 'fc7' "
       "  top: 'fc8' "
       "} "
       "layers { "
-      "  layer { "
-      "    name: 'loss' "
-      "    type: 'softmax_loss' "
-      "  } "
+      "  name: 'loss' "
+      "  type: 'softmax_loss' "
       "  bottom: 'fc8' "
       "  bottom: 'label' "
       "} ";
   this->RunInsertionTest(input_proto, input_proto);
 }
 
-TYPED_TEST(SplitLayerInsertionTest, TestInsertionWithInPlace) {
+TYPED_TEST(SplitLayerInsertionTest, TestNoInsertionWithInPlace) {
   const string& input_proto =
       "name: 'TestNetwork' "
       "layers: { "
-      "  layer { "
-      "    name: 'data' "
-      "    type: 'data' "
-      "  } "
+      "  name: 'data' "
+      "  type: 'data' "
       "  top: 'data' "
       "  top: 'label' "
       "} "
       "layers: { "
-      "  layer { "
-      "    name: 'innerprod' "
-      "    type: 'inner_product' "
-      "  } "
+      "  name: 'innerprod' "
+      "  type: 'inner_product' "
       "  bottom: 'data' "
       "  top: 'innerprod' "
       "} "
       "layers: { "
-      "  layer { "
-      "    name: 'relu' "
-      "    type: 'relu' "
-      "  } "
+      "  name: 'relu' "
+      "  type: 'relu' "
       "  bottom: 'innerprod' "
       "  top: 'innerprod' "
       "} "
       "layers: { "
-      "  layer { "
-      "    name: 'loss' "
-      "    type: 'softmax_with_loss' "
-      "  } "
+      "  name: 'loss' "
+      "  type: 'softmax_with_loss' "
       "  bottom: 'innerprod' "
       "  bottom: 'label' "
       "} ";
@@ -672,119 +600,91 @@ TYPED_TEST(SplitLayerInsertionTest, TestInsertion) {
   const string& input_proto =
       "name: 'TestNetwork' "
       "layers: { "
-      "  layer { "
-      "    name: 'data' "
-      "    type: 'data' "
-      "  } "
+      "  name: 'data' "
+      "  type: 'data' "
       "  top: 'data' "
       "  top: 'label' "
       "} "
       "layers: { "
-      "  layer { "
-      "    name: 'innerprod1' "
-      "    type: 'inner_product' "
-      "  } "
+      "  name: 'innerprod1' "
+      "  type: 'inner_product' "
       "  bottom: 'data' "
       "  top: 'innerprod1' "
       "} "
       "layers: { "
-      "  layer { "
-      "    name: 'innerprod2' "
-      "    type: 'inner_product' "
-      "  } "
+      "  name: 'innerprod2' "
+      "  type: 'inner_product' "
       "  bottom: 'data' "
       "  top: 'innerprod2' "
       "} "
       "layers: { "
-      "  layer { "
-      "    name: 'innerprod3' "
-      "    type: 'inner_product' "
-      "  } "
+      "  name: 'innerprod3' "
+      "  type: 'inner_product' "
       "  bottom: 'data' "
       "  top: 'innerprod3' "
       "} "
       "layers: { "
-      "  layer { "
-      "    name: 'loss1' "
-      "    type: 'euclidean_loss' "
-      "  } "
+      "  name: 'loss1' "
+      "  type: 'euclidean_loss' "
       "  bottom: 'innerprod1' "
       "  bottom: 'innerprod2' "
       "} "
       "layers: { "
-      "  layer { "
-      "    name: 'loss2' "
-      "    type: 'euclidean_loss' "
-      "  } "
+      "  name: 'loss2' "
+      "  type: 'euclidean_loss' "
       "  bottom: 'innerprod2' "
       "  bottom: 'innerprod3' "
       "} ";
   const string& expected_output_proto =
       "name: 'TestNetwork' "
       "layers: { "
-      "  layer { "
-      "    name: 'data' "
-      "    type: 'data' "
-      "  } "
+      "  name: 'data' "
+      "  type: 'data' "
       "  top: 'data' "
       "  top: 'label' "
       "} "
       "layers: { "
-      "  layer { "
-      "    name: 'data_data_0_split' "
-      "    type: 'split' "
-      "  } "
+      "  name: 'data_data_0_split' "
+      "  type: 'split' "
       "  bottom: 'data' "
       "  top: 'data' "
       "  top: 'data_data_0_split_1' "
       "  top: 'data_data_0_split_2' "
       "} "
       "layers: { "
-      "  layer { "
-      "    name: 'innerprod1' "
-      "    type: 'inner_product' "
-      "  } "
+      "  name: 'innerprod1' "
+      "  type: 'inner_product' "
       "  bottom: 'data' "
       "  top: 'innerprod1' "
       "} "
       "layers: { "
-      "  layer { "
-      "    name: 'innerprod2' "
-      "    type: 'inner_product' "
-      "  } "
+      "  name: 'innerprod2' "
+      "  type: 'inner_product' "
       "  bottom: 'data_data_0_split_1' "
       "  top: 'innerprod2' "
       "} "
       "layers: { "
-      "  layer { "
-      "    name: 'innerprod2_innerprod2_0_split' "
-      "    type: 'split' "
-      "  } "
+      "  name: 'innerprod2_innerprod2_0_split' "
+      "  type: 'split' "
       "  bottom: 'innerprod2' "
       "  top: 'innerprod2' "
       "  top: 'innerprod2_innerprod2_0_split_1' "
       "} "
       "layers: { "
-      "  layer { "
-      "    name: 'innerprod3' "
-      "    type: 'inner_product' "
-      "  } "
+      "  name: 'innerprod3' "
+      "  type: 'inner_product' "
       "  bottom: 'data_data_0_split_2' "
       "  top: 'innerprod3' "
       "} "
       "layers: { "
-      "  layer { "
-      "    name: 'loss1' "
-      "    type: 'euclidean_loss' "
-      "  } "
+      "  name: 'loss1' "
+      "  type: 'euclidean_loss' "
       "  bottom: 'innerprod1' "
       "  bottom: 'innerprod2' "
       "} "
       "layers: { "
-      "  layer { "
-      "    name: 'loss2' "
-      "    type: 'euclidean_loss' "
-      "  } "
+      "  name: 'loss2' "
+      "  type: 'euclidean_loss' "
       "  bottom: 'innerprod2_innerprod2_0_split_1' "
       "  bottom: 'innerprod3' "
       "} ";
@@ -795,134 +695,102 @@ TYPED_TEST(SplitLayerInsertionTest, TestInsertionTwoTop) {
   const string& input_proto =
       "name: 'TestNetwork' "
       "layers: { "
-      "  layer { "
-      "    name: 'data' "
-      "    type: 'data' "
-      "  } "
+      "  name: 'data' "
+      "  type: 'data' "
       "  top: 'data' "
       "  top: 'label' "
       "} "
       "layers: { "
-      "  layer { "
-      "    name: 'innerprod1' "
-      "    type: 'inner_product' "
-      "  } "
+      "  name: 'innerprod1' "
+      "  type: 'inner_product' "
       "  bottom: 'data' "
       "  top: 'innerprod1' "
       "} "
       "layers: { "
-      "  layer { "
-      "    name: 'innerprod2' "
-      "    type: 'inner_product' "
-      "  } "
+      "  name: 'innerprod2' "
+      "  type: 'inner_product' "
       "  bottom: 'label' "
       "  top: 'innerprod2' "
       "} "
       "layers: { "
-      "  layer { "
-      "    name: 'innerprod3' "
-      "    type: 'inner_product' "
-      "  } "
+      "  name: 'innerprod3' "
+      "  type: 'inner_product' "
       "  bottom: 'data' "
       "  top: 'innerprod3' "
       "} "
       "layers: { "
-      "  layer { "
-      "    name: 'innerprod4' "
-      "    type: 'inner_product' "
-      "  } "
+      "  name: 'innerprod4' "
+      "  type: 'inner_product' "
       "  bottom: 'label' "
       "  top: 'innerprod4' "
       "} "
       "layers: { "
-      "  layer { "
-      "    name: 'loss1' "
-      "    type: 'euclidean_loss' "
-      "  } "
+      "  name: 'loss1' "
+      "  type: 'euclidean_loss' "
       "  bottom: 'innerprod1' "
       "  bottom: 'innerprod3' "
       "} "
       "layers: { "
-      "  layer { "
-      "    name: 'loss2' "
-      "    type: 'euclidean_loss' "
-      "  } "
+      "  name: 'loss2' "
+      "  type: 'euclidean_loss' "
       "  bottom: 'innerprod2' "
       "  bottom: 'innerprod4' "
       "} ";
   const string& expected_output_proto =
       "name: 'TestNetwork' "
       "layers: { "
-      "  layer { "
-      "    name: 'data' "
-      "    type: 'data' "
-      "  } "
+      "  name: 'data' "
+      "  type: 'data' "
       "  top: 'data' "
       "  top: 'label' "
       "} "
       "layers: { "
-      "  layer { "
-      "    name: 'data_data_0_split' "
-      "    type: 'split' "
-      "  } "
+      "  name: 'data_data_0_split' "
+      "  type: 'split' "
       "  bottom: 'data' "
       "  top: 'data' "
       "  top: 'data_data_0_split_1' "
       "} "
       "layers: { "
-      "  layer { "
-      "    name: 'label_data_1_split' "
-      "    type: 'split' "
-      "  } "
+      "  name: 'label_data_1_split' "
+      "  type: 'split' "
       "  bottom: 'label' "
       "  top: 'label' "
       "  top: 'label_data_1_split_1' "
       "} "
       "layers: { "
-      "  layer { "
-      "    name: 'innerprod1' "
-      "    type: 'inner_product' "
-      "  } "
+      "  name: 'innerprod1' "
+      "  type: 'inner_product' "
       "  bottom: 'data' "
       "  top: 'innerprod1' "
       "} "
       "layers: { "
-      "  layer { "
-      "    name: 'innerprod2' "
-      "    type: 'inner_product' "
-      "  } "
+      "  name: 'innerprod2' "
+      "  type: 'inner_product' "
       "  bottom: 'label' "
       "  top: 'innerprod2' "
       "} "
       "layers: { "
-      "  layer { "
-      "    name: 'innerprod3' "
-      "    type: 'inner_product' "
-      "  } "
+      "  name: 'innerprod3' "
+      "  type: 'inner_product' "
       "  bottom: 'data_data_0_split_1' "
       "  top: 'innerprod3' "
       "} "
       "layers: { "
-      "  layer { "
-      "    name: 'innerprod4' "
-      "    type: 'inner_product' "
-      "  } "
+      "  name: 'innerprod4' "
+      "  type: 'inner_product' "
       "  bottom: 'label_data_1_split_1' "
       "  top: 'innerprod4' "
       "} "
       "layers: { "
-      "  layer { "
-      "    name: 'loss1' "
-      "    type: 'euclidean_loss' "
-      "  } "
+      "  name: 'loss1' "
+      "  type: 'euclidean_loss' "
       "  bottom: 'innerprod1' "
       "  bottom: 'innerprod3' "
       "} "
       "layers: { "
-      "  layer { "
-      "    name: 'loss2' "
-      "    type: 'euclidean_loss' "
-      "  } "
+      "  name: 'loss2' "
+      "  type: 'euclidean_loss' "
       "  bottom: 'innerprod2' "
       "  bottom: 'innerprod4' "
       "} ";
@@ -938,26 +806,20 @@ TYPED_TEST(SplitLayerInsertionTest, TestInputInsertion) {
       "input_dim: 227 "
       "input_dim: 227 "
       "layers: { "
-      "  layer { "
-      "    name: 'innerprod1' "
-      "    type: 'inner_product' "
-      "  } "
+      "  name: 'innerprod1' "
+      "  type: 'inner_product' "
       "  bottom: 'data' "
       "  top: 'innerprod1' "
       "} "
       "layers: { "
-      "  layer { "
-      "    name: 'innerprod2' "
-      "    type: 'inner_product' "
-      "  } "
+      "  name: 'innerprod2' "
+      "  type: 'inner_product' "
       "  bottom: 'data' "
       "  top: 'innerprod2' "
       "} "
       "layers: { "
-      "  layer { "
-      "    name: 'loss' "
-      "    type: 'euclidean_loss' "
-      "  } "
+      "  name: 'loss' "
+      "  type: 'euclidean_loss' "
       "  bottom: 'innerprod1' "
       "  bottom: 'innerprod2' "
       "} ";
@@ -969,35 +831,27 @@ TYPED_TEST(SplitLayerInsertionTest, TestInputInsertion) {
       "input_dim: 227 "
       "input_dim: 227 "
       "layers: { "
-      "  layer { "
-      "    name: 'data_input_0_split' "
-      "    type: 'split' "
-      "  } "
+      "  name: 'data_input_0_split' "
+      "  type: 'split' "
       "  bottom: 'data' "
       "  top: 'data' "
       "  top: 'data_input_0_split_1' "
       "} "
       "layers: { "
-      "  layer { "
-      "    name: 'innerprod1' "
-      "    type: 'inner_product' "
-      "  } "
+      "  name: 'innerprod1' "
+      "  type: 'inner_product' "
       "  bottom: 'data' "
       "  top: 'innerprod1' "
       "} "
       "layers: { "
-      "  layer { "
-      "    name: 'innerprod2' "
-      "    type: 'inner_product' "
-      "  } "
+      "  name: 'innerprod2' "
+      "  type: 'inner_product' "
       "  bottom: 'data_input_0_split_1' "
       "  top: 'innerprod2' "
       "} "
       "layers: { "
-      "  layer { "
-      "    name: 'loss' "
-      "    type: 'euclidean_loss' "
-      "  } "
+      "  name: 'loss' "
+      "  type: 'euclidean_loss' "
       "  bottom: 'innerprod1' "
       "  bottom: 'innerprod2' "
       "} ";
@@ -1008,118 +862,90 @@ TYPED_TEST(SplitLayerInsertionTest, TestWithInPlace) {
   const string& input_proto =
       "name: 'TestNetwork' "
       "layers: { "
-      "  layer { "
-      "    name: 'data' "
-      "    type: 'data' "
-      "  } "
+      "  name: 'data' "
+      "  type: 'data' "
       "  top: 'data' "
       "  top: 'label' "
       "} "
       "layers: { "
-      "  layer { "
-      "    name: 'innerprod1' "
-      "    type: 'inner_product' "
-      "  } "
+      "  name: 'innerprod1' "
+      "  type: 'inner_product' "
       "  bottom: 'data' "
       "  top: 'innerprod1' "
       "} "
       "layers: { "
-      "  layer { "
-      "    name: 'relu1' "
-      "    type: 'relu' "
-      "  } "
+      "  name: 'relu1' "
+      "  type: 'relu' "
       "  bottom: 'innerprod1' "
       "  top: 'innerprod1' "
       "} "
       "layers: { "
-      "  layer { "
-      "    name: 'innerprod2' "
-      "    type: 'inner_product' "
-      "  } "
+      "  name: 'innerprod2' "
+      "  type: 'inner_product' "
       "  bottom: 'innerprod1' "
       "  top: 'innerprod2' "
       "} "
       "layers: { "
-      "  layer { "
-      "    name: 'loss1' "
-      "    type: 'euclidean_loss' "
-      "  } "
+      "  name: 'loss1' "
+      "  type: 'euclidean_loss' "
       "  bottom: 'innerprod1' "
       "  bottom: 'label' "
       "} "
       "layers: { "
-      "  layer { "
-      "    name: 'loss2' "
-      "    type: 'euclidean_loss' "
-      "  } "
+      "  name: 'loss2' "
+      "  type: 'euclidean_loss' "
       "  bottom: 'innerprod2' "
       "  bottom: 'data' "
       "} ";
   const string& expected_output_proto =
       "name: 'TestNetwork' "
       "layers: { "
-      "  layer { "
-      "    name: 'data' "
-      "    type: 'data' "
-      "  } "
+      "  name: 'data' "
+      "  type: 'data' "
       "  top: 'data' "
       "  top: 'label' "
       "} "
       "layers: { "
-      "  layer { "
-      "    name: 'data_data_0_split' "
-      "    type: 'split' "
-      "  } "
+      "  name: 'data_data_0_split' "
+      "  type: 'split' "
       "  bottom: 'data' "
       "  top: 'data' "
       "  top: 'data_data_0_split_1' "
       "} "
       "layers: { "
-      "  layer { "
-      "    name: 'innerprod1' "
-      "    type: 'inner_product' "
-      "  } "
+      "  name: 'innerprod1' "
+      "  type: 'inner_product' "
       "  bottom: 'data' "
       "  top: 'innerprod1' "
       "} "
       "layers: { "
-      "  layer { "
-      "    name: 'relu1' "
-      "    type: 'relu' "
-      "  } "
+      "  name: 'relu1' "
+      "  type: 'relu' "
       "  bottom: 'innerprod1' "
       "  top: 'innerprod1' "
       "} "
       "layers: { "
-      "  layer { "
-      "    name: 'innerprod1_relu1_0_split' "
-      "    type: 'split' "
-      "  } "
+      "  name: 'innerprod1_relu1_0_split' "
+      "  type: 'split' "
       "  bottom: 'innerprod1' "
       "  top: 'innerprod1' "
       "  top: 'innerprod1_relu1_0_split_1' "
       "} "
       "layers: { "
-      "  layer { "
-      "    name: 'innerprod2' "
-      "    type: 'inner_product' "
-      "  } "
+      "  name: 'innerprod2' "
+      "  type: 'inner_product' "
       "  bottom: 'innerprod1' "
       "  top: 'innerprod2' "
       "} "
       "layers: { "
-      "  layer { "
-      "    name: 'loss1' "
-      "    type: 'euclidean_loss' "
-      "  } "
+      "  name: 'loss1' "
+      "  type: 'euclidean_loss' "
       "  bottom: 'innerprod1_relu1_0_split_1' "
       "  bottom: 'label' "
       "} "
       "layers: { "
-      "  layer { "
-      "    name: 'loss2' "
-      "    type: 'euclidean_loss' "
-      "  } "
+      "  name: 'loss2' "
+      "  type: 'euclidean_loss' "
       "  bottom: 'innerprod2' "
       "  bottom: 'data_data_0_split_1' "
       "} ";
index 0e8ce07..05c1e96 100644 (file)
@@ -15,7 +15,7 @@ using std::make_pair;
 
 namespace caffe {
 
-void insert_splits(const NetParameter& param, NetParameter* param_split) {
+void InsertSplits(const NetParameter& param, NetParameter* param_split) {
   // Initialize by copying from the input NetParameter.
   param_split->CopyFrom(param);
   param_split->clear_layers();
@@ -57,7 +57,7 @@ void insert_splits(const NetParameter& param, NetParameter* param_split) {
       const string& layer_name = layer_idx_to_layer_name[-1];
       const string& blob_name = param.input(i);
       LayerParameter* split_layer_param = param_split->add_layers();
-      configure_split_layer(layer_name, blob_name, i, split_count,
+      ConfigureSplitLayer(layer_name, blob_name, i, split_count,
           split_layer_param);
     }
   }
@@ -72,7 +72,7 @@ void insert_splits(const NetParameter& param, NetParameter* param_split) {
       if (split_count > 1) {
         const string& layer_name = layer_idx_to_layer_name[top_idx.first];
         const string& blob_name = layer_param->bottom(j);
-        layer_param->set_bottom(j, get_split_blob_name(layer_name,
+        layer_param->set_bottom(j, SplitBlobName(layer_name,
             blob_name, top_idx.second, top_idx_to_bottom_split_idx[top_idx]++));
       }
     }
@@ -84,28 +84,27 @@ void insert_splits(const NetParameter& param, NetParameter* param_split) {
         const string& layer_name = layer_idx_to_layer_name[i];
         const string& blob_name = layer_param->top(j);
         LayerParameter* split_layer_param = param_split->add_layers();
-        configure_split_layer(layer_name, blob_name, j, split_count,
+        ConfigureSplitLayer(layer_name, blob_name, j, split_count,
             split_layer_param);
       }
     }
   }
 }
 
-void configure_split_layer(const string& layer_name, const string& blob_name,
+void ConfigureSplitLayer(const string& layer_name, const string& blob_name,
     const int blob_idx, const int split_count,
     LayerParameter* split_layer_param) {
   split_layer_param->Clear();
   split_layer_param->add_bottom(blob_name);
-  split_layer_param->set_name(
-      get_split_layer_name(layer_name, blob_name, blob_idx));
+  split_layer_param->set_name(SplitLayerName(layer_name, blob_name, blob_idx));
   split_layer_param->set_type("split");
   for (int k = 0; k < split_count; ++k) {
     split_layer_param->add_top(
-        get_split_blob_name(layer_name, blob_name, blob_idx, k));
+        SplitBlobName(layer_name, blob_name, blob_idx, k));
   }
 }
 
-string get_split_layer_name(const string& layer_name, const string& blob_name,
+string SplitLayerName(const string& layer_name, const string& blob_name,
     const int blob_idx) {
   ostringstream split_layer_name;
   split_layer_name << blob_name << "_" << layer_name << "_" << blob_idx
@@ -113,7 +112,7 @@ string get_split_layer_name(const string& layer_name, const string& blob_name,
   return split_layer_name.str();
 }
 
-string get_split_blob_name(const string& layer_name, const string& blob_name,
+string SplitBlobName(const string& layer_name, const string& blob_name,
     const int blob_idx, const int split_idx) {
   // 0th split top blob is given the same name as the bottom blob so that
   // computation is done 'in-place', saving a bit of time and memory.