caffe icon indicating copy to clipboard operation
caffe copied to clipboard

In Place Computation for ReLU with slope when x < 0 seems to do backprop wrong.

Open forest342003 opened this issue 11 years ago • 4 comments

It seems that in place computation is not possible with ReLU when there is a negative slope for when x < 0. The reason is for the following code: top_data[i] = std::max(bottom_data[i], Dtype(0)) + negative_slope * std::min(bottom_data[i], Dtype(0));

If negative_slope is negative, then top_data will always be positive. Since top_data== bottom_data then bottom_data will always be positive. Therefore, during backprop bottom_diff[i] = top_diff[i] * ((bottom_data[i] > 0) + negative_slope * (bottom_data[i] <= 0)); it will always say that bottom_data[i] > 0 when, in fact, this may not always be the case.

forest342003 avatar May 04 '15 20:05 forest342003

Did you take into account that, if top==bottom, during forward, bottom_data is backed up with caffe_copy(count, bottom_data, bottom_memory_.mutable_cpu_data()); and during backward, it is re-assigned using bottom_data = bottom_memory_.cpu_data();

sontran avatar May 04 '15 21:05 sontran

I am a contributor of PReLU implementation. Thanks for suggesting possible bug in PReLU and ReLU, however, I also have the same question with @sontran. If you already have numerical results that show wrong computation, it would be helpful to discuss about it.

tnarihi avatar May 04 '15 21:05 tnarihi

At first I didn't, I apologize for that, but I noticed that part and modified the issue. I still believe it is an issue with the ReLU layer.

forest342003 avatar May 04 '15 21:05 forest342003

Probably ReLULayer doesn't expect to take negative negative_slope.

tnarihi avatar May 04 '15 21:05 tnarihi