Yak*_*kku 8 python classification machine-learning neural-network keras
我的网络有两个时间序列输入.其中一个输入具有针对每个时间步重复的固定向量.是否有一种优雅的方法将这个固定的矢量加载到模型中一次并将其用于计算?
您可以使用jdehesa描述的tensor参数创建静态输入,但张量应该是Keras(而不是tensorflow)变量.您可以按如下方式创建:
from keras.layers import Input
from keras import backend as K
constants = [1,2,3]
k_constants = K.variable(constants)
fixed_input = Input(tensor=k_constants)
Run Code Online (Sandbox Code Playgroud)
编辑:显然下面的答案不起作用(无论如何现在)。有关相关答案,请参阅在 Keras 中创建恒定值。
查看源代码(我无法在文档中找到参考),看起来您可以只使用Input并向其传递一个常量 Theano/TensorFlow 张量。
from keras.layers import Input
import tensorflow as tf
fixed_input = Input(tensor=tf.constant([1, 2, 3, 4]))
Run Code Online (Sandbox Code Playgroud)
这将“包装”张量(实际上更像是用元数据“扩展”它),这样您就可以将它与任何 Keras 层一起使用。
| 归档时间: |
|
| 查看次数: |
9355 次 |
| 最近记录: |