vlfeat / matconvnet

MatConvNet: CNNs for MATLAB
Other
1.4k stars 756 forks source link

how to use vl_nnpdist for siamese networks? #302

Open virusme opened 8 years ago

virusme commented 8 years ago

Hi, I had a look at this issue https://github.com/vlfeat/matconvnet/issues/253

I am trying to append a vl_nnpdist block as a last layer to construct a siamese network.

@vedaldi mentions "..The trick is to pass pairs of images as consecutive entries in the sequence and then use a block such as vl_nnpdist that would pair them up in the loss."

However, vl_nnpdist expects "x" and "x0" as inputs with "p", "noRoot" and "epsilon" as other parameters. Hence, the below line in vl_simplenn:

case 'pdist' res(i+1) = vl_nnpdist(res(i).x, l.p, 'noRoot', l.noRoot, 'epsilon', l.epsilon) ;

throws an error because it is passing "p" as second argument.

What am I doing wrong? Your advice will be appreciated.

May be the github version of vl_nnpdist or vl_simplenn is an older version?

virusme commented 8 years ago

@vedaldi some insight to this would be really helpful :-)

virusme commented 8 years ago

I have made some changes to vl_simplenn in order to handle consecutive image-samples as image-pairs:

Forward pass:

res(i+1).x = vl_nnpdist(res(i).x(:,:,:,1:2:end), res(i).x(:,:,:,2:2:end), l.p, 'noRoot', l.noRoot, 'epsilon', l.epsilon) ;

Backward pass:

tmp = vl_nnpdist(res(i).x(:,:,:,1:2:end), res(i).x(:,:,:,2:2:end), l.p, res(i+1).dzdx, ... 'noRoot', l.noRoot, 'epsilon', l.epsilon) ; if gpuMode res(i).dzdx = gpuArray( single( zeros( size(tmp,1), size(tmp,2), size(tmp,3), size(tmp,4)_2))); else res(i).dzdx = single( zeros( size(tmp,1), size(tmp,2), size(tmp,3), size(tmp,4)_2)); end res(i).dzdx(:,:,:,1:2:end) = tmp; res(i).dzdx(:,:,:,2:2:end) = tmp;

@vedaldi , @lenck I am interested in knowing if I have missed something that is really obvious? or if have gone off in a tangent?

cheer37 commented 8 years ago

have you constructed your siamese network? if, yes, How did you make the input and configure your net?

cheer37 commented 8 years ago

@virusme you didn't solve your problem?