Multiclassification C2W4 Assignment - output layer definition

Some details -

  • I have done one hot encoding of labels. I can see the expected output does not match for: train_val_generators.
    My Output-
Images of training generator have shape: (27455, 28, 28, 1)
Labels of training generator have shape: (27455, 26)
Images of validation generator have shape: (7172, 28, 28, 1)
Labels of validation generator have shape: (7172, 26)

Expected Output

Images of training generator have shape: (27455, 28, 28, 1)*
Labels of training generator have shape: (27455,)*
Images of validation generator have shape: (7172, 28, 28, 1)*
Labels of validation generator have shape: (7172,)*

Though model compiles fine. I used categorical_crossentropy for loss function & softmax in the output layer. Last layer looks like -

 dense_19 (Dense)            (None, 26)                3354  

The grader gives below error -

    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

I understand the error. i.e. it’s expecting an output of shape[1]. But in a multiclassifier, how do we get the Model to give one label in the output layer?

My understanding was that the model would give a probability & we would do argmax to find the index with highest probablility?

Please see the ungraded lab C1_W2_Lab_2_callbacks.ipynb.

1 Like

Thanks Balaji. I searched this a bit, seems both are correct implementation.

But if I were to take Hint from expected output for: train_val_generators, I should have not done a one-hot encoding for the labels & hence I would need to use sparse_categorical_crossentropy.

Is this understanding correct?

And thank a lot for such a prompt response!

1 Like

You are correct.

1 Like