15👍
✅
from keras import backend as K
K.clear_session()
This will clear the current session (Graph) and so the stale model should be removed from GPU. If it didn’t work, you might need to ‘del model’ and reload it again.
19👍
For people who fail to make K.clear_session()
work, there is an alternative solution:
from numba import cuda
cuda.select_device(0)
cuda.close()
Tensorflow
is just allocating memory to the GPU, while CUDA is responsible for managing the GPU memory.
If CUDA somehow refuses to release the GPU memory after you have cleared all the graph with K.clear_session()
, then you can use the cuda
library to have a direct control on CUDA to clear GPU memory.
- Django render_to_string() ignores {% csrf_token %}
- Django Serialize Queryset to JSON to construct RESTful response with only field information and id
- Django forms.ChoiceField without validation of selected value
- Changes made to (static) CSS file not reflecting in Django development server
- How to use forms in django-cms?
- Can not use celery delay for saved form: object is not JSON serializable
- Django aggregation: sum then average
- Django bootstrap alerts not working as expected
- Django ForeignKey limit_choices_to a different ForeignKey id
Source:stackexchange.com