# Week 4, Assignment 1, Exercise 2 (Verify) brief question

Hi all,

I’m almost there with Ex. 2 (Verify)

The main situation seems to be that I’m calculating the distance erroneously.

The output is a single float value (stored as a tf tensor), but it does not match the expected calculation value, see below:

#first line shows the output of: print(dist)

``````tf.Tensor(0.29555342, shape=(), dtype=float32)
It's bertrand, welcome in!
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-63-166ca75f1224> in <module>
1 # BEGIN UNIT TEST
----> 2 assert(np.allclose(verify("images/camera_1.jpg", "bertrand", database, FRmodel), (0.54364836, True)))
3 assert(np.allclose(verify("images/camera_3.jpg", "bertrand", database, FRmodel), (0.38616243, True)))
4 assert(np.allclose(verify("images/camera_1.jpg", "younes", database, FRmodel), (1.3963861, False)))
5 assert(np.allclose(verify("images/camera_3.jpg", "younes", database, FRmodel), (1.3872949, False)))

AssertionError:
``````

My calculation of dist: 0.29
Test #1’s assertion: 0.54

Clearly the calculation of ‘dist’ is erroneous. I’ve set the anchor to be the value obtained by calling the identity key from database. The image in question has been set to encoding, which is a function of image_path and model.

The dist equation is the same as the distance equations in the previous exercise (triplet loss), without setting an axis. This is because both encodings appear to be single degree tensors of 128 values, rather than m instances of 128 values.

For add’l clarity, I am calculating dist first (innermost) by subtracting database[identity] by encoding, then squaring that difference, then performing reduce_sum on the squared differences to add the elements of the sum of squared errors together. I am assuming that squaring the difference of each element will automatically set the elements to be positive values.

What else could it be?

Solution found.

the way to calculate distance is found in the prompt…somehow missed it the few times I was reading it!