When I run the following code:
from keras import models
from keras import layers
from keras import optimizers
model = models.Sequential()
model.add(layers.Dense(256, activation='relu', input_shape = (4, 4, 512)))
model.add(layers.Dropout(0.5))
model.add(layers.Dense(1, activation='sigmoid'))
model.compile(optimizer=optimizers.RMSprop(lr=2e-5),
loss='binary_crossentropy',
metrics=['acc'])
model.summary()
history = model.fit(train_features, train_labels,
epochs=30,
batch_size=20,
validation_data=(validation_features, validation_labels))
I get this error:
ValueError: Error when checking input: expected dense_40_input to have 2 dimensions, but got array with shape (2000, 4, 4, 512)
Here is the shape of training and validation data:
print(train_features.shape, train_labels.shape, validation_features.shape, validation_labels.shape)
Output:
(2000, 4, 4, 512) (2000,) (1000, 4, 4, 512) (1000,)
Whats happening here? My train and validation shape should be the same as what I just specified. Even when I change to input_dim = 4*4*512 I still get an error.
Output of model.summary():
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
dense_42 (Dense) (None, 4, 4, 256) 131328
_________________________________________________________________
dropout_19 (Dropout) (None, 4, 4, 256) 0
_________________________________________________________________
dense_43 (Dense) (None, 4, 4, 1) 257
=================================================================
Total params: 131,585
Trainable params: 131,585
Non-trainable params: 0
_________________________________________________________________
My Keras version is 2.1.6.
import keras; print(keras.__version__).model.summary()as well.model.summary(): Layer (type) Output Shape Param # =============================================================== dense_42 (Dense) (None, 4, 4, 256) 131328 dropout_19 (Dropout) (None, 4, 4, 256) 0 dense_43 (Dense) (None, 4, 4, 1) 257 Total params: 131,585 Trainable params: 131,585 Non-trainable params: 0