vedaldi / practical-cnn-reg

A CNN practical focusing on image to image regression
29 stars 14 forks source link

Is there a bug on the exercise to check the L2 loss (creating my own layer)? #1

Open brando90 opened 8 years ago

brando90 commented 8 years ago

I was doing exercise 2.3 and designing my own layer (the L2 loss in particular) and couldn't make the derivatives match even though the implementation was provided by the tutorial, I just had to put it together to check it. In particular I had:

clc;clear;clc;clear;
%% Eucledian distance layer
x = randn(10, 10, 1, 2, 'single') ; % fake data
r = randn(10, 10, 1, 2, 'single') ; % reference tensor
p = randn(1); % projection

%% compute analytic derivative
dl2dx = l2LossBackward(x,r,p); % computes analytic derivative = backard pass
%% figures for difference between analytic and numerical
figure(22) ; clf('reset') ;
set(gcf, 'name', 'Part 2.3: check L2 layer') ;
%% compute numerical derivative
func = @(X) l2LossForward(X,r); % l2 loss = forward pass
checkDerivativeNumerically(func, x, dl2dx) ;

but it didn't work. I am confident that the implementation given should be correct. Why doesn't it work though?

Btw, are there solutions to the tutorial available somewhere?

MaxChu719 commented 8 years ago

you have not included the p in your numerical checking.