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

Method Reshape

src/caffe/layers/bias_layer.cpp:40–69  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38
39template <typename Dtype>
40void BiasLayer<Dtype>::Reshape(const vector<Blob<Dtype>*>& bottom,
41 const vector<Blob<Dtype>*>& top) {
42 const BiasParameter& param = this->layer_param_.bias_param();
43 Blob<Dtype>* bias = (bottom.size() > 1) ? bottom[1] : this->blobs_[0].get();
44 // Always set axis == 0 in special case where bias is a scalar
45 // (num_axes == 0). Mathematically equivalent for any choice of axis, so the
46 // actual setting can be safely ignored; and computation is most efficient
47 // with axis == 0 and (therefore) outer_dim_ == 1.
48 const int axis = (bias->num_axes() == 0) ?
49 0 : bottom[0]->CanonicalAxisIndex(param.axis());
50 CHECK_GE(bottom[0]->num_axes(), axis + bias->num_axes())
51 << "bias blob's shape extends past bottom[0]'s shape when applied "
52 << "starting with bottom[0] axis = " << axis;
53 for (int i = 0; i < bias->num_axes(); ++i) {
54 CHECK_EQ(bottom[0]->shape(axis + i), bias->shape(i))
55 << "dimension mismatch between bottom[0]->shape(" << axis + i
56 << ") and bias->shape(" << i << ")";
57 }
58 outer_dim_ = bottom[0]->count(0, axis);
59 bias_dim_ = bias->count();
60 inner_dim_ = bottom[0]->count(axis + bias->num_axes());
61 dim_ = bias_dim_ * inner_dim_;
62 if (bottom[0] != top[0]) {
63 top[0]->ReshapeLike(*bottom[0]);
64 }
65 bias_multiplier_.Reshape(vector<int>(1, inner_dim_));
66 if (bias_multiplier_.cpu_data()[inner_dim_ - 1] != Dtype(1)) {
67 caffe_set(inner_dim_, Dtype(1), bias_multiplier_.mutable_cpu_data());
68 }
69}
70
71template <typename Dtype>
72void BiasLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,

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