Skip to content

Commit 39d01a1

Browse files
committed
simplify LayerSetUp and add more comments for SpaceToBatchND
1 parent 0c45caf commit 39d01a1

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/caffe/layers/space_to_batch_nd_layer.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ template <typename Dtype>
1313
void SpaceToBatchNDLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom,
1414
const vector<Blob<Dtype>*>& top) {
1515
const SpaceToBatchNDParameter& space_to_batch_nd_param = this->layer_param_.space_to_batch_nd_param();
16-
for(auto i = space_to_batch_nd_param.block_shape().begin(); i != space_to_batch_nd_param.block_shape().end(); ++i)
17-
block_shape_.push_back(*i);
18-
for(auto i = space_to_batch_nd_param.paddings().begin(); i != space_to_batch_nd_param.paddings().end(); ++i)
19-
paddings_.push_back(*i);
16+
for(auto i : space_to_batch_nd_param.block_shape())
17+
block_shape_.push_back(i);
18+
for(auto i : space_to_batch_nd_param.paddings())
19+
paddings_.push_back(i);
2020
}
2121

2222
template <typename Dtype>
@@ -65,7 +65,7 @@ void SpaceToBatchNDLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,
6565
for(int i=block_shape_.size(); i<bottom_shape.size(); i++)
6666
strides *= bottom_shape[i];
6767

68-
// top shape after padding
68+
// 1. Zero-pad the start and end of dimensions [1, ..., M] of the input according to paddings to produce padded of shape padded_shape.
6969
for(int i=0; i<paddings_.size()/2; i++)
7070
top_shape[i+1] += paddings_[2*i] + paddings_[2*i+1];
7171

@@ -77,7 +77,7 @@ void SpaceToBatchNDLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,
7777
int position_top = offset(coord_pad, top_shape);
7878
copy_n(bottom_data+position*strides, strides, top_data+position_top);
7979
}
80-
// Reshape padded to reshaped_padded of shape:
80+
// 2. Reshape padded to reshaped_padded of shape:
8181
// [batch] + [padded_shape[1] / block_shape[0], block_shape[0], ..., padded_shape[M] / block_shape[M-1], block_shape[M-1]] + remaining_shape
8282
vector<int> permuted_shape = top_shape;
8383
vector<int> permuted_order(2*top_shape.size()+1);
@@ -93,7 +93,7 @@ void SpaceToBatchNDLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,
9393
permuted_order[i] = i + s;
9494
}
9595

96-
// Permute dimensions of reshaped_padded to produce permuted_reshaped_padded of shape:
96+
// 3. Permute dimensions of reshaped_padded to produce permuted_reshaped_padded of shape:
9797
// block_shape + [batch] + [padded_shape[1] / block_shape[0], ..., padded_shape[M] / block_shape[M-1]] + remaining_shape
9898
vector<Dtype> top_temp(top[0]->count());
9999
copy_n(top_data, top[0]->count(), top_temp.begin());
@@ -107,7 +107,7 @@ void SpaceToBatchNDLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,
107107
copy_n(top_temp.begin()+i, 1, top_data+position_permuted);
108108
}
109109

110-
// Reshape permuted_reshaped_padded to flatten block_shape into the batch dimension, producing an output tensor of shape:
110+
// 4. Reshape permuted_reshaped_padded to flatten block_shape into the batch dimension, producing an output tensor of shape:
111111
// [batch * prod(block_shape)] + [padded_shape[1] / block_shape[0], ..., padded_shape[M] / block_shape[M-1]] + remaining_shape
112112
}
113113

0 commit comments

Comments
 (0)