Python ValueError:检查输入时出错:预期输入有4个维度,但得到了具有形状的数组(859307,1)
我正在创建一个卷积自动编码器,它接收16x16个图像,但我一直收到以下错误:Python ValueError:检查输入时出错:预期输入有4个维度,但得到了具有形状的数组(859307,1),python,tensorflow,keras,conv-neural-network,dimension,Python,Tensorflow,Keras,Conv Neural Network,Dimension,我正在创建一个卷积自动编码器,它接收16x16个图像,但我一直收到以下错误: Traceback (most recent call last): File "WTApruning.py", line 69, in <module> validation_data=(x_test, x_test)) File "/PycharmProjects/predictivemodel/venv/lib/python3.6/site-packages/tensorflow/py
Traceback (most recent call last):
File "WTApruning.py", line 69, in <module>
validation_data=(x_test, x_test))
File "/PycharmProjects/predictivemodel/venv/lib/python3.6/site-packages/tensorflow/python/keras/engine/training.py", line 709, in fit
shuffle=shuffle)
File "/PycharmProjects/predictivemodel/venv/lib/python3.6/site-packages/tensorflow/python/keras/engine/training.py", line 2651, in _standardize_user_data
exception_prefix='input')
File "/PycharmProjects/predictivemodel/venv/lib/python3.6/site-packages/tensorflow/python/keras/engine/training_utils.py", line 376, in standardize_input_data
'with shape ' + str(data_shape))
ValueError: Error when checking input: expected input to have 4 dimensions, but got array with shape (859307, 1)
添加了重塑后的新错误:
Traceback (most recent call last):
File "WTApruning.py", line 43, in <module>
x_train = x_train.reshape(x_train,(len(x_train),16,16,1))
TypeError: only integer scalar arrays can be converted to a scalar index
回溯(最近一次呼叫最后一次):
文件“wtaprunning.py”,第43行,在
x_列=x_列。重塑(x_列,(len(x_列),16,16,1))
TypeError:只能将整数标量数组转换为标量索引
未重新整形的错误:
Traceback (most recent call last):
File "WTApruning.py", line 68, in <module>
validation_data=(x_test, x_test))
File "/PycharmProjects/predictivemodel/venv/lib/python3.6/site-packages/tensorflow/python/keras/engine/training.py", line 709, in fit
shuffle=shuffle)
File "/PycharmProjects/predictivemodel/venv/lib/python3.6/site-packages/tensorflow/python/keras/engine/training.py", line 2651, in _standardize_user_data
exception_prefix='input')
"/PycharmProjects/predictivemodel/venv/lib/python3.6/site-packages/tensorflow/python/keras/engine/training_utils.py", line 376, in standardize_input_data
'with shape ' + str(data_shape))
ValueError: Error when checking input: expected input to have 4 dimensions, but got array with shape (859307, 1)
回溯(最近一次呼叫最后一次):
文件“wtaprunning.py”,第68行,在
验证数据=(x检验,x检验)
文件“/PycharmProjects/predictivemodel/venv/lib/python3.6/site packages/tensorflow/python/keras/engine/training.py”,第709行
洗牌
文件“/PycharmProjects/predictivemodel/venv/lib/python3.6/site packages/tensorflow/python/keras/engine/training.py”,第2651行,在用户数据中
异常(前缀为“输入”)
标准化输入数据中的第376行“/PycharmProjects/predictivemodel/venv/lib/python3.6/site packages/tensorflow/python/keras/engine/training_utils.py”
“带形状”+str(数据形状))
ValueError:检查输入时出错:预期输入有4个维度,但得到了具有形状的数组(859307,1)
您输入的x\U序列不是4d输入。
您应该在将其送入网络之前对其进行重塑。
最好的如果您的输入是16x16个图像,为什么您的x_列的形状像(859307,1)?正确。我会检查x_列的输入大小now@MatiasValdenegro还刚刚添加了我用来定义x_train和x_testCode的代码,x_testCode没有告诉我们太多,您正在手动将其重塑为(-1859307,1),为什么?删除了那一行。更新了代码,改了一行-谢谢。
Traceback (most recent call last):
File "WTApruning.py", line 68, in <module>
validation_data=(x_test, x_test))
File "/PycharmProjects/predictivemodel/venv/lib/python3.6/site-packages/tensorflow/python/keras/engine/training.py", line 709, in fit
shuffle=shuffle)
File "/PycharmProjects/predictivemodel/venv/lib/python3.6/site-packages/tensorflow/python/keras/engine/training.py", line 2651, in _standardize_user_data
exception_prefix='input')
"/PycharmProjects/predictivemodel/venv/lib/python3.6/site-packages/tensorflow/python/keras/engine/training_utils.py", line 376, in standardize_input_data
'with shape ' + str(data_shape))
ValueError: Error when checking input: expected input to have 4 dimensions, but got array with shape (859307, 1)