Tensorflow Keras:ValueError:layer sequential的输入0与layer:expected轴不兼容
我试图使用Keras构建一个神经网络,但得到了错误:Tensorflow Keras:ValueError:layer sequential的输入0与layer:expected轴不兼容,tensorflow,keras,Tensorflow,Keras,我试图使用Keras构建一个神经网络,但得到了错误: ValueError: Input 0 of layer sequential is incompatible with the layer: expected axis -1 of input shape to have value 25168 but received input with shape (None, 34783) 我将模型定义为: model = Sequential() model.add(Dense(1024, in
ValueError: Input 0 of layer sequential is incompatible with the layer: expected axis -1 of input shape to have value 25168 but received input with shape (None, 34783)
我将模型定义为:
model = Sequential()
model.add(Dense(1024, input_dim = len(X), activation = 'relu'))
model.add(Dense(6, activation='softmax'))
在这种情况下,X
是使用scikit learn的CountVectorizer()
(经过培训后)的结果,如下所示:
X = count_vectorizer.transform(X).todense()
有什么方法可以解决这个问题吗?环顾四周,我发现我可能需要重塑数据,但是我不知道如何和在哪里。您使用的是作为
输入的维度:len(X)
(与X.shape[0]
)这是错误的
Keras希望输入特征的尺寸数量,在2D输入的情况下,这些特征的尺寸是X.shape[-1]