Week 4 >>> Face_Recognition programming exercise >>> Exercise 2 - verify

Yes, when I do it your way, here’s the beginning of the output, which you didn’t show:

Dist for bertrand = tf.Tensor([0.54364824], shape=(1,), dtype=float32)
It's bertrand, welcome in!
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-17-02e2f1840f11> in <module>
----> 1 assert(np.allclose(verify("images/camera_1.jpg", "bertrand", database, FRmodel), (0.54364836, True)))
      2 assert(np.allclose(verify("images/camera_3.jpg", "bertrand", database, FRmodel), (0.38616243, True)))
      3 assert(np.allclose(verify("images/camera_1.jpg", "younes", database, FRmodel), (1.3963861, False)))
      4 assert(np.allclose(verify("images/camera_3.jpg", "younes", database, FRmodel), (1.3872949, False)))
      5 

<__array_function__ internals> in allclose(*args, **kwargs)

The key thing to notice there is that the shape of dist is (1,), meaning that it is a “rank 1” tensor and not a scalar. Here’s what it looks like when I remove the “axis” argument:

Dist for bertrand = tf.Tensor(0.54364824, shape=(), dtype=float32) It's bertrand, welcome in! Dist for bertrand = tf.Tensor(0.38616234, shape=(), dtype=float32) It's bertrand, welcome in! Dist for younes = tf.Tensor(1.3963861, shape=(), dtype=float32) It's not younes, please go away Dist for younes = tf.Tensor(1.3872949, shape=(), dtype=float32) It's not younes, please go away Dist for younes = tf.Tensor(0.5992949, shape=(), dtype=float32) It's younes, welcome in!

Out[19]:

See the difference? It’s perfectly fine for it to be a tensor, but it has to be of the correct shape.

But as Tom mentioned above, you can do the whole thing with straight numpy and no TF at all and it also works fine.

1 Like