CNTK icon indicating copy to clipboard operation
CNTK copied to clipboard

Efficient Siamese network implementation

Open sreeyella opened this issue 10 years ago • 2 comments

Hi,

I am trying to efficiently implement a Siamese network (http://yann.lecun.com/exdb/publis/pdf/chopra-05.pdf) in CNTK. The network learns a projection that maps the input samples into a d-dimensional space where the samples belonging to the same class are closer than samples belonging to different classes. The network can be trained using loss functions based on some distance measure such as Euclidean/Cosine/KL etc.,

The objective is to train the above network given a training set of samples distributed among N classes. The usual implementation of the network would require forward passing all possible pairs of samples in a minibatch through the network. This would require each sample to be passed multiple times (in combination with all other samples in the minibatch to come up with all possible same/different class examples) which is not necessary. Instead one can forward pass all the samples in a minibatch once and then use the activations of the final projection layer and the corresponding labels of the samples to create all possible pairwise samples. Which can be fed to the loss function.

I think this would require implementing a new node which can read a matrix of features and their corresponding labels and create a bigger matrix of all possible pairs of features with their new labels (same/different). Any thoughts/suggestions how to go about implementing this ?

Thank you, Sree.

sreeyella avatar May 06 '16 18:05 sreeyella

Hi, I meet the same problem. Have you got the efficient implementation?

1026112881 avatar Feb 07 '17 01:02 1026112881

Could you please try: cosine distance with negative samples. https://cntk.ai/pythondocs/cntk.losses.html#cntk.losses.cosine_distance_with_negative_samples

This function is now available in V2. Closing this issue as resolved please reopen if you have further issues.

sayanpa avatar Jul 15 '17 00:07 sayanpa