Question on C2W4 assignment

I recently completed the C2W4 assignment and i had a question after grading. First. i used one-hot encoding and categorical_crossentropy. Before i onehot coded it i received an Value error ValueError: Shapes (None, 1) and (None, 25) are incompatible. Then i changed to sparse. with a .002 learning rate. 100% got it. then i one hot encoded and used categorical, and got this error: ValueError: Shapes (None, 1) and (None, 25) are incompatible. Then i dropped one of the units in the last layer to 24, it ran and passed, but 89/100 with this grader comment. ValueError: Shapes (None, 1) and (None, 24) are incompatible. still passed on it. Any thoughts appreciated

Please share your error screenshot. Do not post any code screenshot as it is against community guidelines.

logits and labels must be broadcastable: logits_size=[32,25] labels_size=[32,24]
[[{{node categorical_crossentropy/softmax_cross_entropy_with_logits}}]] [Op:__inference_train_function_901]

This is the error when i run categorical with 25 units

Thats when i used one hot on labels

Hello @gtcoogee

Kindly let us know

  1. The most important part is parse data from input grader cell, note in this grader cell you need to append the labels with row[0] and image with row[1:]
    Next if you have correctly reshape the images and labels and converted them into array form correctly using numpy.
  2. in the train val generator grader cell
    In this section you will have to add another dimension to the data, what axis did you include and did you use Hint: np.expand_dims
  3. Next mention for train and val generator what all parameter you used. Hint keep it as simple as possible.
  4. Your batch size?
  5. your model architecture like how many conv2d layers and dense layers choice, last dense layer’s activation?
  6. Next optimizer and metric choice.

P.S. in this assignment using one hot label to label the images is incorrect. Read the instructions before the grader cell again carefully or refer the point 1 above mentioned.

Regards
DP

Hello @gtcoogee

the section GRADED FUNCTION: parse_data_from_input
where it mentions to use csv.reader, passing in the appropriate delimiter,
you recalled row =1(which is incorrect)
Also you did not include delimiter “,” while reading the file

Next for row in csv_reader, you were suppose to append the labels to row[0] and images to row[1:]
Then first convert the images into array shape by using astype(‘float64’), then reshaping images as image.shape[0],28,28
for label converting into array shape by using astype(‘float64’)

I suppose you passed the grader because
You will not be graded based on the accuracy of your model but try making it as high as possible for both training and validation, as an optional exercise, after submitting your notebook for grading.

Below is screenshot of your model training

So actually you can practice around your model and try to improve your accuracy if you want to learn more about models training.

This is only for your practice purpose and not for passing grader:
One thing I noticed difference in your and mine model, you have chosen different optimizer, notice most of the time if softmax activation is used, you could use adam, next your first dense layer units probably could be reduced

While adding another dimension in the train-val generator, your axis choice is -1,
Hint: instruction given

  • You need to add the “color” dimension to the numpy arrays that encode the images. These are black and white images, so this new dimension should have a size of 1 (instead of 3, which is used when dealing with colored images). Take a look at the function np.expand_dims for this. So which could be better choice for axis here??

At the end it is only for practice as you were interested in learning which I am glad.

Feel free to ask any doubt.

Regards
DP