How to K.clear_session() within GridSearchCV?

719 views Asked by At

I am using GridSearchCV from sklearn and get the error message:

Cannot interpret feed_dict key as Tensor: Tensor Tensor("masking_1_input:0", shape=(?, 300, 31), dtype=float32) is not an element of this graph.

which can be prevented through using K.clear_session() after each run. So far, I have not found any possibilities to include this function in GridSearchCV. Do you know how it could work?

I have tried to implement it as a callback with on_train_end(), but that would clear the session too early and produces another error message:

Update

I have found out that the error is connected to the callbacks TensorBoard and ModelCheckpoint. When i remove them the GridSearch works. With the other two callbacks Histories, ReduceLROnPlateau and EarlyStopping the GridSearch works without any problems. The similarity between those two callbacks is that both save a file on the computer. the code for the two callbacks is:

callback_tb = keras.callbacks.TensorBoard(log_dir="D:/logs/"name + '_' + str(count) + 'days', write_graph = True, write_grads = True, histogram_freq=5, write_images = True )
checkpointer = keras.callbacks.ModelCheckpoint(filepath='D:/tmp/'name+ '_' + str(count)+'.hdf5', verbose=1, save_best_only=True)
0

There are 0 answers