我试图将尺寸为(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)
而且,类似地:
print(type(trainingData)) # <class 'numpy.ndarray'>
print(trainingData.shape) # (32,)
print(type(trainingData[0].shape)) # <class 'tuple'>
print(trainingData[0].shape) # (350, 350, 3)
所以当我执行以下操作时:
model.fit(trainingData,
validateData,
epochs=5,
verbose=2,
batch_size=4) # 32 images-> 8 batches of 4
我应该将.fit
函数的前两个参数设置为什么?
目前情况是,我遇到了以下错误:
ValueError: Error when checking input: expected input_1 to have 4 dimensions, but got array with shape (32, 1)
这是我完整代码,如果您想深入了解,请查看。 Keras API对应输入数据格式并不十分明确。
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).
这里是我尝试使用的另一种实现的完整代码(链接)。这次,我将参数更改为Python列表np_array(每个图像都是3D np_array)。现在我遇到了这个错误:
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],
...
很难知道我是更接近还是更遥远。