-#include <vector>
#include <cfloat>
+#include <vector>
#include "caffe/layer.hpp"
#include "caffe/util/math_functions.hpp"
bottom_data_b = bottom[1]->cpu_data();
for (int idx = 0; idx < count; ++idx) {
if (bottom_data_a[idx] > bottom_data_b[idx]) {
- top_data[idx] = bottom_data_a[idx]; // maxval
- mask[idx] = 0; // maxid
+ top_data[idx] = bottom_data_a[idx]; // maxval
+ mask[idx] = 0; // maxid
} else {
- top_data[idx] = bottom_data_b[idx]; // maxval
- mask[idx] = 1; // maxid
+ top_data[idx] = bottom_data_b[idx]; // maxval
+ mask[idx] = 1; // maxid
}
}
// bottom 2++
- bottom_data_a = top_data;
for (int blob_idx = 2; blob_idx < bottom.size(); ++blob_idx) {
bottom_data_b = bottom[blob_idx]->cpu_data();
for (int idx = 0; idx < count; ++idx) {
- if (bottom_data_a[idx] < bottom_data_b[idx]) {
+ if (bottom_data_b[idx] > top_data[idx]) {
top_data[idx] = bottom_data_b[idx]; // maxval
mask[idx] = blob_idx; // maxid
}
-#include <vector>
#include <cfloat>
+#include <vector>
#include "caffe/layer.hpp"
#include "caffe/util/math_functions.hpp"
}
}
-template<typename Dtype>
+template <typename Dtype>
void EltwiseLayer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,
vector<Blob<Dtype>*>* top) {
int* mask = NULL;
}
}
-template<typename Dtype>
+template <typename Dtype>
__global__ void MaxBackward(const int nthreads, const Dtype* top_diff,
const int blob_idx, const int* mask, Dtype* bottom_diff) {
CUDA_KERNEL_LOOP(index, nthreads) {
}
}
-template<typename Dtype>
+template <typename Dtype>
void EltwiseLayer<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top,
const vector<bool>& propagate_down, vector<Blob<Dtype>*>* bottom) {
const int* mask = NULL;
break;
case EltwiseParameter_EltwiseOp_MAX:
mask = max_idx_->gpu_data();
- // NOLINT_NEXT_LINE(whitespace/operators)
- MaxBackward<Dtype> <<<CAFFE_GET_BLOCKS(count), CAFFE_CUDA_NUM_THREADS>>>(
+ MaxBackward<Dtype> // NOLINT_NEXT_LINE(whitespace/operators)
+ <<<CAFFE_GET_BLOCKS(count), CAFFE_CUDA_NUM_THREADS>>>(
count, top_diff, i, mask, bottom_diff);
break;
default:
+#include <algorithm>
#include <vector>
#include "gtest/gtest.h"
blob_bottom_c_(new Blob<Dtype>(2, 3, 4, 5)),
blob_top_(new Blob<Dtype>()) {
// fill the values
+ Caffe::set_random_seed(1701);
FillerParameter filler_param;
UniformFiller<Dtype> filler(filler_param);
filler.Fill(this->blob_bottom_a_);
const Dtype* in_data_b = this->blob_bottom_b_->cpu_data();
const Dtype* in_data_c = this->blob_bottom_c_->cpu_data();
for (int i = 0; i < count; ++i) {
- EXPECT_GE(data[i], in_data_a[i]);
- EXPECT_GE(data[i], in_data_b[i]);
- EXPECT_GE(data[i], in_data_c[i]);
+ EXPECT_EQ(data[i],
+ std::max(in_data_a[i], std::max(in_data_b[i], in_data_c[i])));
}
}
EltwiseParameter* eltwise_param = layer_param.mutable_eltwise_param();
eltwise_param->set_operation(EltwiseParameter_EltwiseOp_MAX);
EltwiseLayer<Dtype> layer(layer_param);
- GradientChecker<Dtype> checker(1e-2, 1e-3);
+ GradientChecker<Dtype> checker(1e-4, 1e-3);
checker.CheckGradientEltwise(&layer, &(this->blob_bottom_vec_),
&(this->blob_top_vec_));
}