use Blob directly instead of shared_ptr for EltwiseLayer::max_idx_
authorJonathan L Long <jonlong@cs.berkeley.edu>
Thu, 11 Sep 2014 05:06:15 +0000 (22:06 -0700)
committerEvan Shelhamer <shelhamer@imaginarynumber.net>
Thu, 18 Sep 2014 19:41:45 +0000 (12:41 -0700)
This is in keeping with #742.

include/caffe/common_layers.hpp
src/caffe/layers/eltwise_layer.cpp
src/caffe/layers/eltwise_layer.cu

index 190b5c2..deb4a57 100644 (file)
@@ -178,7 +178,7 @@ class EltwiseLayer : public Layer<Dtype> {
 
   EltwiseParameter_EltwiseOp op_;
   vector<Dtype> coeffs_;
-  shared_ptr<Blob<int> > max_idx_;
+  Blob<int> max_idx_;
 
   bool stable_prod_grad_;
 };
index 46034be..ca157a8 100644 (file)
@@ -40,8 +40,7 @@ void EltwiseLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom,
   // If max operation, we will initialize the vector index part.
   if (this->layer_param_.eltwise_param().operation() ==
       EltwiseParameter_EltwiseOp_MAX && top->size() == 1) {
-    max_idx_.reset(new Blob<int>(bottom[0]->num(), channels,
-                                 height, width));
+    max_idx_.Reshape(bottom[0]->num(), channels, height, width);
   }
 }
 
@@ -69,7 +68,7 @@ void EltwiseLayer<Dtype>::Forward_cpu(
     break;
   case EltwiseParameter_EltwiseOp_MAX:
     // Initialize
-    mask = max_idx_->mutable_cpu_data();
+    mask = max_idx_.mutable_cpu_data();
     caffe_set(count, -1, mask);
     caffe_set(count, Dtype(-FLT_MAX), top_data);
     // bottom 0 & 1
@@ -138,7 +137,7 @@ void EltwiseLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top,
         }
         break;
       case EltwiseParameter_EltwiseOp_MAX:
-        mask = max_idx_->cpu_data();
+        mask = max_idx_.cpu_data();
         for (int index = 0; index < count; ++index) {
           Dtype gradient = 0;
           if (mask[index] == i) {
index c0d47fd..16cb6cc 100644 (file)
@@ -53,7 +53,7 @@ void EltwiseLayer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,
     }
     break;
   case EltwiseParameter_EltwiseOp_MAX:
-    mask = max_idx_->mutable_gpu_data();
+    mask = max_idx_.mutable_gpu_data();
     // NOLINT_NEXT_LINE(whitespace/operators)
     MaxForward<Dtype> <<<CAFFE_GET_BLOCKS(count), CAFFE_CUDA_NUM_THREADS>>>(
         count, bottom[0]->gpu_data(), bottom[1]->gpu_data(), 0, top_data, mask);
@@ -118,7 +118,7 @@ void EltwiseLayer<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top,
         }
         break;
       case EltwiseParameter_EltwiseOp_MAX:
-        mask = max_idx_->gpu_data();
+        mask = max_idx_.gpu_data();
         MaxBackward<Dtype>  // NOLINT_NEXT_LINE(whitespace/operators)
             <<<CAFFE_GET_BLOCKS(count), CAFFE_CUDA_NUM_THREADS>>>(
             count, top_diff, i, mask, bottom_diff);