[英]Conitional output in keras LSTM
Maybe it is a dummy question but I'd like to know whether I can have my output vector to meet specific requirements. 也许这是一个虚拟的问题,但我想知道是否可以让我的输出向量满足特定要求。
I have multiple outputs (that are not binary) and I want their sum to be 1. I want my model to do some kind of evaluation in order for my output vector to meet this requirement. 我有多个输出(非二进制),并且我希望它们的总和为1。我希望我的模型进行某种评估,以便我的输出向量满足此要求。
You can either: 您可以:
softmax
activation at the end of your model, or softmax
激活,或 Softmax: Softmax:
Just add Activation('softmax')
at the end of the model. 只需在模型末尾添加
Activation('softmax')
。
This will perform some log operations though, and may be adding some extra conditions you do not want. 但是,这将执行一些日志操作,并且可能会添加一些您不希望的额外条件。
Custom normalizing: 自定义规范化:
Simply add this layer: 只需添加以下层:
import keras.backend as K
Lambda(lambda x: x / K.sum(x), output_shape=optional_with_tensorflow)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.