from keras.models import Model
model = load_model()
layer = model.layers[-1].output
layer = Dense(100)(layer)
layer = BatchNormalization()(layer)
layer = Actiation('relu')(layer)
layer = Dense(1, name='new_out')(layer)
model = Model(inputs=model.inputs, outputs=[layer])
model.compile(...)
model.fit(...)
def get_model(X):
model = Sequential() model.add(LSTM(12, batch_input_shape=(1, X.shape[1], X.shape[2]), return_sequences=True, name='layer-1')) model.add(LeakyReLU(alpha=.001)) model.add(LSTM(8, return_sequences=True, name='layer-2')) model.add(LeakyReLU(alpha=.001)) model.add(Dense(1, name='output-layer')) model.compile(loss='mse', optimizer='adam', metrics=['mse', 'mae', 'mape'])
return model
train_X, train_y = load_data() # Your year-basis dataset.
model = get_model(train_X)
model.fit(train_X, train_y, epochs=100, batch_size=1, validation_data=(test_X, test_y), verbose=2, shuffle=False)
model.save('model-5.h5')
train_X, train_y = load_data() # Your daily-basis dataset.
model_daily = get_model(train_X)
model_daily.set_weights(model.get_weights())
# Or alternatively:
# model.load_weights('model-5.h5')
model = Sequential()model.add(LSTM(12, input_dim=(None, None, train_X.shape[2]), return_sequences=True, name='layer-1'))
...