Skip to content

Commit 8757628

Browse files
committed
refine the format in pad layer
1 parent 5f7ba2e commit 8757628

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

src/caffe/layers/pad_layer.cpp

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ namespace caffe {
99

1010
template <typename Dtype>
1111
void PadLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom,
12-
const vector<Blob<Dtype>*>& top) {
12+
const vector<Blob<Dtype>*>& top) {
1313
const PadParameter& pad_param = this->layer_param_.pad_param();
1414
constant_values_ = pad_param.constant_values();
1515
paddings_.clear();
1616
std::copy(pad_param.paddings().begin(),
17-
pad_param.paddings().end(),
18-
std::back_inserter(paddings_));
17+
pad_param.paddings().end(),
18+
std::back_inserter(paddings_));
1919
int pad_dim = paddings_.size();
2020
CHECK_EQ(pad_dim % 2, 0) << "Paddings for each dimension should have 2 values!";
2121
CHECK_EQ(pad_dim / 2, bottom[0]->num_axes()) << "Paddings' num should be 2 times of bottom dimension!";
@@ -24,13 +24,13 @@ void PadLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom,
2424

2525
template <typename Dtype>
2626
void PadLayer<Dtype>::Reshape(const vector<Blob<Dtype>*>& bottom,
27-
const vector<Blob<Dtype>*>& top) {
27+
const vector<Blob<Dtype>*>& top) {
2828
int num_top_axes = bottom[0]->num_axes();
2929
std::vector<int> shape(num_top_axes, 1);
3030
shape = bottom[0]->shape();
3131
for (int i=0;i<num_top_axes;i++)
3232
{
33-
shape[i] = shape[i] + paddings_[2*i] + paddings_[2*i+1];
33+
shape[i] = shape[i] + paddings_[2*i] + paddings_[2*i+1];
3434
}
3535
top[0]->Reshape(shape);
3636
}
@@ -39,28 +39,28 @@ void PadLayer<Dtype>::Reshape(const vector<Blob<Dtype>*>& bottom,
3939
// Initially suggested by Tom Pennello
4040
template <typename Dtype>
4141
void PadLayer<Dtype>::Pad(const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top,
42-
int level, int bottom_index, int top_index, vector<int> paddings) {
43-
const Dtype* bottom_data = bottom[0]->cpu_data();
44-
Dtype* top_data = top[0]->mutable_cpu_data();
45-
vector<int> BS = bottom[0]->shape();
46-
vector<int> TS = top[0]->shape();
42+
int level, int bottom_index, int top_index, vector<int> paddings) {
43+
const Dtype* bottom_data = bottom[0]->cpu_data();
44+
Dtype* top_data = top[0]->mutable_cpu_data();
45+
vector<int> BS = bottom[0]->shape();
46+
vector<int> TS = top[0]->shape();
4747

48-
bool innermost = (level == BS.size()-1);
49-
int bottom_level_size = BS[level];
50-
//int top_level_size = TS[level];
51-
int padl = paddings[level*2];
48+
bool innermost = (level == BS.size()-1);
49+
int bottom_level_size = BS[level];
50+
//int top_level_size = TS[level];
51+
int padl = paddings[level*2];
5252

53-
for (int ix = 0; ix < bottom_level_size; ix++) {
54-
int bix = bottom_index + ix;
55-
int tix = top_index + padl + ix;
56-
if (innermost) {
57-
//printf("top_data[%d] <- bottom_data[%d]\n",tix,bix); //Show for debug
58-
top_data[tix] = bottom_data[bix];
59-
}
60-
else {
61-
Pad(bottom, top, level+1, bix*BS[level+1], tix*TS[level+1], paddings);
62-
}
53+
for (int ix = 0; ix < bottom_level_size; ix++) {
54+
int bix = bottom_index + ix;
55+
int tix = top_index + padl + ix;
56+
if (innermost) {
57+
//printf("top_data[%d] <- bottom_data[%d]\n",tix,bix); //Show for debug
58+
top_data[tix] = bottom_data[bix];
6359
}
60+
else {
61+
Pad(bottom, top, level+1, bix*BS[level+1], tix*TS[level+1], paddings);
62+
}
63+
}
6464
};
6565

6666
template <typename Dtype>
@@ -141,7 +141,7 @@ void PadLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,
141141
top_data[top_index] = bottom_data[bottom_index];
142142
}
143143
}
144-
*/
144+
*/
145145
}
146146

147147
INSTANTIATE_CLASS(PadLayer);

0 commit comments

Comments
 (0)