CNN - Week 4

Week 4 covered challenges for doing face verification and recognition and how to do neural style transfer.

Face verification and recognition

  • Verification, is this person X?
  • Recognition, who is this person?

Even if the accuracy is high on the verification, since we need to test vs all images in the possible space for recognition, we might end up with false positives if the amount of possible people in the set is large.

One shot learning

Oftentimes with face recognition, you only have one image of the employee to learn from which usually doesn’t work well with learning.

A way to get around this is to train the network to learn a similarity function between images so that if then they are a match.

For a new image, you perform pairwise comparisons towards all known persons in the database.

Another of the benefits of this approach, as opposed to a softmax multiclassification with likelihoods, is that adding new persons doesn’t impact the difference ratings for the others, so they remain unaffected.

Siamese network

A network is put in place that outputs a unit encoding based on an input image. This output vector is then compared to another output vector generated by an identical network (i.e. Siamese twin…) to calculate the distance between the encodings.

Triplet loss

In order to learn the vector encoding of images, you can use the triplet loss function which trains on triplets of images with one anchor image (A) of the person, and then two images of which one is another image of the person in question (P), and the other is an image of another person (N).

The goal during training is to ensure;

In order to avoid the network learning a trivial solution of always outputting zero, the parameter is added in order to ensure we have a margin between the two distance function outputs. Rearranged we get the loss function;

Since as long as the value is below zero, the loss is zero. Summed over the set for the cost function;

Choosing triplets

When preparing the training sets, it’s good to choose negative pictures in each triplet that is hard to train on, i.e. where the distance isn’t very big.

Choosing triplets randomly will mean very many triplets are very easy, and thus won’t force the algorithm to learn useful features it will encounter in the wild.

Face verification and binary classification

An alternative to triplet loss is to generate encodings for two images that then are fed into a logistic output unit for binary classification of whether the input images are of the same person or not.

Neural Style Transfer

Based on input images content (C) and style (S), a third image is generated (G) that applies the styles from S onto the content of C. In broad strokes;

  1. Initiate the generated image G randomly
  2. Use gradient descent to minimize

Cost functions

Where the content cost function is the difference in activation between the content image and the generated image in layer in a pretrained ConvNet.

For the style cost function, “style” is defined as the correlation between activations across channels. Since the higher level features becomes things like patterns, textures and shapes and they tend to correlate heavily in the source image set, they should also correlate in the generated image.

is activation at . is .

…and the same for the generated image.

These style matrixes are also sometimes called gram matrixes, which is why G is used for the function.

…restating and adding a normalisation term;

Finally, in practice usually you get a more aestethically pleasing result using a combination of multiple layers.

Comments