如何为 keras 提供恒定输入 [英] How to give a constant input to keras

查看:39
本文介绍了如何为 keras 提供恒定输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网络有两个时间序列输入.其中一个输入有一个固定向量,每个时间步都重复.有没有一种优雅的方法将这个固定向量加载到模型中并使用它进行计算?

My network has two time-series inputs. One of the input has a fixed vector repeating for every time step. Is there an elegant way to load this fixed vector into the model just once and use it for computation?

推荐答案

您可以使用 jdehesa 描述的张量参数创建静态输入,但是张量应该是 Keras(而不是 tensorflow)变量.您可以按如下方式创建:

You can create a static input using the tensor argument as described by jdehesa, however the tensor should be a Keras (not tensorflow) variable. You can create this as follows:

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)

这篇关于如何为 keras 提供恒定输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆