C2W3 model fit error

I keep getting this error in C2W3 assignment; why is it happening?

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

I sent it, but I don’t see it nor would it let me end again. Did you get my notebook?

Your notebook works. Am I missing anything?

It isn’t working for me. I kept getting that error at model.fit()

Your notebook is working at my end.

Please describe the environment are you using.
Let’s start with:

  1. Tensorflow version
  2. output of nvidia-smi

I restarted runtime and it worked

However the same problem persists in C2W4 assignment and restarting is not helping

You’ve sent C2W3 notebook to me on this direct message. Is that the right one?
Seems like you want to fix C2W4. Please confirm.

Yes sorry
I sent C2W4 now

I have the same Error, that is why my work was graded 75/100. Will you explain me the same issue?
All tests passed for train_val_generators!

All tests passed for create_pre_trained_model!

All tests passed for output_of_last_layer!

Details of failed tests for create_final_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 1807, in binary_crossentropy
    backend.binary_crossentropy(y_true, y_pred, from_logits=from_logits),
File "/opt/conda/lib/python3.7/site-packages/keras/backend.py", line 5158, in binary_crossentropy
    return tf.nn.sigmoid_cross_entropy_with_logits(labels=target, logits=output)

ValueError: `logits` and `labels` must have the same shape, received ((None, 2) vs (None, 1)).

.

The assignment deals with a binary classification. Please fix the number of units in the final dense layer.

Hi Balaji,

Thank you for bringing up the issue with the final dense layer in the create_final_model function.
It seems that the modification of the final dense layer to have 1 unit and using the sigmoid activation has significantly improved model’s performance. Accuracy of 0.9981 on the training set and 1.0000 on the validation set is indeed exceptional and indicates that model is learning the task effectively.

Keep up the fantastic work!