eliminate some cruft by relying on std::map default initializations
authorJeff Donahue <jeff.donahue@gmail.com>
Sun, 16 Feb 2014 19:11:03 +0000 (11:11 -0800)
committerJeff Donahue <jeff.donahue@gmail.com>
Sun, 16 Feb 2014 19:11:03 +0000 (11:11 -0800)
src/caffe/util/insert_splits.cpp

index 9ced99b..09492d4 100644 (file)
@@ -18,23 +18,12 @@ void insert_splits(const NetParameter& param, NetParameter* param_split) {
   param_split->clear_layers();
   map<string, int> blob_name_to_bottom_count;
   map<string, int> blob_name_to_bottom_split_idx;
-  // Determine for each top blob (including input blobs) the number of times
-  // it's used as a bottom blob.
-  for (int i = 0; i < param.input_size(); ++i) {
-    const string& blob_name = param.input(i);
-    blob_name_to_bottom_count[blob_name] = 0;
-    blob_name_to_bottom_split_idx[blob_name] = 0;
-  }
+  // Determine the number of times each blob is used as an input (bottom) blob.
   for (int i = 0; i < param.layers_size(); ++i) {
     const LayerConnection& layer_connection = param.layers(i);
     for (int j = 0; j < layer_connection.bottom_size(); ++j) {
       const string& blob_name = layer_connection.bottom(j);
-      blob_name_to_bottom_count[blob_name]++;
-    }
-    for (int j = 0; j < layer_connection.top_size(); ++j) {
-      const string& blob_name = layer_connection.top(j);
-      blob_name_to_bottom_count[blob_name] = 0;
-      blob_name_to_bottom_split_idx[blob_name] = 0;
+      ++blob_name_to_bottom_count[blob_name];
     }
   }
   // Create split layer for any input blobs used by other layers as bottom
@@ -76,8 +65,7 @@ void configure_split_layer(const string& blob_name,
     const int split_count, LayerConnection* split_layer_connection) {
   split_layer_connection->Clear();
   split_layer_connection->add_bottom(blob_name);
-  LayerParameter* split_layer_param =
-      split_layer_connection->mutable_layer();
+  LayerParameter* split_layer_param = split_layer_connection->mutable_layer();
   split_layer_param->set_name(blob_name + "_split");
   split_layer_param->set_type("split");
   for (int k = 0; k < split_count; ++k) {
@@ -86,6 +74,8 @@ void configure_split_layer(const string& blob_name,
 }
 
 string get_split_blob_name(const string& blob_name, const int split_index) {
+  // 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.
   if (split_index == 0) {
     return blob_name;
   }