在使用TensorFlow2.0中自带Keras进行训练的时候,输入的训练集为RGB三通道图像,然而配置好网络后使用 model.fit(x, ...)进行训练时却始终报如下错误
expected input_conv to have 4 dimensions, but got array...
具体意思是输入的参数x需要输入4个参数,而训练输入却只有3个维度,我的图片维度为(192, 192, 3)。
解决过程
首先先去了解了一下fit函数的x究竟是什么,TensorFlow官网给出的解释如下
x
: Input data. It could be:
- A Numpy array (or array-like), or a list of arrays (in case the model has multiple inputs).
- A TensorFlow tensor, or a list of tensors (in case the model has multiple inputs).
- A dict mapping input names to the corresponding array/tensors, if the model has named inputs.
- A
tf.data
dataset. Should return a tuple of either(inputs, targets)
or(inputs, targets, sample_weights)
.- A genera