您不需要在第二个Dense层中提供input_shape,第一个也不提供,仅在第一层中,以下层的形状将被计算:
from tensorflow.keras.layers import Embedding,Dense
from tensorflow.keras.models import Sequential
# 286 features and 324827 rows (324827,286)
model = Sequential()
model.add(Embedding(286,64,input_shape=(286,)))
model.add(Dense(10,activation='relu'))
model.add(Dense(1,activation='softmax'))
model.compile(loss='mse',optimizer='adam')
model.summary()
返回:
Model: "sequential_2"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
embedding_2 (Embedding) (None,286,64) 18304
_________________________________________________________________
dense_2 (Dense) (None,10) 650
_________________________________________________________________
dense_3 (Dense) (None,1) 11
=================================================================
Total params: 18,965
Trainable params: 18,965
Non-trainable params: 0
_________________________________________________________________
我希望这就是您要寻找的
本文链接:https://www.f2er.com/2704158.html