W02 Assignment TypeError: x and y must have the same dtype, got tf.uint8 != tf.float32

Hello everybody,

I am facing a problem I can’t figure out.

I created the type changing function as follows:

(Solution code removed by staff)

But getting the following error at point when final dense layer is created:

---------------------------------------------------------------------------TypeError Traceback (most recent call last)
in

8
9 # Create the mnist object.–

10 mnist = MNIST(**args)

11

12 # Train the model.

in init(self, export_path, buffer_size, batch_size, learning_rate, epochs)

8 self._epochs = epochs

9 —>

10 self._build_model()

11 self.train_dataset, self.test_dataset = self._prepare_dataset()

12
in _build_model(self)

59 tf.keras.layers.Flatten(),

60 tf.keras.layers.Dense(128, activation=“relu”),—>

61 tf.keras.layers.Dense(10, activation=“softmax”)

62 ])

63

TypeError: x and y must have the same dtype, got tf.uint8 != tf.float32

Please do you have some hints on how to solve that?

Many thanks!

Jiri

Hi @jiri.palek,

Firstly, uploading the solution code publicly is against our code of conduct. I have removed it. You can upload the error though, the staff and mentors will try to help you after looking at them. In instances when we would need to look at the solution code, the staff or mentors will ask you to direct message them it.

Secondly, after looking at the code you had posted, I wasn’t able to figure out the issue. Can you share your lab ID with me ? I’ll take an in depth look at your notebook. When you are in your assignment, you’ll see a “Help” icon on the top right, when you’ll click on it the panel will open and your lab ID will be shown at the bottom.

Thanks,
Mubsi

3 Likes

Hello @Mubsi ,

First of all, my appology for inapropriate sharing.

Next, thank you for your answer. I will have a look at my solution again when I am fresh and if the trouble still persists, I will follow your instruction and share the ID.

Please have a nice day!
Jiri