#include #include "caffe/layers/absval_layer.hpp" #include "caffe/util/math_functions.hpp" namespace caffe { template void AbsValLayer::LayerSetUp(const vector*>& bottom, const vector*>& top) { NeuronLayer::LayerSetUp(bottom, top); CHECK_NE(top[0], bottom[0]) << this->type() << " Layer does not " "allow in-place computation."; } template void AbsValLayer::Forward_cpu( const vector*>& bottom, const vector*>& top) { const int count = top[0]->count(); Dtype* top_data = top[0]->mutable_cpu_data(); caffe_abs(count, bottom[0]->cpu_data(), top_data); } template void AbsValLayer::Backward_cpu(const vector*>& top, const vector& propagate_down, const vector*>& bottom) { const int count = top[0]->count(); 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_cpu_sign(count, bottom_data, bottom_diff); caffe_mul(count, bottom_diff, top_diff, bottom_diff); } } #ifdef CPU_ONLY STUB_GPU(AbsValLayer); #endif INSTANTIATE_CLASS(AbsValLayer); REGISTER_LAYER_CLASS(AbsVal); } // namespace caffe