Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in Data Science by (17.6k points)

I want to train CNN for cifar10 datasets but got this error Error when checking input: expected conv2d_10_input to have shape (3, 32, 32) but got array with shape (32, 32, 3)

this is my CNN model

epochs = 10 batch_size = 32

model.fit(X_train, Y_train, validation_data=(X_test, Y_test), epochs=epochs, batch_size=batch_size, verbose = 1)

1 Answer

0 votes
by (41.4k points)

Here, the format of dataset is (Height, Width, Channel) and  the format which the model is expecting is (Channel, Height, Width).

So, using the tf.transpose() function we can switch around the dimensions of a tensor.

For converting a single image tensor from HWC to CHW:

reshaped = tf.transpose(image_tensor, (2,0,1))

And for converting a batch:

reshaped = tf.transpose(images_tensor, (0,3,1,2))

Browse Categories

...