From 09c034d757a13d6579197ffc04f3eb38eb0644e1 Mon Sep 17 00:00:00 2001 From: Jeff Donahue Date: Sat, 15 Feb 2014 15:52:48 -0800 Subject: [PATCH] eliminate redundant code with get_split_blob_name method --- include/caffe/util/insert_splits.hpp | 3 +++ src/caffe/util/insert_splits.cpp | 27 +++++++++++++++------------ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/include/caffe/util/insert_splits.hpp b/include/caffe/util/insert_splits.hpp index f8aae28..5bf49f1 100644 --- a/include/caffe/util/insert_splits.hpp +++ b/include/caffe/util/insert_splits.hpp @@ -16,6 +16,9 @@ void insert_splits(const NetParameter& param, NetParameter* param_split); void configure_split_layer(const string& blob_name, const int split_count, LayerConnection* split_layer_connection); +void get_split_blob_name(const string& blob_name, const int split_index, + string* split_blob_name); + } // namespace caffe #endif // CAFFE_UTIL_INSERT_SPLITS_HPP_ diff --git a/src/caffe/util/insert_splits.cpp b/src/caffe/util/insert_splits.cpp index c963dc8..2638f8c 100644 --- a/src/caffe/util/insert_splits.cpp +++ b/src/caffe/util/insert_splits.cpp @@ -54,12 +54,9 @@ void insert_splits(const NetParameter& param, NetParameter* param_split) { const string& blob_name = layer_connection->bottom(j); const int split_count = blob_name_to_bottom_count[blob_name]; if (split_count > 1) { - const int suffix_max_length = 16; - char split_suffix[suffix_max_length]; - const int suffix_length = snprintf(split_suffix, suffix_max_length, - "_split_%d", blob_name_to_bottom_split_idx[blob_name]++); - CHECK_LT(suffix_length, suffix_max_length); - const string& split_blob_name = blob_name + split_suffix; + string split_blob_name; + get_split_blob_name(blob_name, + blob_name_to_bottom_split_idx[blob_name]++, &split_blob_name); layer_connection->set_bottom(j, split_blob_name); } } @@ -86,14 +83,20 @@ void configure_split_layer(const string& blob_name, split_layer_param->set_name(blob_name + "_split"); split_layer_param->set_type("split"); for (int k = 0; k < split_count; ++k) { - const int suffix_max_length = 16; - char split_suffix[suffix_max_length]; - const int suffix_length = snprintf(split_suffix, suffix_max_length, - "_split_%d", k); - CHECK_LT(suffix_length, suffix_max_length); - const string& split_blob_name = blob_name + split_suffix; + string split_blob_name; + get_split_blob_name(blob_name, k, &split_blob_name); split_layer_connection->add_top(split_blob_name); } } +void get_split_blob_name(const string& blob_name, const int split_index, + string* split_blob_name) { + const int suffix_max_length = 16; + char split_suffix[suffix_max_length]; + const int suffix_length = snprintf(split_suffix, suffix_max_length, + "_split_%d", split_index); + CHECK_LT(suffix_length, suffix_max_length); + *split_blob_name = blob_name + split_suffix; +} + } // namespace caffe -- 2.7.4