python - 如何在此 LSTM 示例代码中计算可训练参数数量为 335872?
问题描述
我得到了这个示例代码,但不知道如何计算可训练参数为 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)]
解决方案
我假设您想知道如何训练模型以便可以计算 、 等weight matrices
。biases
您的代码的问题在于您只定义了模型的体系结构。你还没有真正编译它。最后这样做:
encoder_model.compile(loss='binary_crossentropy', optimizer='adam', metrics='binary_accuracy')
在上面的代码行中loss
,optimizer
和metrics
由您根据问题的类型进行选择。
推荐阅读
- c# - 每次在c#中以编程方式单击按钮时如何添加组合框的新实例
- r - R中零点之间向量的总和
- java - 不使用 Spring Data QBE 调用 JPA Hibernate Converter
- c# - 关闭一个表单并打开另一个而不结束应用程序
- javascript - 如何测试使用 Teaspoon-mocha 和 Sinon 重新加载位置的功能
- view - Vtiger CRM - 创建扩展主布局的新自定义视图
- ssl - SSL 警报编号 48:未知 CA,即使使用 openssl 验证返回 OK
- paypal - 带有自定义派送详细信息的 PayPal 经典表单,而不是“卖家尚未提供任何派送详细信息”
- java - 如何使用杰克逊流 api 解析给定的 json?
- javascript - 分配架构时出现“架构路径值无效”错误