简体   繁体   English

如何在此LSTM示例代码中将可训练参数数量计算为335872?

[英]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 matricesbiases等。

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. 在上面的代码行中,您可以根据问题的类型来选择lossoptimizermetrics

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在串联的keras模型中设置可训练的参数 - how to set trainable param in concatenated keras models 如果我们将一个可训练参数与一个不可训练的参数组合在一起,那么原始的可训练参数是否可训练? - If we combine one trainable parameters with a non-trainable parameter, is the original trainable param trainable? Keras:了解可训练的LSTM参数的数量 - Keras: Understanding the number of trainable LSTM parameters 如何从子产品数量计算集合产品数量? - How to calculate set product quantity from subproduct quantity? 如何在 Python 中计算导出量的误差 - how to calculate errors in a derived quantity in Python LSTM的样本预测不足 - Out of sample predictions with LSTM 参数param ['pagetoken']是示例Google报告代码中的语法错误吗? - Is param['pagetoken'] a syntax error in sample Google Reports Code? 如何使用Keras在LSTM中做出样本预测? - How to make out of sample prediction in LSTM using Keras? 如何计算非熊猫样本总体的协方差? - How to calculate Covariance for a population not sample in pandas? 如何使用 Pandas 计算两个日期之间的工作日数 - How to calculate the quantity of business days between two dates using Pandas
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM