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
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) {
}
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;
}