Skip to content

Commit

Permalink
Merge pull request BVLC#2165 from longjon/auto-reshape
Browse files Browse the repository at this point in the history
Always call Layer::Reshape in Layer::Forward
  • Loading branch information
jeffdonahue committed May 14, 2015
2 parents 07f56a0 + f61c374 commit cadc42b
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 8 deletions.
1 change: 1 addition & 0 deletions include/caffe/layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ template <typename Dtype>
inline Dtype Layer<Dtype>::Forward(const vector<Blob<Dtype>*>& bottom,
const vector<Blob<Dtype>*>& top) {
Dtype loss = 0;
Reshape(bottom, top);
switch (Caffe::mode()) {
case Caffe::CPU:
Forward_cpu(bottom, top);
Expand Down
1 change: 0 additions & 1 deletion src/caffe/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,6 @@ Dtype Net<Dtype>::ForwardFromTo(int start, int end) {
}
for (int i = start; i <= end; ++i) {
// LOG(ERROR) << "Forwarding " << layer_names_[i];
layers_[i]->Reshape(bottom_vecs_[i], top_vecs_[i]);
Dtype layer_loss = layers_[i]->Forward(bottom_vecs_[i], top_vecs_[i]);
loss += layer_loss;
if (debug_info_) { ForwardDebugInfo(i); }
Expand Down
4 changes: 0 additions & 4 deletions src/caffe/test/test_neuron_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,14 +541,10 @@ TYPED_TEST(NeuronLayerTest, TestPReLUInPlace) {
caffe_copy(ip2.blobs()[0]->count(), ip.blobs()[0]->cpu_data(),
ip2.blobs()[0]->mutable_cpu_data());
// Forward in-place
ip.Reshape(this->blob_bottom_vec_, this->blob_top_vec_);
ip.Forward(this->blob_bottom_vec_, this->blob_top_vec_);
prelu.Reshape(this->blob_top_vec_, this->blob_top_vec_);
prelu.Forward(this->blob_top_vec_, this->blob_top_vec_);
// Forward non-in-place
ip2.Reshape(blob_bottom_vec_2, blob_middle_vec_2);
ip2.Forward(blob_bottom_vec_2, blob_middle_vec_2);
prelu2.Reshape(blob_middle_vec_2, blob_top_vec_2);
prelu2.Forward(blob_middle_vec_2, blob_top_vec_2);
// Check numbers
for (int s = 0; s < blob_top_2->count(); ++s) {
Expand Down
3 changes: 0 additions & 3 deletions tools/caffe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,6 @@ int time() {
forward_timer.Start();
for (int i = 0; i < layers.size(); ++i) {
timer.Start();
// Although Reshape should be essentially free, we include it here
// so that we will notice Reshape performance bugs.
layers[i]->Reshape(bottom_vecs[i], top_vecs[i]);
layers[i]->Forward(bottom_vecs[i], top_vecs[i]);
forward_time_per_layer[i] += timer.MicroSeconds();
}
Expand Down

0 comments on commit cadc42b

Please sign in to comment.