Keras input shape throws value error expected 4d but got an array with shape (60000, 28,28)

前端 未结 2 519
执念已碎
执念已碎 2021-01-28 15:18
(x_train, y_train), (x_test, y_test) = tf.keras.datasets.fashion_mnist.load_data()
x_train = x_train.astype(\'float32\') / 255
x_test = x_test.astype(\'float32\') / 255
         


        
2条回答
  •  悲哀的现实
    2021-01-28 16:13

    You are missing the channels dimension (with a value of one), it can be easily corrected by reshaping the array:

    x_train = x_train.reshape((-1, 28, 28, 1))
    x_test = x_test.reshape((-1, 28, 28, 1))
    

提交回复
热议问题