Face Recognition Programming Assignment - Exercise 3

The result:
it’s younes, the distance is tf.Tensor(0.35915437, shape=(), dtype=float32)
it’s younes, the distance is tf.Tensor(0.35915437, shape=(), dtype=float32)

AssertionError Traceback (most recent call last)
5 # Test 2 with Younes pictures
6 test1 = who_is_it(“images/camera_0.jpg”, database, FRmodel)
----> 7 assert np.isclose(test1[0], 0.5992946)
8 assert test1[1] == ‘younes’


I’m using the same code in exercise 2 to calculate distance. In exercise 2 I pass it, but in exercise 3 it returns an error. How do I fix it?

Hey @yahyasyukri,
Welcome to the community. Can you please DM your code for the function who_is_it to me? For DM, click on my name and select “Message”.

P.S. - Posting code publicly is strictly against the community guidelines, so, please refrain from doing so.


Hey @yahyasyukri,
In this function, dist represents the L2 distance between the target “encoding” and the current db_enc from the database. However, in your code, you are computing the square of the L2 distance, i.e., you need to change the below line of code from:

dist = tf.reduce_sum(tf.square(tf.subtract(db_enc, encoding)))


dist = tf.reduce_sum(tf.square(tf.subtract(db_enc, encoding[0])))**0.5

Do check if you have done the same mistake in your previous functions as well. If so, then do correct them as well. I hope this helps.


It works. Thank you very much

1 Like

Why are we taking power of 0.5? Can you please explain

Taking power of 0.5 is under root…

Hey @Shubham219,
In addition to @saifkhanengr’s answer, taking root is the part of the formulation of L2 distance or L2 norm. You can check out the formulation once for your reference.