C4W4L02 One Shot Learning

Lecture excerpt (Andrew Ng) explaining the one-shot learning challenge in face recognition and proposing learning a similarity function D that maps pairs of images to a distance measure. The function is used for verification (compare to threshold τ) and recognition (pairwise compare a new image to a stored database) enabling recognition from a single example without retraining for new identities.
Chapters
One of the challenges of face recognition is that you need to solve the one shot learning problem. What that means is that for most face recognition applications, you need to be able to recognize a person given just one single image or given just one example of that person's face. And historically, deep learning algorithms don't work well if you have only one training example. Let's see an example of what this means and then talk about how to address this this problem. Let's say you have a database of four pictures of employees in your organization. These are actually some of my colleagues at Deeplearning, AI Kian, Danielle, Eunice and Tian. Now, let's say someone shows up at the office and they want to be led through the turnstile. What the system has to do is, despite ever having seen only one image of Danielle, to recognize that this is actually the same person. And in contrast, if it sees someone that's not in this database, then it should recognize that this is not any of the four persons in the database. So in the one shot learning problem, you have to learn from just one example to recognize the person again. And you need this for most face recognition systems because you might have only one picture of each of your employees or each of your team members in your employee database. So one approach you could try is to input the image of the person, feed it to a confnet, and have it output a label Y using a softMax unit with four outputs, or maybe five outputs corresponding to each of these four persons, or none of the above. So that would be five outputs in the softmax. But this really doesn't work well, because if you have such a small training set is really not enough to train a robust neural network for this task. And also, what if a new person joins your team? Um, so now you have five persons you need to recognize. So there should now be six outputs. Do you have to retrain the continent every time? That just doesn't seem like a good approach. So to carry out face recognition, to carry out one shot learning. So instead to make this work, what you're gonna do instead is learning similarity function. In particular, you want a neural network to learn a function which is going to denote D which inputs two images and outputs the degree of difference between the two images. So if the two images are of the same person, you want this to output a small number, and if the two images are of two very different people, you want it to output a large number. So, so during recognition time, if the degree of difference between them is less than some threshold called tau, which is a parameter, a hyperparameter, then you would predict that these two pictures are of the same person. And if it's greater than tau, you would predict that these are different persons. And so this is how you address the face verification problem. To use this for a recognition task, what you do is given this new picture, you would use this function D to compare these two images and maybe output a very large number, let's say 10 for this example. And then you compare this with the second image in your database. And because these two are the same person, hopefully I'll put a very small number. And then you do this for the other images in your database and so on. And based on this, you would figure out that this is actually that person, which is Danielle. And in contrast, if someone not in your database shows up as you use the function D to make all of these pairwise comparisons, hopefully D will output a very large number for all four pairwise comparisons. And then you say that this is not any one of the four persons in the database. Notice how this allows you to solve the one shot learning problem. So long as you can learn this function D which inputs a pair of images and tells you basically if they're the same person or different persons. Then if you have someone new join your team, you can add a fifth person to your database and it just works fine. So you've seen how learning this function D which inputs two images allows you to address the one shot learning problem in the next video. Let's take a look how at how you can actually train a neural network to learn this function D.










