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?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- batch_dot with variable batch size in Keras
- How to get the background from multiple images by
- Evil ctypes hack in python
Something to add: When you come to compile the model you need to give the constant input as an input otherwise the graph disconnects
when you train you can just feed in the data you have, you don't need the constant layer anymore.
I have found that no matter what you try it's usually easier to just use a custom layer and take advantage of the power of numpy:
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:
EDIT: Apparently the answer below does not work (nowadays anyway). See Creating constant value in Keras for a related answer.
Looking at the source (I haven't been able to find a reference in the docs), it looks like you can just use
Input
and pass it a constant Theano/TensorFlow tensor.This will "wrap" the tensor (actually more like "extend" it with metadata) so you can use it with any Keras layer.