TypeError: Cannot convert 'bertrand' to EagerTensor of dtype float

CNNs Week 4 Exercise 2

At first run this worked perfectly but when I was running the malicious entry from Kian i got this message. I restarted the Kernel and the error message appears on the first check. Any ideas?


TypeError Traceback (most recent call last)
in
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)))

in verify(image_path, identity, database, model)
20 encoding = img_to_encoding(image_path, model)
21 # Step 2: Compute distance with identity’s image (≈ 1 line)
—> 22 dist = tf.subtract(encoding, identity)
23 # Step 3: Open the door if dist < 0.7, else don’t open (≈ 3 lines)
24 if dist < 0.7:

/opt/conda/lib/python3.7/site-packages/tensorflow/python/util/dispatch.py in wrapper(*args, **kwargs)
199 “”“Call target, and fall back on dispatchers if there is a TypeError.”“”
200 try:
→ 201 return target(*args, **kwargs)
202 except (TypeError, ValueError):
203 # Note: convert_to_eager_tensor currently raises a ValueError, not a

/opt/conda/lib/python3.7/site-packages/tensorflow/python/ops/math_ops.py in subtract(x, y, name)
525 @dispatch.add_dispatch_support
526 def subtract(x, y, name=None):
→ 527 return gen_math_ops.sub(x, y, name)
528
529

/opt/conda/lib/python3.7/site-packages/tensorflow/python/ops/gen_math_ops.py in sub(x, y, name)
10459 try:
10460 return sub_eager_fallback(

10461 x, y, name=name, ctx=_ctx)
10462 except _core._SymbolicException:
10463 pass # Add nodes to the TensorFlow graph.

/opt/conda/lib/python3.7/site-packages/tensorflow/python/ops/gen_math_ops.py in sub_eager_fallback(x, y, name, ctx)
10478
10479 def sub_eager_fallback(x, y, name, ctx):

10480 _attr_T, _inputs_T = _execute.args_to_matching_eager([x, y], ctx)
10481 (x, y) = _inputs_T
10482 _inputs_flat = [x, y]

/opt/conda/lib/python3.7/site-packages/tensorflow/python/eager/execute.py in args_to_matching_eager(l, ctx, default_dtype)
261 ret.append(
262 ops.convert_to_tensor(
→ 263 t, dtype, preferred_dtype=default_dtype, ctx=ctx))
264 if dtype is None:
265 dtype = ret[-1].dtype

/opt/conda/lib/python3.7/site-packages/tensorflow/python/framework/ops.py in convert_to_tensor(value, dtype, name, as_ref, preferred_dtype, dtype_hint, ctx, accepted_result_types)
1497
1498 if ret is None:
→ 1499 ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
1500
1501 if ret is NotImplemented:

/opt/conda/lib/python3.7/site-packages/tensorflow/python/framework/constant_op.py in _constant_tensor_conversion_function(v, dtype, name, as_ref)
336 as_ref=False):
337 _ = as_ref
→ 338 return constant(v, dtype=dtype, name=name)
339
340

/opt/conda/lib/python3.7/site-packages/tensorflow/python/framework/constant_op.py in constant(value, dtype, shape, name)
262 “”"
263 return _constant_impl(value, dtype, shape, name, verify_shape=False,
→ 264 allow_broadcast=True)
265
266

/opt/conda/lib/python3.7/site-packages/tensorflow/python/framework/constant_op.py in _constant_impl(value, dtype, shape, name, verify_shape, allow_broadcast)
273 with trace.Trace(“tf.constant”):
274 return _constant_eager_impl(ctx, value, dtype, shape, verify_shape)
→ 275 return _constant_eager_impl(ctx, value, dtype, shape, verify_shape)
276
277 g = ops.get_default_graph()

/opt/conda/lib/python3.7/site-packages/tensorflow/python/framework/constant_op.py in _constant_eager_impl(ctx, value, dtype, shape, verify_shape)
298 def _constant_eager_impl(ctx, value, dtype, shape, verify_shape):
299 “”“Implementation of eager constant.”“”
→ 300 t = convert_to_eager_tensor(value, ctx, dtype)
301 if shape is None:
302 return t

/opt/conda/lib/python3.7/site-packages/tensorflow/python/framework/constant_op.py in convert_to_eager_tensor(value, ctx, dtype)
96 dtype = dtypes.as_dtype(dtype).as_datatype_enum
97 ctx.ensure_initialized()
—> 98 return ops.EagerTensor(value, ctx.device_name, dtype)
99
100

TypeError: Cannot convert ‘bertrand’ to EagerTensor of dtype float

I re-downloaded the exercise and this time i used the L2 distance np.linalg.norm when I was trying to find the distance between the encoding and the identity in the database.

Problem solved!

As the exercise notes :

Note: In this implementation, compare the L2 distance, not the square of the L2 distance, to the threshold 0.7