ValueError:conv2d_6层的输入0与该层不兼容:预期ndim = 4,找到的ndim = 1。收到的完整形状:[无]

时间:2020-05-31 13:25:01

标签: python-3.x deep-learning conv-neural-network tensorflow2.0 cnn

我在这里检查了许多类似的答复,以了解其他一些代码,但是它们不能以某种方式帮助我。如果我在这里询问代码问题可能对我有帮助。如果有人可以帮助我,我会感到很高兴。

import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Activation, Flatten, Conv2D, MaxPooling2D, Dropout
import numpy as np

X = np.load("feature.npy") #loading X
y = np.load("feature.npy") #loading y

X = X/255

model = Sequential()

model.add(Conv2D(256, (3, 3), input_shape=X.shape[1:]))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))

model.add(Conv2D(256, (3, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))

model.add(Flatten())  # this converts our 3D feature maps to 1D feature vectors

model.add(Dense(64))

model.add(Dense(1))
model.add(Activation('sigmoid'))

model.compile(loss='binary_crossentropy',
              optimizer='adam',
              metrics=['accuracy'])

model.fit(X, y, batch_size=32, epochs=3, validation_split=0.3)

它说它需要4维,所以我把它做成4d。

model.add(Conv2D(256, (3, 3), input_shape=(64,64,1))) 我只添加了3个,因为tensorflow本身添加了另一个。但它说

ValueError: Error when checking input: expected conv2d_10_input to have 4 dimensions, but got array with shape (24946, 1)

0 个答案:

没有答案