Using "Split" like functionality in Keras Functional Model with Tensorflow

585 views
Skip to first unread message

Rajaditya Mukherjee

unread,
Jul 5, 2017, 2:37:41 PM7/5/17
to Keras-users

I am using Keras with tensorflow backend. I am using functional layers in Keras. What I want to achieve is that I have the following architecture at some layer.

Tensor of (20,200)----> LSTM----> Split into two Tensors of size (20,100) each


Then use those two tensors as two branches of a further network. (We can think of this as being the opposite of a Merge operation)


I am given to understand that the only way to achieve this is currently using the Lambda layer since there is no "Split" functionality in Keras.

However looking into the documentation for Lambda function, it seems the output_shape functionality is only relevant iff we are using Keras.


Can anyone offer any advice on how to achieve this ? This is the rough pseudo-code of what I want to achieve.


#Other code before this 
lstm_1st_layer = LSTM(nos_hidden_neurons, return_sequences=True)(lstm_0th_layer)
#this layer outputs a tensor of size(20,200)
#Split it into two tensors of size (20,100) each (call them left and right)
left_lstm = LSTM(200, return_sequences=True)(left)
right_lstm = LSTM(200, return_sequences=True)(right)
#Other code after this --- just to clarify left_lstm and right_lstm should take inputs of tensors (20,100) and output tensors of (20,100) each as compared to the previous lstm layer
which inputs and outputs tensors of (20,200) each. 
Reply all
Reply to author
Forward
0 new messages