我将结合这两个模型并运行机器学习。
从图上看,它大致类似于以下内容:将这两个模型合并到FC中是成功的。
在这些值中,LSTM层侧节省了重量。
我的目标是在将模型组合成预先保存的权重值之前,将LSTM模型端的权重初始化。 如何将LSTM模型侧的权重初始化为保存的权重值并与FC层组合?
第一个代码没有错误,第二个代码经过修改以仅初始化LSTM模型一侧的权重。
inputA = Input(shape=(7,1))
inputB = Input(shape=(1,))
#Part 1 : LSTM
x = LSTM(20, activation="linear")(inputA)
x = Dense(10, activation="linear")(x)
x = Dense(1, activation="linear")(x)
#Part 2 : FC
y = Dense(10, activation="relu")(inputB)
y = Dense(1)(y)
#Part 3 : Concatenate
combined = concatenate([x, y])
z = Dense(2, activation="linear")(combined)
z = Dense(10, activation="linear")(z)
z = Dense(1, activation="linear")(z)
model = Model(inputs=[inputA,inputB] ,outputs=z)
model.compile(loss='mean_squared_error',optimizer='adam')
model.summary()
#Part 1 : LSTM, I want to update the weight of this model.
LSTM_model = Sequential()
LSTM_model.add(LSTM(10,input_shape=(7,1),inner_activation="linear"))
LSTM_model.add(Dense(10))
LSTM_model.add(Dense(1))
LSTM_model.load_weights(weight)
#Part 2 : FC
y = Dense(10, activation="relu")(inputB)
y = Dense(1)(y)
#Part 3 : Concatenate
combined = concatenate([LSTM_model, y])
z = Dense(2, activation="linear")(combined)
z = Dense(10, activation="linear")(z)
z = Dense(1, activation="linear")(z)
model = Model(inputs=[inputA,inputB] ,outputs=z)
model.compile(loss='mean_squared_error',optimizer='adam')
model.summary()