![](/img/trans.png)
[英]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: Input 0 of layer sequential_1 is incompatible with the layer: : expected min_ndim=4, found ndim=3. Full shape received: [None, 256, 256]
在我將圖像轉換為灰度之前,一切都很好。 所以 rgb 的形狀是(256, 256, 3)
但灰度有(256, 256)
。 當我喂它時,我得到了那個錯誤。
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'])
您必須在網絡中提供形狀為 256x256x1 的圖像。
要將您的初始x_train
轉換為您的新X_train
:
X_train=np.reshape(x_train,(x_train.shape[0], x_train.shape[1],x_train.shape[2],1))
最后將您的 input_shape 從input_shape=(256,256)
更改為input_shape=(256,256,1)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.