Skip to content

Commit ed7cd47

Browse files
committed
fix the broadcasting initializer issue for power in corner case
1 parent e348d4c commit ed7cd47

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

include/caffe/layers/pow_layer.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ class PowLayer : public Layer<Dtype> {
2121
public:
2222
explicit PowLayer(const LayerParameter& param)
2323
: Layer<Dtype>(param) {}
24+
virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,
25+
const vector<Blob<Dtype>*>& top);
2426
virtual void Reshape(const vector<Blob<Dtype>*>& bottom,
2527
const vector<Blob<Dtype>*>& top);
2628

src/caffe/layers/pow_layer.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,26 @@
66
#include "caffe/layers/pow_layer.hpp"
77

88
namespace caffe {
9+
template <typename Dtype>
10+
void PowLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom,
11+
const vector<Blob<Dtype>*>& top) {
12+
// Add the fake initialization to avoid special case in evconvert for the moment when
13+
// the prototxt is generated, the 2nd input is parameter to be fed into caffemodel, but the caffemodel is not generated yet
14+
if (bottom.size() == 1 && this->blobs_.size() == 0)
15+
{
16+
LOG(WARNING) << "Note: Make fake parameter initialization to avoid segment fault!";
17+
// initialize the 2nd input to avoid error in reshape stage
18+
this->blobs_.resize(1);
19+
const vector<int>::const_iterator& shape_start =
20+
bottom[0]->shape().begin();
21+
const vector<int>::const_iterator& shape_end = bottom[0]->shape().end();
22+
vector<int> bias_shape(shape_start, shape_end);
23+
this->blobs_[0].reset(new Blob<Dtype>(bias_shape));
24+
25+
this->param_propagate_down_.resize(this->blobs_.size(), true);
26+
}
27+
}
28+
929
template <typename Dtype>
1030
void PowLayer<Dtype>::Reshape(const vector<Blob<Dtype>*>& bottom,
1131
const vector<Blob<Dtype>*>& top) {

0 commit comments

Comments
 (0)