Neural network 在Caffe框架中修改ReLU中的阈值
我是Caffe新手,现在我需要在卷积神经网络中修改ReLU层中的阈值。我现在使用的修改阈值的方法是编辑C++源代码:CAFE/SRC/CAFE/Leopu/ReluuLea. CPP ,并重新编译它。但是,每次调用ReLU时,这会将阈值更改为指定值。有没有办法在网络中的每个ReLU层中使用不同的值作为阈值?顺便说一下,我正在使用pycaffe接口,我找不到这样的方法Neural network 在Caffe框架中修改ReLU中的阈值,neural-network,deep-learning,caffe,pycaffe,Neural Network,Deep Learning,Caffe,Pycaffe,我是Caffe新手,现在我需要在卷积神经网络中修改ReLU层中的阈值。我现在使用的修改阈值的方法是编辑C++源代码:CAFE/SRC/CAFE/Leopu/ReluuLea. CPP ,并重新编译它。但是,每次调用ReLU时,这会将阈值更改为指定值。有没有办法在网络中的每个ReLU层中使用不同的值作为阈值?顺便说一下,我正在使用pycaffe接口,我找不到这样的方法 最后,很抱歉我的英语很差,如果有不清楚的地方,请告诉我,我会尽量详细描述。是的,你可以。在src/caffe/proto中,添加一
最后,很抱歉我的英语很差,如果有不清楚的地方,请告诉我,我会尽量详细描述。是的,你可以。在
src/caffe/proto
中,添加一行:
message ReLUParameter {
...
optional float threshold = 3 [default = 0]; #add this line
...
}
在src/caffe/layers/relu_layer.cpp
中,进行一些小的修改,如下所示:
template <typename Dtype>
void ReLULayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,
const vector<Blob<Dtype>*>& top) {
...
Dtype threshold = this->layer_param_.relu_param().threshold(); //add this line
for (int i = 0; i < count; ++i) {
top_data[i] = (bottom_data[i] > threshold) ? (bottom_data[i] - threshold) :
(negative_slope * (bottom_data[i] - threshold));
}
}
template <typename Dtype>
void ReLULayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top,
const vector<bool>& propagate_down,
const vector<Blob<Dtype>*>& bottom) {
if (propagate_down[0]) {
...
Dtype threshold = this->layer_param_.relu_param().threshold(); //this line
for (int i = 0; i < count; ++i) {
bottom_diff[i] = top_diff[i] * ((bottom_data[i] > threshold)
+ negative_slope * (bottom_data[i] <= threshold));
}
}
}
如果我理解正确,你的“带阈值的ReLU”基本上是
f(x) = x-threshold if x>threshold, 0 otherwise
您可以通过添加一个
“Bias”
层来轻松实现它,该层在常规“ReLU”
层之前从输入中减去阈值
?为什么是3?我知道阈值=3的意思。我的net.prototxt
在添加relu_参数{threshold:1}
而不是threshold:1
时工作。如果我使用threshold:1
,我会得到一个错误,如消息类型“caffe.LayerParameter”没有名为“threshold”的字段。对不起,我的粗心。我已经更正了我的答案。在你的向前传球中,第二个论点是最小值。应该是阈值而不是零。这里的门槛是什么意思?我想你需要改变功能…@Shai我的错。正如我从问题中看到的,这应该是你提到的第一个案例。我已经改正了,再次感谢!这应该是首选的解决方案。除非需要,否则应避免修改caffe
。谢谢,此解决方案更容易实现。Dale的答案很好,但应选择Shai的答案作为正确答案。不需要时,应避免修改Caffe。
f(x) = x-threshold if x>threshold, 0 otherwise