Course 4, Week 4, Assignment 1, Exercise 2

Hello,
My code seems right but I am getting below error. Can you help me?

encoding = img_to_encoding(image_path, model)
# Step 2: Compute distance with identity’s image (≈ 1 line)
dist = np.linalg.norm(encoding, database[“identity”])


KeyError 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 im = database[“identity”]
23 dist = np.linalg.norm(encoding, im)
24 # Step 3: Open the door if dist < 0.7, else don’t open (≈ 3 lines)

KeyError: ‘identity’

The error tells you that the key “identity” does not exist in the database dictionary.

The hints say that it is a key in the database dictionary:

Hints :

  • identity is a string that is also a key in the database dictionary.
  • img_to_encoding has two parameters: the image_path and model.

identity is a variable name.
You’re using it as a text string.