简体   繁体   English

ValueError:layersequential_1 的输入 0 与 layer 不兼容::预期 min_ndim=4,发现 ndim=3。 收到的完整形状:[无、256、256]

[英]ValueError: Input 0 of layer sequential_1 is incompatible with the layer: : expected min_ndim=4, found ndim=3. Full shape received: [None, 256, 256]

Everything is okay until I convert my image to grayscale.在我将图像转换为灰度之前,一切都很好。 So the rgb's shape is (256, 256, 3) but grayscale has (256, 256) .所以 rgb 的形状是(256, 256, 3)但灰度有(256, 256) When I feed it, I get that error.当我喂它时,我得到了那个错误。

network = Sequential()

network.add(Convolution2D(32, kernel_size=(3, 3),strides=1,activation='relu',input_shape=(256, 256)))
network.add(MaxPooling2D((2, 2)))

# network.add(Convolution2D(32, kernel_size=(3, 3), strides=1, activation='relu'))
# network.add(MaxPooling2D((2, 2)))


network.add(Convolution2D(64, kernel_size=(3, 3), strides=1, activation='relu'))
network.add(MaxPooling2D((2, 2)))

# network.add(Convolution2D(64, kernel_size=(3, 3), strides=1, activation='relu'))
# network.add(MaxPooling2D((2, 2)))


network.add(Convolution2D(128, kernel_size=(3, 3), strides=1, activation='relu'))
network.add(MaxPooling2D((2, 2)))

# network.add(Convolution2D(128, kernel_size=(3, 3), strides=1, activation='relu'))
# network.add(MaxPooling2D((2, 2)))


network.add(Flatten())
network.add(Dense(256, activation = 'relu'))
network.add(Dense(2, activation = 'softmax'))

checkpoint_path = os.path.join("/---------/grayscale", "weights.best.hdf5")
checkpoint = ModelCheckpoint(checkpoint_path, monitor='val_accuracy', verbose=1, save_best_only=True, mode='max')
es = EarlyStopping(monitor='val_loss', mode='min', verbose=1, patience=10)
callbacks_list = [checkpoint, es]

network.compile(optimizer = 'adam', loss = 'categorical_crossentropy', metrics = ['accuracy'])

You have to feed images of shape 256x256x1 in your network.您必须在网络中提供形状为 256x256x1 的图像。

To convert your initial x_train into your new X_train :要将您的初始x_train转换为您的新X_train

X_train=np.reshape(x_train,(x_train.shape[0], x_train.shape[1],x_train.shape[2],1))

and finally change your input_shape from input_shape=(256,256) to input_shape=(256,256,1)最后将您的 input_shape 从input_shape=(256,256)更改为input_shape=(256,256,1)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ValueError:层 sequential_3 的输入 0 与层不兼容::预期 min_ndim=4,发现 ndim=3。 已收到完整形状:(无、224、256) - ValueError: Input 0 of layer sequential_3 is incompatible with the layer: : expected min_ndim=4, found ndim=3. Full shape received: (None, 224, 256) ValueError:layersequential_32 的输入 0 与 layer 不兼容::预期 min_ndim=3,发现 ndim=2。 收到的完整形状:[无,256] - ValueError: Input 0 of layer sequential_32 is incompatible with the layer: : expected min_ndim=3, found ndim=2. Full shape received: [None, 256] ValueError: 层序列 9 的输入 0 与层不兼容:预期 min_ndim=4,发现 ndim=3。 收到的完整形状:[无,无,无] - ValueError: Input 0 of layer sequential_9 is incompatible with the layer: : expected min_ndim=4, found ndim=3. Full shape received: [None, None, None] ValueError:层顺序的输入 0 与层不兼容::预期 min_ndim=4,发现 ndim=3。 收到的完整形状:[None, 32, 32] - ValueError: Input 0 of layer sequential is incompatible with the layer: : expected min_ndim=4, found ndim=3. Full shape received: [None, 32, 32] ValueError: 层序贯_1 的输入 0 与层不兼容: : 预期 min_ndim=4,发现 ndim=2。 收到的完整形状:(32768, 1) - ValueError: Input 0 of layer sequential_1 is incompatible with the layer: : expected min_ndim=4, found ndim=2. Full shape received: (32768, 1) ValueError:顺序层的输入 0 与层不兼容::预计 min_ndim=4,发现 ndim=3。 收到完整形状:[8, 28, 28] - ValueError: Input 0 of layer sequential is incompatible with the layer: : expected min_ndim=4, found ndim=3. Full shape received: [8, 28, 28] Conv1D:ValueError:层序列_1 的输入 0 与层不兼容::预期 min_ndim=3,发现 ndim=2。 收到完整形状:(无,2) - Conv1D: ValueError: Input 0 of layer sequential_1 is incompatible with the layer: : expected min_ndim=3, found ndim=2. Full shape received: (None, 2) ValueError:layersequence_4 的输入 0 与 layer 不兼容::预期 min_ndim=4,发现 ndim=3。 收到的完整形状:(32、224、3) - ValueError: Input 0 of layer sequential_4 is incompatible with the layer: : expected min_ndim=4, found ndim=3. Full shape received: (32, 224, 3) 层序的输入 0 与层不兼容::预期 min_ndim=4,发现 ndim=2。 收到的完整形状:(无,1) - Input 0 of layer sequential is incompatible with the layer: : expected min_ndim=4, found ndim=2. Full shape received: (None, 1) ValueError:layersequential_5 的输入 0 与 layer 不兼容::预期 min_ndim=4,发现 ndim=2。 收到的完整形状:[无,953] - ValueError: Input 0 of layer sequential_5 is incompatible with the layer: : expected min_ndim=4, found ndim=2. Full shape received: [None, 953]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM