In [[[Week 4 >>> Face_Recognition programming exercise >>> Exercise 2 - verify]]] I got this error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-97-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)))
<__array_function__ internals> in allclose(*args, **kwargs)
/opt/conda/lib/python3.7/site-packages/numpy/core/numeric.py in allclose(a, b, rtol, atol, equal_nan)
2157
2158 """
-> 2159 res = all(isclose(a, b, rtol=rtol, atol=atol, equal_nan=equal_nan))
2160 return bool(res)
2161
<__array_function__ internals> in isclose(*args, **kwargs)
/opt/conda/lib/python3.7/site-packages/numpy/core/numeric.py in isclose(a, b, rtol, atol, equal_nan)
2255 y = array(y, dtype=dt, copy=False, subok=True)
2256
-> 2257 xfin = isfinite(x)
2258 yfin = isfinite(y)
2259 if all(xfin) and all(yfin):
TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
I figured out the error came from the dist
calculation, and I managed to solve it using numpy()
to convert the tf tensor to a numpy array and np.asscalar()
to convert the numpy array to a scalar, as shown below, but it seems like a very patchy solution.
dist = np.asscalar(((tf.norm( tf.subtract(encoding, database[identity]), axis=-1 )).numpy()))
How did others write the dist
line to avoid that error?
Thanks for your time
Jaime