Destroys the current TF graph and creates a new one. Useful to avoid clutter from old models / layers.
()
| 218 | |
| 219 | @keras_export('keras.backend.clear_session') |
| 220 | def clear_session(): |
| 221 | """Destroys the current TF graph and creates a new one. |
| 222 | |
| 223 | Useful to avoid clutter from old models / layers. |
| 224 | """ |
| 225 | global _SESSION |
| 226 | global _GRAPH_LEARNING_PHASES # pylint: disable=global-variable-not-assigned |
| 227 | global _GRAPH_VARIABLES # pylint: disable=global-variable-not-assigned |
| 228 | global _GRAPH_TF_OPTIMIZERS # pylint: disable=global-variable-not-assigned |
| 229 | global _GRAPH |
| 230 | global _FREEZABLE_VARS |
| 231 | _GRAPH = None |
| 232 | ops.reset_default_graph() |
| 233 | reset_uids() |
| 234 | _SESSION.session = None |
| 235 | graph = get_graph() |
| 236 | with graph.as_default(): |
| 237 | with name_scope(''): |
| 238 | phase = array_ops.placeholder_with_default( |
| 239 | False, shape=(), name='keras_learning_phase') |
| 240 | _GRAPH_LEARNING_PHASES = {} |
| 241 | _GRAPH_LEARNING_PHASES[graph] = phase |
| 242 | _GRAPH_VARIABLES.pop(graph, None) |
| 243 | _GRAPH_TF_OPTIMIZERS.pop(graph, None) |
| 244 | _FREEZABLE_VARS.pop(graph, None) |
| 245 | |
| 246 | |
| 247 | @keras_export('keras.backend.manual_variable_initialization') |
nothing calls this directly
no test coverage detected