[英]How to calculate the trainable param quantity to be 335872 in this LSTM sample code?
I got this sample code but can't figure out how to calculate the trainable parameters to be 335872? 我得到了此示例代码,但无法弄清楚如何将可训练参数计算为335872? (showed in the following output) (在以下输出中显示)
I would appreciate it if anyone could help on this question. 如果有人可以在这个问题上提供帮助,我将不胜感激。 Thanks! 谢谢!
-------------------------code------------------------------------ - - - - - - - - - - - - -码 - - - - - - - - - - - - ------------
input_shape = (None, num_encoder_tokens)
# Define an input sequence and process it.
encoder_inputs = Input(shape=input_shape)
encoder = LSTM(latent_dim, return_state=True)
encoder_outputs, state_h, state_c = encoder(encoder_inputs)
# We discard `encoder_outputs` and only keep the states.
encoder_states = [state_h, state_c]
encoder_model = Model(encoder_inputs, encoder_states)
encoder_model.summary(line_length=100)
encoder_model.output_shape
---------------------output is as follows---------------------- ---------------------输出如下----------------------
Layer (type) Output Shape Param #
=================================================================================
input_2 (InputLayer) (None, None, 71) 0
_________________________________________________________________________________
lstm_5 (LSTM) [(None, 256), (None, 256), (None, 256)] 335872
=================================================================================
Total params: 335,872
Trainable params: 335,872
Non-trainable params: 0
_________________________________________________________________________________
[(None, 256), (None, 256)]
I am assuming that you want to know how to train the model so that weight matrices
, biases
, etc. can be calculated. 我假设您想知道如何训练模型,以便可以计算weight matrices
, biases
等。
The problem with your code is that you have only defined the architecture of your model. 代码的问题在于,您仅定义了模型的体系结构。 You haven't really compiled it. 您尚未真正编译它。 Do this in the end: 最后执行此操作:
encoder_model.compile(loss='binary_crossentropy', optimizer='adam', metrics='binary_accuracy')
In the above line of code, loss
, optimizer
and metrics
is up to you to choose depending on the type of your problem. 在上面的代码行中,您可以根据问题的类型来选择loss
, optimizer
和metrics
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.