Keras Lambda层,用于在LSTM模型中计算温度

时间:2019-01-20 09:58:23

标签: lambda keras lstm layer temperature

我对Keras Lambda图层有问题。我正在使用Keras功能API创建模型。另外,我想将模型保存到h5文件中。

它与以下代码完美配合:

shared_layer = LSTM(size, return_sequences=True, dropout=self.params['dropout'][0], recurrent_dropout=self.params['dropout'][1])(shared_layer)
output = shared_layer
output = TimeDistributed(Dense(n_class_labels, activation='softmax'), name=modelName+'_softmax')(output)

但是,如果添加以下行,则在保存模型时会出现错误。尽管在训练时它不会引发错误:

logits_temperature = Lambda(lambda x : x / self.params['temperature'])(output)
output = TimeDistributed(Dense(n_class_labels, activation='softmax'), name=modelName+'_softmax')(logits_temperature)

这是保存时出现的错误:

TypeError: cannot serialize '_io.TextIOWrapper' object

0 个答案:

没有答案