Course 4, week 4, exercise 1

{moderator edit - solution code removed}


Can somebody please tell me why i am getting this error and hoc can I fix it?

Take another look at the formulas you are implementing. The problem is that the sums used to compute pos_dist and neg_dist are supposed to end up as vectors with one value per image, but the way you have implemented it you end up with a scalar value.

The reduction to a scalar is supposed to happen only at the very last step.

Also note that you filed this under General Discussion, so I moved it to DLS Course 4 for you.

thank you for reply, so how can I change it in order to get as vectors with one value per image?

i tried to put reduce sum just in last step but it is still giving error:

ah i manage to solve the problem!

Check these 2 points from the Notebook.

  • For steps 1 and 2, maintain the number of m training examples and sum along the 128 values of each encoding. tf.reduce_sum has an axis parameter. This chooses along which axis the sums are applied.
  • Note that one way to choose the last axis in a tensor is to use negative indexing (axis=-1).

Glad to know that…~~~

but i am a bit confused, what are dimensions of pos_dist and neg_dist?

You can check the dimension by printing out the shape. You may use tf.shape(neg_dist.shape) or neg_dist.shape.