I have a file train.py to train neural net model via tensorflow.keras, and the best model will be saved as best_train.h5 according to the train_loss. The training time is about 7 days.
I have another file test.py to test the model saved during the running of train.py. In the test.py model, I load the best_train.h5 every hour to see the test performance. The codes are as follows:
for i in range(7*24):
time.sleep(1*60*60)
model = tf.keras.models.load_model('best_train.h5')
model.predict(test_data)
I found that every time I load best-train.h5, the occupied GPU memory will be increased. And after about 200 iterations, the GPU memory will be run out. OOM Errors will occur.
I know tf.clear_session() can free the GPU memory. But this command will clear all the sessions and graph. I is not what I wanted. Because in test.py there are still other models I hold.