MCPcopy Create free account
hub / github.com/BVLC/caffe / Reshape

Method Reshape

src/caffe/layers/scale_layer.cpp:76–114  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

74
75template <typename Dtype>
76void ScaleLayer<Dtype>::Reshape(const vector<Blob<Dtype>*>& bottom,
77 const vector<Blob<Dtype>*>& top) {
78 const ScaleParameter& param = this->layer_param_.scale_param();
79 Blob<Dtype>* scale = (bottom.size() > 1) ? bottom[1] : this->blobs_[0].get();
80 // Always set axis_ == 0 in special case where scale is a scalar
81 // (num_axes == 0). Mathematically equivalent for any choice of axis_, so the
82 // actual setting can be safely ignored; and computation is most efficient
83 // with axis_ == 0 and (therefore) outer_dim_ == 1. (Setting axis_ to
84 // bottom[0]->num_axes() - 1, giving inner_dim_ == 1, would be equally
85 // performant.)
86 axis_ = (scale->num_axes() == 0) ?
87 0 : bottom[0]->CanonicalAxisIndex(param.axis());
88 CHECK_GE(bottom[0]->num_axes(), axis_ + scale->num_axes())
89 << "scale blob's shape extends past bottom[0]'s shape when applied "
90 << "starting with bottom[0] axis = " << axis_;
91 for (int i = 0; i < scale->num_axes(); ++i) {
92 CHECK_EQ(bottom[0]->shape(axis_ + i), scale->shape(i))
93 << "dimension mismatch between bottom[0]->shape(" << axis_ + i
94 << ") and scale->shape(" << i << ")";
95 }
96 outer_dim_ = bottom[0]->count(0, axis_);
97 scale_dim_ = scale->count();
98 inner_dim_ = bottom[0]->count(axis_ + scale->num_axes());
99 if (bottom[0] == top[0]) { // in-place computation
100 temp_.ReshapeLike(*bottom[0]);
101 } else {
102 top[0]->ReshapeLike(*bottom[0]);
103 }
104 sum_result_.Reshape(vector<int>(1, outer_dim_ * scale_dim_));
105 const int sum_mult_size = std::max(outer_dim_, inner_dim_);
106 sum_multiplier_.Reshape(vector<int>(1, sum_mult_size));
107 if (sum_multiplier_.cpu_data()[sum_mult_size - 1] != Dtype(1)) {
108 caffe_set(sum_mult_size, Dtype(1), sum_multiplier_.mutable_cpu_data());
109 }
110 if (bias_layer_) {
111 bias_bottom_vec_[0] = top[0];
112 bias_layer_->Reshape(bias_bottom_vec_, top);
113 }
114}
115
116template <typename Dtype>
117void ScaleLayer<Dtype>::Forward_cpu(

Callers

nothing calls this directly

Calls 10

caffe_setFunction · 0.85
num_axesMethod · 0.80
CanonicalAxisIndexMethod · 0.80
shapeMethod · 0.80
countMethod · 0.80
ReshapeLikeMethod · 0.80
sizeMethod · 0.45
getMethod · 0.45
cpu_dataMethod · 0.45
mutable_cpu_dataMethod · 0.45

Tested by

no test coverage detected