anon
anon

Reputation:

N timeseries feed to one layer with N lstm cells, how to concatenate lstm horizontally as a layer?

I am trying to impliment https://dl.acm.org/doi/pdf/10.1145/3269206.3271794 .

It has a network structure like

timeseries1 -> lstm1
timeseries2 -> lstm2
....
timeseriesN -> lstmN

[lstm1, lstm2, ... , lstmN] ->  CNN -> FC


enter image description here

I saw a lot of examples of stacking lstm layers , no one show me how to concatenate multiple lstm cells horizontally .

Now , I have a dataframe with 4 timeseries columns : ['t1', 't2', 't3', 't4'] , how do I build a model with four horizontally concated lstm cell ?

Upvotes: 1

Views: 85

Answers (1)

Andrey
Andrey

Reputation: 6367

Try this:

import tensorflow as tf
input1 = tf.keras.layers.Input((10, 10))
input2 = tf.keras.layers.Input((10, 10))
x1 = tf.keras.layers.LSTM(128)(input1)
x2 = tf.keras.layers.LSTM(128)(input2)
x = tf.concat([x1, x2], -1)
model = tf.keras.Model(inputs=[input1, input2], outputs=x)
trainx1 = tf.random.uniform([10, 10, 10])
trainx2 = tf.random.uniform([10, 10, 10])
pred = model((trainx1, trainx2))

Upvotes: 2

Related Questions