Problem in exercise 6-Programming Assignment: TensorFlow Introduction

for the excersie 6 I have this line of code:

{moderator edit - solution code removed}

but I get this error:

tf.Tensor(0.17102128, shape=(), dtype=float32)

AssertionError Traceback (most recent call last)
in
17 print(“\033[92mAll test passed”)
18
—> 19 compute_total_loss_test(compute_total_loss, new_y_train )

in compute_total_loss_test(target, Y)
13 print(result)
14 assert(type(result) == EagerTensor), “Use the TensorFlow API”
—> 15 assert (np.abs(result - (0.50722074 + 1.1133534) / 2.0) < 1e-7), “Test does not match. Did you get the reduce sum of your loss functions?”
16
17 print(“\033[92mAll test passed”)

AssertionError: Test does not match. Did you get the reduce sum of your loss functions?

can’t realize where I am mistaken. Any help is appreciated!

You also need to transpose the labels and logits.

2 Likes

thanks @paulinpaloalto, this solved the problem. but can I ask the reason behind this, as the categorical_crossentropy function looks automatically handle the appropriate shapes of the inputs

Well it turns out that the TF functions cannot handle any arrangement of the inputs. They assume that the “samples” dimension is first, but Prof Ng has used the orientation of features x samples ever since the very beginning of Course 1 because the vector operations work better for feed forward networks and he repeats that in the way the forward propagation logic is defined in this assignment. But this is the first time that we use TF, so we have to rearrange the data in the way that TF expects.

3 Likes

I get same or similar issue error

total_loss = 0.0285035465
Test 1: tf.Tensor(0.028503546, shape=(), dtype=float32)

AssertionError Traceback (most recent call last)
in
25 print(“\033[92mAll test passed”)
26
—> 27 compute_total_loss_test(compute_total_loss, new_y_train )

in compute_total_loss_test(target, Y)
13 print("Test 1: ", result)
14 assert(type(result) == EagerTensor), “Use the TensorFlow API”
—> 15 assert (np.abs(result - (0.50722074 + 1.1133534) / 2.0) < 1e-7), “Test 1 does not match. Did you get the reduce sum of your loss functions?”
16
17 ### Test 2

AssertionError: Test 1 does not match. Did you get the reduce sum of your loss functions?

In compute_totoal_loss
Do the categoricallCrossEntrophy (from_logits=True)
Then do reduc_sum

What else do you expecct.
Why not fix those testing scripts ?

There is nothing wrong with the testing scripts. That means your code is not correct. Now you need to figure what is wrong.

Here’s a thread that lists the most common mistakes on this function.

1 Like