Created
August 21, 2019 16:37
-
-
Save karolzak/970b3fbf00073f22fa65dec2ee5fe494 to your computer and use it in GitHub Desktop.
Reset keras and TF
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from keras.backend.tensorflow_backend import set_session | |
| from keras.backend.tensorflow_backend import clear_session | |
| from keras.backend.tensorflow_backend import get_session | |
| import tensorflow | |
| # Reset Keras Session | |
| def reset_keras(): | |
| sess = get_session() | |
| clear_session() | |
| sess.close() | |
| sess = get_session() | |
| try: | |
| del classifier # this is from global space - change this as you need | |
| except: | |
| pass | |
| print(gc.collect()) # if it's done something you should see a number being outputted | |
| # use the same config as you used to create the session | |
| config = tensorflow.ConfigProto() | |
| config.gpu_options.per_process_gpu_memory_fraction = 1 | |
| config.gpu_options.visible_device_list = "0" | |
| set_session(tensorflow.Session(config=config)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment