I have the following model, I want to build the same sequentional network and finally concate the outputs of the two network. Here is my model:
import numpy as np
import tensorflow as tf
from keras.models import Sequential, Model,load_model
from keras.layers import Dense, Dropout, Activation, Flatten, LSTM, Embedding, Input, concatenate, Lambda
from keras.utils import np_utils
from sklearn.metrics import mean_squared_error
#from keras.utils.vis_utils import plot_model
import keras
from keras_self_attention import SeqSelfAttention, SeqWeightedAttention
X1 = np.random.normal(size=(100,1,2))
X2 = np.random.normal(size=(100,1,2))
X3 = np.random.normal(size=(100,1,2))
Y = np.random.normal(size=(100,18))
model = Sequential()
model.add(LSTM(units=50, return_sequences=True, input_shape=(X1.shape[1],X1.shape[2])))
model.add(LSTM(units=50))
model.add(Dropout(0.2))
model.add(Dense(units=18))
model.compile(optimizer = 'adam', loss = 'mean_squared_error',metrics = ['MAE'])
model.fit(X1, Y, epochs =1, batch_size = 100)
Here is the model. I want to add the red part to the model. Can anybody help me? Thanks
it is better to use the Functionnal API to handle multiple inputs :
def sub_model(input):
mod1=LSTM(50,return_sequences=True)(input)
mod1=LSTM(50,dropout=0.2)(mod1)
return Dense(18)(mod1)
inp1=Input(shape=(1,2))
inp2=Input(shape=(1,2))
mod1=sub_model(inp1)
mod2=sub_model(inp2)
concat=Concatenate()([mod1,mod2])
output=Dense(18)(concat)
model=models.Model([inp1,inp2],output)
which gives you :
To train it, you can use model.fit()
like :
model.fit([X1,X2],y)