DLS Course 4 Assignment 2 Face verify error

Despite using the right function, there exists error

encoding = img_to_encoding(image_path, model)
dist = np.linalg.norm(encoding - database[identity], ord=2)) #None

Also, when used
dist = np.linalg.norm(encoding, database[identity]) #

Could you please check @paulinpaloalto @TMosh

The first implementation looks correct to me. The second one is clearly wrong: you are passing two separate vector arguments to np.linalg.norm, but it takes only one. The other arguments are things like ord, not other vectors. You did read the documentation, right? The point is we are computing the length of the difference between the computed encoding and the database version, so we need to subtract the two vectors first, which is what your first solution correctly does.

So what I bet happened is that after you typed in the correct code, you did not hit “Shift - Enter” to “compile” (well it’s really an interpreter, but whatever :nerd_face:) the new version. So you were not running the correct code. Type in that code again and then make sure everything is consistent by doing “Kernel → Restart and Clear Output” and then “Cell → Run All” and see if it works now. It’s important to remember that the notebooks are not really a WYSIWYG interface. What you are running is not necessarily what you are seeing unless you are paying careful attention to execute the function cells after typing in them. Just calling the function again runs the old code. You can easily demonstrate this effect to yourself. Take a function that works and now add a print statement in the body of the function, but do not hit “Shift - Enter”. Now call the function again from the test cell and no print comes out, right? Now hit “Shift - Enter” on the actual function cell and then run the test cell again. Bingo! Give it a try!

Thanks for the your quick reply.
However, I downloaded the assignment just this month.
Therefore I highly doubt if its related to new version

It looks issue with vector and not scalar
a.any() or a.all()

That error was from the second incorrect version of your code, right? I already explained why that is wrong. Try the first version again.

Also what do you mean by “downloaded just this month”? If you are running the notebooks in some environment other than the course website, then all bets are off. It is a huge hassle to get all the stuff downloaded and all the right versions of software configured.

Sorry for misunderstanding.
I meant…I just opened this programming assignment just last week.

Hence it is the newest version available. Hence I really doubted about the version issue.

Where did I say anything about versions of the notebook? I’m talking about versions of your code. I suggest you read my first reply again more carefully.

I tried this suggestion but still the error persist.

Also, for the next exercise,

UNQ_C3(UNIQUE CELL IDENTIFIER, DO NOT EDIT)

Similar to earlier exercise,
I tried

Compute L2 distance between the target “encoding” and the current db_enc from the database. (≈ 1 line)

    dist = np.linalg.norm(database[name], db_enc) #None

But still there is similar error even in this exercise

But the point is that you are using the wrong version of your code. I explained all of this in my original reply on this thread. np.linalg.norm takes only one vector as the argument. Did you read the documentation?

But think about what it is the instructions tell you to do:

  1. Compute the vector difference between the computed encoding and the database version for the relevant person.
  2. Compute the 2-norm of that difference vector.

Where in your code do you compute the difference? You did in the original version you showed in your first post on this thread.

1 Like

Your code for calling np.linalg.norm() is incorrect.

  • You’re passing the function two vectors.
  • It only accepts one vector.

So please fix your code.

1 Like

Thanks @TMosh and @paulinpaloalto

I read documentation and adjusted the code but still it shows the error

Best part the same module works for another example

Also, for the 3rd exercise,
I have the similar issue :slight_smile:

Did you notice that your code for “if dist > 0.7…” is incorrect?
A small distance value indicates the that picture matches the database.
That’s why the comment says “Step 3: Open the door if dist < 0.7…”
Your logic is backwards.

1 Like

Thanks @TMosh
I accepted your solution.