Python 3.x Keras“;“适合”;输入不清楚

Python 3.x Keras“;“适合”;输入不清楚,python-3.x,tensorflow,neural-network,keras,Python 3.x,Tensorflow,Neural Network,Keras,我正在尝试输入尺寸(350x350x3)的图像作为输入形状,我想训练网络输出(1400x1400x3)图像(4倍高比例) 我的训练数据集包含8幅图像1400x1400x3,我将这些图像翻过来,总共得到32幅图像进行验证 然后,我将这32幅图像缩小到350x350x3,以获得将与其他32幅图像交叉验证的输入图像 print(type(validateData)) print(validateData.shape) print(type(validateData[0].shape)) print(v

我正在尝试输入尺寸
(350x350x3)
的图像作为输入形状,我想训练网络输出
(1400x1400x3)
图像(4倍高比例)

我的训练数据集包含8幅图像
1400x1400x3
,我将这些图像翻过来,总共得到32幅图像进行验证

然后,我将这32幅图像缩小到
350x350x3
,以获得将与其他32幅图像交叉验证的输入图像

print(type(validateData))
print(validateData.shape)
print(type(validateData[0].shape))
print(validateData[0].shape)
返回

<class 'numpy.ndarray'>
(32,)
<class 'tuple'>
(1400, 1400, 3)
作为
.fit
函数的前两个参数,我应该输入什么

事实上,我得到了这个错误:

ValueError: Error when checking input: expected input_1 to have 4 dimensions, but got array with shape (32, 1)
ValueError: Error when checking model input: the list of Numpy arrays that you are passing to your model is not the size the model expected. Expected to see 1 array(s), but instead got the following list of 32 arrays: [array([[[0.6774938 , 0.64219969, 0.60690557],
        [0.67257049, 0.63743775, 0.60206295],
        [0.67203473, 0.6418085 , 0.60398018],
        ...,
        [0.55292714, 0.5253832 , 0.46217287],
  ...
如果你想调查的话,这是我的建议

对于应该输入的数据的格式不是很明确:

fit
fit(x=None, y=None, batch_size=None, epochs=1, verbose=1, callbacks=None, validation_split=0.0, validation_data=None, shuffle=True, class_weight=None, sample_weight=None, initial_epoch=0, steps_per_epoch=None, validation_steps=None)
Trains the model for a given number of epochs (iterations on a dataset).

Arguments

x: Numpy array of training data (if the model has a single input), or list of Numpy arrays (if the model has multiple inputs). If input layers in the model are named, you can also pass a dictionary mapping input names to Numpy arrays.  x can be None (default) if feeding from framework-native tensors (e.g. TensorFlow data tensors).
y: Numpy array of target (label) data (if the model has a single output), or list of Numpy arrays (if the model has multiple outputs). If output layers in the model are named, you can also pass a dictionary mapping output names to Numpy arrays.  y can be None (default) if feeding from framework-native tensors (e.g. TensorFlow data tensors).

下面是我尝试使用的完整代码。这次,我将参数更改为np_数组的python列表(每个图像都是3D np_数组)。我现在得到这个错误:

ValueError: Error when checking input: expected input_1 to have 4 dimensions, but got array with shape (32, 1)
ValueError: Error when checking model input: the list of Numpy arrays that you are passing to your model is not the size the model expected. Expected to see 1 array(s), but instead got the following list of 32 arrays: [array([[[0.6774938 , 0.64219969, 0.60690557],
        [0.67257049, 0.63743775, 0.60206295],
        [0.67203473, 0.6418085 , 0.60398018],
        ...,
        [0.55292714, 0.5253832 , 0.46217287],
  ...
很难知道我离得近还是远

fit(x=None, y=None, batch_size=None, epochs=1, verbose=1, callbacks=None, validation_split=0.0, validation_data=None, shuffle=True, class_weight=None, sample_weight=None, initial_epoch=0, steps_per_epoch=None, validation_steps=None)
在拟合函数中,x是您的训练数据。也许它更适合称为X_火车或类似的东西,而不是火车数据。在这种情况下,如果您有32个形状(350350,3)的训练图像,那么它们应该堆叠在一个四维(32350350,3)阵列中。如果你有一个像你看起来一样的对象的图像数组,你可以使用下面的代码重塑

X_train = np.array([x for x in trainingData])

fit函数中的y是您希望网络为相应输入输出的值,通常是一个标签,在本例中是较大的图像。你称之为validateData,但更常见的是称之为更接近y_train的东西。验证数据是在训练期间不使用的数据,但仅在每个历元后的模型评估期间使用。所以,像X_火车一样塑造y_火车。y_序列的预期形状应为(32140014001403)。

应堆叠在一个四维(323503503)阵列中。如果你有一组图像
:这正是我迷路的地方。我不明白我应该使用什么python数据类型作为输入(np_数组,或每个图像列表作为np_数组,或每个图像列表作为数组,或图像数组作为np_数组,或…等等)。它应该是一个形状的单个四维numpy数组(图像的nr_、图像的高度、图像的宽度、颜色的通道)。您似乎有一个包含32个对象的numpy数组。如果重塑命令不起作用,我已经在中编辑了另一段代码(您尝试过吗?)。我还意识到代码示例中有一些拼写错误,对此表示抱歉。现在应该修好了。不工作。你介意我们不要在评论部分发垃圾邮件吗?:)为了澄清,我想让社区知道sds解决了我的问题。我的numpy数组是用两个不同大小的图像创建的,然后,我将它分离,以分离这两类图像。但是,由于数组的创建方式,分离会留下一个包含numpy数组的
numpy数组的工件,而不是一个
numpy数组
。拆分后应用的
X\u train=np.数组([X代表trainingData中的X])
代码行已计算出来!他还解决了我关于输入格式的问题:一个大小为
(num_imgs x W x H x D)
的numpy数组。