Keras展平层输入形状

时间:2018-09-01 16:53:09

标签: tensorflow keras keras-layer

我正在运行以下Keras模型:

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)

X的形状是在运行时打印的:

Shape of x: (6457,)

但是,我遇到的错误是:

  

期望flatten_input具有4维,但是数组的形状   (6457,1)

1 个答案:

答案 0 :(得分:0)

我没有正确调整图像大小。我以为CV2函数可以正常工作,但是必须让它们返回到我正在传递的变量中,就像这样:

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

在此之后,只需向Flatten层提供图像大小(64,64):

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