Error in who_is_it

I have successfully submitted my assignment and I haven’t found any errors. But still I see the message that there was an error in the “who_is_it” after submission.

def who_is_it(image_path, database, model):
“”"
Implements face recognition for the office by finding who is the person on the image_path image.

Arguments:
    image_path -- path to an image
    database -- database containing image encodings along with the name of the person on the image
    model -- your Inception model instance in Keras

Returns:
    min_dist -- the minimum distance between image_path encoding and the encodings from the database
    identity -- string, the name prediction for the person on image_path
"""

### START CODE HERE

## Step 1: Compute the target "encoding" for the image. Use img_to_encoding() see example above. ## (≈ 1 line)
encoding =  img_to_encoding(image_path, model)

## Step 2: Find the closest encoding ##

# Initialize "min_dist" to a large value, say 100 (≈1 line)
min_dist = 100

# Loop over the database dictionary's names and encodings.
for (name, db_enc) in database.items():
    
    # Compute L2 distance between the target "encoding" and the current db_enc from the database. (≈ 1 line)
    dist = np.linalg.norm(encoding-db_enc)

    # If this distance is less than the min_dist, then set min_dist to dist, and identity to name. (≈ 3 lines)
    if dist<min_dist:
        min_dist = dist
        identity = name
### END CODE HERE

if min_dist>0.7:
    print("Not in the database.")
else:
    print ("it's " + str(identity) + ", the distance is " + str(min_dist))
    
return min_dist, identity

After submission:
Code Cell UNQ_C1: Function ‘triplet_loss’ is correct.
Code Cell UNQ_C2: Function ‘verify’ is correct.
Code Cell UNQ_C3: Unexpected error (TypeError("’>’ not supported between instances of ‘NoneType’ and ‘float’")) occurred during function check. We expected function who_is_it to return compute_layer_style_cost test 1 failed. Please check that this function is defined properly.
If you see many functions being marked as incorrect, try to trace back your steps & identify if there is an incorrect function that is being used in other steps.
This dependency may be the cause of the errors.

Did you save your notebook before you submitted it for grading?

Have you re-named your notebook .ipynb file?

Hi @ChandiniSaiKumarDukk,

The error would have been shown in the unit tests as well. I am not sure why might be happening.
One possible reason might be as @TMosh said: maybe you had not submitted the latest saved file.

Thank you @TMosh @thearkamitra for your reply
I have figured why that is happening it is since I haven’t assigned any value for identity when I assigned the value to 0 the problem has been fixed.

I’m afraid that is a very wrong solution.
The ‘name’ and ‘identity’ values comes from these statements:

for (name, db_enc) in database.items():

and inside the for-loop and if-statements:
identity = name

You do not have to set ‘identity’ yourself. And forcing it to zero is not a good idea, because it’s only going to work in one specific instance.

Thank you @TMosh for your reply
I have initialized the value of identity =0 before the for loop, whereas I have maintained the value of identity= name in the for loop.

Thanks for your explanation.

I think your solution is not necessary, because if min_dist is initialized to an impossibly large value, then “identity” will be set to “name” on the first pass through the for-loop.

This should prevent “identity” from being undefined when the function returns.

In any case, setting identity = 0 as a default value is a poor choice, because “name” is a text string, and 0 is a number. So it is initializing identity to the wrong data type. Using a null string would be a better idea.