define gradient at zero to be zero
authorJack Culpepper <jackculpepper@gmail.com>
Sun, 19 Oct 2014 15:31:29 +0000 (08:31 -0700)
committerJack Culpepper <jackculpepper@gmail.com>
Sun, 19 Oct 2014 15:31:29 +0000 (08:31 -0700)
src/caffe/layers/absval_layer.cpp
src/caffe/layers/absval_layer.cu

index 54e484b..c347d46 100644 (file)
@@ -26,12 +26,11 @@ template <typename Dtype>
 void AbsValLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top,
     const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {
   const int count = top[0]->count();
-  const Dtype* top_data = top[0]->cpu_data();
   const Dtype* top_diff = top[0]->cpu_diff();
   if (propagate_down[0]) {
     const Dtype* bottom_data = bottom[0]->cpu_data();
     Dtype* bottom_diff = bottom[0]->mutable_cpu_diff();
-    caffe_div(count, top_data, bottom_data, bottom_diff);
+    caffe_cpu_sign(count, bottom_data, bottom_diff);
     caffe_mul(count, bottom_diff, top_diff, bottom_diff);
   }
 }
index 732d4c6..91f3c77 100644 (file)
@@ -23,7 +23,7 @@ void AbsValLayer<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top,
   if (propagate_down[0]) {
     const Dtype* bottom_data = bottom[0]->gpu_data();
     Dtype* bottom_diff = bottom[0]->mutable_gpu_diff();
-    caffe_gpu_div(count, top_data, bottom_data, bottom_diff);
+    caffe_gpu_sign(count, bottom_data, bottom_diff);
     caffe_gpu_mul(count, bottom_diff, top_diff, bottom_diff);
   }
 }