はい、可能です。 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));
}
}
}
と同様src/caffe/layers/relu_layer.cu
のコードはthisようでなければなりません。
そして、あなたのcaffe
とpycaffe
をコンパイルした後、あなたのnet.prototxt
では、あなたのようなrelu
層を書くことができます。
layer {
name: "threshold_relu"
type: "ReLU"
relu_param: {threshold: 1 #e.g. you want this relu layer to have a threshold 1}
bottom: "input"
top: "output"
}
デールの答えは良いですが、シャイの答えは正しいものとして選ぶべきです。 Caffeが必要でないときは、Caffeを変更しないでください。 – Jonathan