Error in TF1 Course 2 Week 4 Assignment - but runs

Hi,

In my C2W4 assignment, I did used one-hot encoding and my model was able to be run achieving 99% training accuracy and 99% validation accuracy. But when I submitted the assignment, I got 89% with grader notes that said that there was an error as follows: - I think this was an error? Please advise.

======================================================
Details of failed tests for create_model

Failed test case: your model could not be used for inference. Details shown in ‘got’ value below:.
Expected:
no exceptions,
but got:
in user code:

File "/opt/conda/lib/python3.7/site-packages/keras/engine/training.py", line 1366, in test_function  *
    return step_function(self, iterator)
File "/opt/conda/lib/python3.7/site-packages/keras/engine/training.py", line 1356, in step_function  **
    outputs = model.distribute_strategy.run(run_step, args=(data,))
File "/opt/conda/lib/python3.7/site-packages/keras/engine/training.py", line 1349, in run_step  **
    outputs = model.test_step(data)
File "/opt/conda/lib/python3.7/site-packages/keras/engine/training.py", line 1306, in test_step
    y, y_pred, sample_weight, regularization_losses=self.losses)
File "/opt/conda/lib/python3.7/site-packages/keras/engine/compile_utils.py", line 201, in __call__
    loss_value = loss_obj(y_t, y_p, sample_weight=sw)
File "/opt/conda/lib/python3.7/site-packages/keras/losses.py", line 141, in __call__
    losses = call_fn(y_true, y_pred)
File "/opt/conda/lib/python3.7/site-packages/keras/losses.py", line 245, in call  **
    return ag_fn(y_true, y_pred, **self._fn_kwargs)
File "/opt/conda/lib/python3.7/site-packages/keras/losses.py", line 1665, in categorical_crossentropy
    y_true, y_pred, from_logits=from_logits, axis=axis)
File "/opt/conda/lib/python3.7/site-packages/keras/backend.py", line 4994, in categorical_crossentropy
    target.shape.assert_is_compatible_with(output.shape)

ValueError: Shapes (None, 1) and (None, 26) are incompatible

.

Hello @rajanivij78 ,

Send me your notebook via dm such that I can check where it went wrong. By clicking on the profile picture, you will see an option to message. There you can attach your notebook. Then we can discuss the issues here, under the topic you created.

With regards,
Nilosree Sengupta

Hello @rajanivij78 ,

I have gone through your notebook.

There are multiple issues:

  1. GRADED FUNCTION: parse_data_from_input
    I see, your code is commented out and multiple print statements, seems you tried to print it manually.
    You don’t need to worry about printing.There is a cell below to print :
# grader-required-cell
# Test your function

Kindly re-write.

  1. GRADED FUNCTION: train_val_generators
  • You have taken the wrong axis.
  • You don’t need to print labels. Remove.
  • Datagen only has 1 parameter- rescale-to normalize pixel values. But you have put more parameters.Remove others.
  1. def create_model():
    Multiple parameters are wrong.

Your overall notebook seems a little confused and going like a hit and trial method. As a mentor, I can’t say the code, though I have given you multiple hints to fix it. I would suggest you kindly go through the lessons again.

Happy learning!!

With regards,
Nilosree Sengupta

Hi,

Thank you for the suggestions. I agree I’ve used some print statements but as you noted, these were used by me before I submitted. I agree my algo can certainly have some improvements.
I still have my question about the error shown only during grading which seems misleading. Shouldn’t we perform one-hot encoding as I’ve done?. If so, then the below in the mark down cell is incorrect.

I get the below.

In fact, the model only runs when we have the above as there are 26 classes.
So can you please advise me more about that? Isn’t this an error in the grading?

If the grade is more indicative of the improvements on my algo that’s ok. Its just that the comments from grading are misleading then.

More q on your comments below:-

  • GRADED FUNCTION: train_val_generators - You’ve said I’ve taken the wrong axis. How can that be when I do get the correct output when I train the model? (99% training and validation accuracy?) Are you also considering some obsolete(commented statements that maybe I haven;t cleaned before?)
  • Datagen - I’m using some data augmentation too and that improved the accuracy of my validation. Since I’m getting 99% validation which is more than what is asked by the exercise isn;t that ok to do? In fact we may achieve the goal of 99% training and > 95% validation if we do not perform augmentation, but I’ve observed, doing augmentation in this manner improves validation accuracy. Also, I’ve only used augmentation across parameters that make sense for this dataset, for example, not considering any orientation change, etc. as that may not make sense for this dataset.

Again, thank you so much for your response and going through my notebook. I apologize if it seems like I’m going back and forth , but just trying to correct my understanding.

Regards,
Rajani

From your outputs, I’d guess that you hard-coded the value 26 somewhere that you shouldn’t have. The grader’s tests probably don’t use 26 units.
(I’m not a mentor for that course, just a bystander).

Hello @rajanivij78 ,

It’s really great that you are trying out multiple things and this experience of playing with code will teach you the best, besides knowing theory!

Could you kindly share a clean notebook in dm. By clean notebook I mean removing the commented out codes that you think is not correct and keeping only the code in non-commented form that you submit to the grader for evaluation. Otherwise It’s causing a confusion as I am unable to interpret which commented out code you are keeping and dont wanna keep amidst hit and trial.
Kindly remove print statements too for manual printing.

And If you want to keep multiple codes commented out for future reference, just create a copy of your notebook, then remove the unnecessary part and send it to me.

With regards,
Nilosree Sengupta

I had the same problem, My grade was 89 because I hot encoded the classes.

Sorry for the delayed response. Please find a clean notebook.
Copy_of_C2W4_Assignment.ipynb (130.6 KB)
Thank you again for your help and guidance.