Course 4 Week 4 Assignment 1 (Face recognition)


I have finished the week 4 face recognition assignment and keep getting a grade of 0 even though I am confident my code is correct (as I have reproduced all the required answers for each sub-component of the code).

Can someone please help me resolve this?


Hi, Tom.

Sorry, but passing the tests in the notebook is not always a guarantee of passing the grader. Writing complete test cases is not such an easy task, it turns out.

The first question is whether you get any meaningful feedback from the grader other than just the 0 points. What does it say under “Show grader feedback”? Please “copy/paste” over whatever it says there. Sometimes you can at least tell whether it’s some kind of systemic problem or whether it’s just that it doesn’t agree with your code. Then we’ll go from there …


Hi Paul,

Thanks for the timely response. This is the error message that I am seeing under the grader output:

ell #4. Can’t compile the student’s code. Error: SyntaxError(‘EOF while scanning triple-quoted string literal’, (’/tmp/student_solution_cells/’, 45, 1290, ‘’’’\ntf.random.set_seed(1)\ny_true = (None, None, None) # It is not used\ny_pred = (tf.keras.backend.random_normal([3, 128], mean=6, stddev=0.1, seed = 1),\n tf.keras.backend.random_normal([3, 128], mean=1, stddev=1, seed = 1),\n tf.keras.backend.random_normal([3, 128], mean=3, stddev=4, seed = 1))\nalpha = 0.2\n\nanchor, positive, negative = y_pred[0], y_pred[1], y_pred[2]\n\nprint("— anchor shape —")\nprint(anchor.shape)\n\nprint("-- positive —")\nprint(positive.shape)\n\npositive_dist = tf.square(tf.subtract(anchor, positive))\nprint("— positive_dist —")\nprint(positive_dist.shape)\n\nanchor, positive, negative = y_pred[0], y_pred[1], y_pred[2]\n\n# Step 1: Compute the (encoding) distance between the anchor and the positive\npos_dist = tf.reduce_sum(tf.square(tf.subtract(anchor, positive)), axis = -1)\n\nprint("— pos_dist—")\nprint(pos_dist)\n\n# Step 2: Compute the (encoding) distance between the anchor and the negative\nneg_dist = tf.reduce_sum(tf.square(tf.subtract(anchor, negative)), axis = -1)\nprint("— neg_dist ----")\nprint(neg_dist)\n\n# Step 3: subtract the two previous distances and add alpha.\nbasic_loss = tf.add(tf.subtract(pos_dist,neg_dist),alpha)\nprint("-- basic_loss —")\nprint(basic_loss)\n\nloss = tf.reduce_sum(tf.maximum(basic_loss,0.0))\nprint(loss)\n’))


Hmmm, the formatting of the message makes it a little tough to read, but I think the salient part is this:

I would recommend searching for the string tf.random.set_seed and see if you can see any funny looking multiple quotes nearby. If you don’t see anything sketchy looking, the other strategy might be to get a clean copy of the notebook and very carefully “copy/paste” over just your completed code and see if that makes a difference. The theory being that you may have accidentally corrupted something in the template code. There is a topic on the FAQ Thread about how to get a clean copy. FWIW, I did not encounter any such problems on this assignment.

I reset my notebook and copied my old code line by line and it resolved the issue. Thank you Paul, appreciate your help!

That’s great news! So the theory must be that something got damaged accidentally. Thanks for confirming.