I\'m running multiple nested loops to do hyper parameter grid search. Each nested loop runs through a list of hyper parameter values and inside the innermost loop, a Keras s
Using the tip given by indraforyou, I added the code to clear the TensorFlow session inside the function I pass to GridSearchCV, like this:
def create_model():
# cleanup
K.clear_session()
inputs = Input(shape=(4096,))
x = Dense(2048, activation='relu')(inputs)
p = Dense(2, activation='sigmoid')(x)
model = Model(input=inputs, outputs=p)
model.compile(optimizer='SGD',
loss='mse',
metrics=['accuracy'])
return model
And then I can invoke the grid search:
model = KerasClassifier(build_fn=create_model)
grid = GridSearchCV(estimator=model, param_grid=param_grid, n_jobs=1)
It should work.
Cheers!