Week 4 Assignment 3 Exercise 1

In the assignment → Programming Assignment: Deep Neural Network - Application,
The compute_cost function is returning Nan value.

Used command is -
cost = compute_cost(A2, Y)

Output is below
Cost after iteration 1: nan

Please click my name and message your notebook as an attachment.

This is the file name.
/notebooks/release/W4A2/Deep Neural Network - Application.ipynb

Not sure how to find the link click my name and message in notebook.

File > Download > Download .ipynb and message the notebook as an attachment. Here’s the community faq to get started.

Are you sure that you are taking the logarithm of the A values and not the Y values?

If you got that code correct, then the other possibility is that your A values are wrong. Do you mean that error message happened in the test for the compute_cost function or one of the “model” functions?

Also note that there are only 2 assignments in DLS C1 W4, so the title is misleading.

PFA the file attached for your reference.

{moderator edit - solution notebook removed}

Your forward and back propagation logic for two_layer_model is incorrect. In both directions, you have used “relu” as the activation at both layers. That’s not the way the network is configured, right?

Actually that explains the NaN from the cost: your output A2 should only include values between 0 and 1, but with ReLU as the output activation that will not be true. That causes you to take the log of a negative number in the Y = 0 term in the loss function.

Thank you for your clarifications. I could rectify the error based on your guidance.