1

When I print(inp_shape) I get (288, 512, 3). However I still get the

ValueError: Error when checking input: expected conv2d_1_input to have 4 
dimensions, but got array with shape (120, 1)

I don't understand where the shape (120, 1) comes from.

dropout_prob = 0.2
activation_function = 'relu'
loss_function = 'categorical_crossentropy'
verbose_level = 1
convolutional_batches = 32
convolutional_epochs = 3
inp_shape = X_training.shape[1:]
num_classes = 2
opt = SGD()
opt2 = 'adam'

y_train_cat = np_utils.to_categorical(y_training, num_classes) 
y_test_cat = np_utils.to_categorical(y_testing, num_classes)

model = Sequential()
model.add(Conv2D(filters=16, kernel_size=(3, 3), input_shape=inp_shape))
model.add(Conv2D(filters=32, kernel_size=(3, 3)))
#model.add(MaxPooling2D(pool_size = (2,2)))
#model.add(Dropout(rate=dropout_prob))
model.add(Flatten())
model.add(Dense(128,activation=activation_function))
#model.add(Dropout(rate=dropout_prob))
model.add(Dense(64,activation=activation_function))
#model.add(Dropout(rate=dropout_prob))
model.add(Dense(32,activation=activation_function))
model.add(Dense(num_classes,activation='softmax'))
model.summary()
model.compile(loss=loss_function, optimizer=opt, metrics=['accuracy'])
history = model.fit(X_training, y_train_cat, batch_size=convolutional_batches, epochs = convolutional_epochs, verbose = verbose_level, validation_data=(X_testing, y_test_cat))
model.save('../models/neural_net.h5')
2
  • what is the full shape of X_training ? Commented Aug 2, 2017 at 7:22
  • What does model.summary() tell give you? Commented Aug 27, 2018 at 19:28

1 Answer 1

2

add this line

X_training= tf.reshape(X_training,[-1,288, 512, 3])

before feeding X_training to the model.fit

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

Comments

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.