2
votes

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
change this 'input_shape=(32, 32, 3)'Rahul Verma

1 Answers

1
votes

It seems like the dataset is in (Height, Width, CHannel) format but the model is expecting (Channel, Height, Width) format.

We can convert between these using the tf.transpose() function which can "switch" around the dimensions of a tensor.

TO convert a single image tensor from HWC to CHW just do:

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

To convert a batch you can do:

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