编译keras模型后"None"是什么意思?
What does a "None" mean after compilation of keras model?
我正在尝试使用 keras 图层实现二进制文本分类模型。编译模型后,在总结中,我在底端得到 None 我不完全明白这是什么意思?
这是我正在使用的代码。
max_words = 10000
max_len = 500
tok = Tokenizer(num_words=max_words)
tok.fit_on_texts(X_train)
sequences = tok.texts_to_sequences(X_train)
sequences_matrix = sequence.pad_sequences(sequences,maxlen=max_len)
model = Sequential()
model.add(Embedding(max_words, 50, input_length=max_len))
model.add(LSTM(64))
model.add(Dense(256,name='FC1',activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(1, activation='sigmoid'))
model.compile(optimizer='adam', loss='binary_crossentropy', metrics=
['acc'])
print(model.summary())
这是模型摘要,在底部显示 None。
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
embedding_1 (Embedding) (None, 500, 50) 500000
_________________________________________________________________
lstm_1 (LSTM) (None, 64) 29440
_________________________________________________________________
FC1 (Dense) (None, 256) 16640
_________________________________________________________________
dropout_1 (Dropout) (None, 256) 0
_________________________________________________________________
dense_1 (Dense) (None, 1) 257
=================================================================
Total params: 546,337
Trainable params: 546,337
Non-trainable params: 0
_________________________________________________________________
None
model.summary()
return 什么都没有 (None
),而您正在打印它的 return 值。 model.summary()
已经在内部进行了打印,无需与手动打印混淆,所以只需执行:
model.summary()
我正在尝试使用 keras 图层实现二进制文本分类模型。编译模型后,在总结中,我在底端得到 None 我不完全明白这是什么意思?
这是我正在使用的代码。
max_words = 10000
max_len = 500
tok = Tokenizer(num_words=max_words)
tok.fit_on_texts(X_train)
sequences = tok.texts_to_sequences(X_train)
sequences_matrix = sequence.pad_sequences(sequences,maxlen=max_len)
model = Sequential()
model.add(Embedding(max_words, 50, input_length=max_len))
model.add(LSTM(64))
model.add(Dense(256,name='FC1',activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(1, activation='sigmoid'))
model.compile(optimizer='adam', loss='binary_crossentropy', metrics=
['acc'])
print(model.summary())
这是模型摘要,在底部显示 None。
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
embedding_1 (Embedding) (None, 500, 50) 500000
_________________________________________________________________
lstm_1 (LSTM) (None, 64) 29440
_________________________________________________________________
FC1 (Dense) (None, 256) 16640
_________________________________________________________________
dropout_1 (Dropout) (None, 256) 0
_________________________________________________________________
dense_1 (Dense) (None, 1) 257
=================================================================
Total params: 546,337
Trainable params: 546,337
Non-trainable params: 0
_________________________________________________________________
None
model.summary()
return 什么都没有 (None
),而您正在打印它的 return 值。 model.summary()
已经在内部进行了打印,无需与手动打印混淆,所以只需执行:
model.summary()