问题描述
我想将多层多尺度LSTM实现为Keras层.
它在此处发布,并在tensorflow 此处.
我的理解是,有一种方法可以在Keras中将这样的张量流对象包装为一层.我不确定这有多复杂,但我认为这是可行的.你能帮我怎么做吗?
I would like to implement Hierarchical Multiscale LSTM as a Keras layer.
It was published here and implemented in tensorflow here.
My understanding is that there's a way to wrap such a tensorflow object in Keras as a layer. I'm not sure how complicated it is but I think it's feasible. Can you help me how to do it?
推荐答案
通常由实现自定义图层.具体来说,您应该继承 keras .engine.topology.layer 并为以下方法提供自定义实现(并将TensorFlow代码放入其中):
This is usually done by implementing a custom Layer. To be more specific, you should inherit from keras.engine.topology.layer and provide a custom implementation for the following methods (and place the TensorFlow code within them):
由于您尝试实现循环层,因此直接从 keras.legacy.layers.recurrent .在这种情况下,您可能不需要重新定义compute_output_shape(input_shape)
.如果您的图层需要其他参数,则可以将其传递到自定义图层的__init__
方法.
Since you're trying to implement a recurrent layer, it would also be convenient to inherit directly from keras.legacy.layers.recurrent. In this case, you probably do not need to redefine compute_output_shape(input_shape)
. If your layer needs additional arguments, you can pass them to the __init__
method of your custom layer.
这篇关于如何将张量流对象包装为Keras层?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!