在构建卷积神经网络时,遇到了这个错误
ValueError: Input 0 of layer conv2d is incompatible with the layer: expected ndim=4, found ndim=3.
这是说conv2d(卷积层)的输入和这一层不兼容,期望的维度是4,实际给的是3。
这一层的维度是, (样本个数,长度,宽度,灰度),我们在导入训练数据时,如果数据没有指定灰度,也要给一个默认值。也就是要默认增加一维。
x_train = np.expand_dims(x_train, -1)
x_test = np.expand_dims(x_test, -1)