JY2k
JY2k

Reputation: 2909

Keras Flatten Layer Input Shape

I am running the following Keras model:

model = keras.Sequential([
    keras.layers.Flatten(input_shape=(6457,)),
    keras.layers.Dense(128, activation=tf.nn.relu),
    keras.layers.Dense(len(class_names), activation=tf.nn.softmax)
])

print("Shape of x: " + str(x.shape))
model.fit(x,y, epochs=5)

The shape of X is, as printed in runtime:

Shape of x: (6457,)

However, the error I am encountering is:

expected flatten_input to have 4 dimensions, but got array with shape (6457, 1)

Upvotes: 2

Views: 8957

Answers (1)

JY2k
JY2k

Reputation: 2909

I was improperly resizing the image. I thought the CV2 functions work in place but instead had to have them return into the variable I was passing on, like so:

im1 = cv2.resize(image, (64,64))
im2 = cv2.blur(im1,(5,5))
return im2

After this it was simply a matter of supplying the image size (64,64) to the Flatten layer:

keras.layers.Flatten(input_shape=(64,64))

Upvotes: 2

Related Questions