0

Everything is okay until I convert my image to grayscale. So the rgb's shape is (256, 256, 3) but grayscale has (256, 256). When I feed it, I get that error.

network = Sequential()

network.add(Convolution2D(32, kernel_size=(3, 3),strides=1,activation='relu',input_shape=(256, 256)))
network.add(MaxPooling2D((2, 2)))

# network.add(Convolution2D(32, kernel_size=(3, 3), strides=1, activation='relu'))
# network.add(MaxPooling2D((2, 2)))


network.add(Convolution2D(64, kernel_size=(3, 3), strides=1, activation='relu'))
network.add(MaxPooling2D((2, 2)))

# network.add(Convolution2D(64, kernel_size=(3, 3), strides=1, activation='relu'))
# network.add(MaxPooling2D((2, 2)))


network.add(Convolution2D(128, kernel_size=(3, 3), strides=1, activation='relu'))
network.add(MaxPooling2D((2, 2)))

# network.add(Convolution2D(128, kernel_size=(3, 3), strides=1, activation='relu'))
# network.add(MaxPooling2D((2, 2)))


network.add(Flatten())
network.add(Dense(256, activation = 'relu'))
network.add(Dense(2, activation = 'softmax'))

checkpoint_path = os.path.join("/---------/grayscale", "weights.best.hdf5")
checkpoint = ModelCheckpoint(checkpoint_path, monitor='val_accuracy', verbose=1, save_best_only=True, mode='max')
es = EarlyStopping(monitor='val_loss', mode='min', verbose=1, patience=10)
callbacks_list = [checkpoint, es]

network.compile(optimizer = 'adam', loss = 'categorical_crossentropy', metrics = ['accuracy'])

1 Answer 1

1

You have to feed images of shape 256x256x1 in your network.

To convert your initial x_train into your new X_train:

X_train=np.reshape(x_train,(x_train.shape[0], x_train.shape[1],x_train.shape[2],1))

and finally change your input_shape from input_shape=(256,256) to input_shape=(256,256,1)

Sign up to request clarification or add additional context in comments.

2 Comments

tnx. but why should I change it back to (256, 256, 3)?
it's (256,256,1), sorry it was a mistake (edited)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.