Assignment: Face Recognition

In the notebook cell for testing the function triplet_loss, the first test uses Tensor for y_pred[0], y_pred[1], and y_pred[2] , but all the other tests use list for these y_pred’s. My implementation of triplet_loss gives an exception because of incompatible types.

Any advice is greatly appreciated.

Vu

My temporary solution to pass the triplet_loss cell tests is to check the types of anchor,positive, and negative. If they are not Tensor, then convert them to Tensor, reshape them to have two dimensions then continue to the calculation of equation (3) using Tensor. This solution passes both the cell tests and the grader.

Do the tests really want students to do the above conversion if the inputs are not of the type Tensor ? Or do I misunderstand something ?

Thanks,

Vu

Hi Vu,

Using tensorflow methods with every calculation in triplet_loss() may resolve this.

Hope this helps.

Hi Reinoud,

Thanks for your reply.

I copied the cell test code and the triplet_loss function to ipython to run each command manually, and found that tf.reduce_sum complained when y_pred = ([1., 1.], [1., 1.], [1., 1.,]), which is from the 2nd test. In this case, the data has only one dimension, and tf.reduce_sum is called with axis=1 when calculating pos_dist and neg_dist.

The doc of the function does say the anchor, positive, and negative have two dimensions, but the test data has only one dimension. I am sure I miss something, but not sure what it is.

Thanks,

Vu

Hi Vu,

A way to think about it is this: Which axis value could you use that would not create this problem?

The provided hints may be helpful.

Good luck!

2 Likes

Thanks a lot Renoud. " Which axis value could you use that would not create this problem?" is what I need . The moment I read it I know what the problem is.

It works and the function looks clean.

Thanks,

Vu