【问题标题】:How to calculate the trainable param quantity to be 335872 in this LSTM sample code?如何在此 LSTM 示例代码中计算可训练参数数量为 335872?
【发布时间】:2019-03-04 03:31:45
【问题描述】:

我得到了这个示例代码,但不知道如何计算可训练参数为 335872? (显示在以下输出中)

如果有人可以帮助解决这个问题,我将不胜感激。谢谢!

--------------代码---------- ---------------

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

----------输出如下----------


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)]

【问题讨论】:

  • 你能说出latent_dimnum_encoder_tokens的值吗?

标签: python machine-learning keras lstm


【解决方案1】:

我假设您想知道如何训练模型以便可以计算 weight matricesbiases 等。

您的代码的问题在于您只定义了模型的架构。你还没有真正编译它。最后这样做:

encoder_model.compile(loss='binary_crossentropy', optimizer='adam', metrics='binary_accuracy')

在上面的代码行中,lossoptimizermetrics 取决于您的问题类型。

【讨论】:

  • 这根本没有回答问题。
  • @MatiasValdenegro 你能编辑一下这个问题吗?我无法弄清楚“可训练参数为 335872”的含义,所以我假设作者想了解训练参数。
  • 感谢您的回复。我已经修改了问题并使其更清楚。
  • 我的问题是,为什么可训练参数的数量是 335,872?你可以看到代码的输出包括:Trainable params: 335,872
猜你喜欢
  • 2018-11-29
  • 1970-01-01
  • 2016-11-04
  • 1970-01-01
  • 2014-07-22
  • 1970-01-01
  • 2018-10-16
  • 2019-01-21
  • 1970-01-01
相关资源
最近更新 更多