ValueError: Error when checking input: expected conv2d_1_input to have 4 dimensions, but got array w

Posted peng8098

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ValueError: Error when checking input: expected conv2d_1_input to have 4 dimensions, but got array w相关的知识,希望对你有一定的参考价值。

  • 报错
Traceback (most recent call last):
  File "D:/PyCharm 5.0.3/WorkSpace/3.Keras/3.构建各种神经网络/3.CNN.py", line 46, in <module>
    model.fit(x_train, y_train, epochs=1, batch_size=32)
  File "D:\Anaconda3\lib\site-packages\keras\engine\training.py", line 952, in fit
    batch_size=batch_size)
  File "D:\Anaconda3\lib\site-packages\keras\engine\training.py", line 751, in _standardize_user_data
    exception_prefix='input')
  File "D:\Anaconda3\lib\site-packages\keras\engine\training_utils.py", line 128, in standardize_input_data
    'with shape ' + str(data_shape))
ValueError: Error when checking input: expected conv2d_1_input to have 4 dimensions, but got array with shape (60000, 28, 28)
  • 原因
    输入的格式不对
  • 解决
    将数据集标准化
x_train = x_train.reshape(x_train.shape[0],1,28,28)/255
x_test = x_test.reshape(x_test.shape[0],1,28,28)/255
y_train = np_utils.to_categorical(y_train,num_classes=10)
y_test = np_utils.to_categorical(y_test,num_classes=10)

以上是关于ValueError: Error when checking input: expected conv2d_1_input to have 4 dimensions, but got array w的主要内容,如果未能解决你的问题,请参考以下文章

ValueError: Object arrays cannot be loaded when allow_pickle=False

完美解决:ValueError: Object arrays cannot be loaded when allow_pickle=False

数据分析,使用plt.hist(runtime_data, num_bin_list)时出现ValueError: `bins` must increase monotonically, when a

pandas apply返回多列时出错ValueError: Must have equal len keys and value when setting with an iterable解决方案

pandas apply返回多列时出错ValueError: Must have equal len keys and value when setting with an iterable解决方案

When “ERROR CAN NOT MAP ERROR CODE : 21” is displayed