MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / eager_learning_phase_scope

Function eager_learning_phase_scope

tensorflow/python/keras/backend.py:401–427  ·  view source on GitHub ↗

Internal scope that sets the learning phase in eager / tf.function only. Arguments: value: Learning phase value, either 0 or 1 (integers). Yields: None. Raises: ValueError: if `value` is neither `0` nor `1`.

(value)

Source from the content-addressed store, hash-verified

399
400@tf_contextlib.contextmanager
401def eager_learning_phase_scope(value):
402 """Internal scope that sets the learning phase in eager / tf.function only.
403
404 Arguments:
405 value: Learning phase value, either 0 or 1 (integers).
406
407 Yields:
408 None.
409
410 Raises:
411 ValueError: if `value` is neither `0` nor `1`.
412 """
413 global _GRAPH_LEARNING_PHASES # pylint: disable=global-variable-not-assigned
414 assert value in {0, 1}
415 assert ops.executing_eagerly_outside_functions()
416 global_learning_phase_was_set = global_learning_phase_is_set()
417 if global_learning_phase_was_set:
418 previous_value = learning_phase()
419 try:
420 _GRAPH_LEARNING_PHASES[_DUMMY_EAGER_GRAPH] = value
421 yield
422 finally:
423 # Restore learning phase to initial value or unset.
424 if global_learning_phase_was_set:
425 _GRAPH_LEARNING_PHASES[_DUMMY_EAGER_GRAPH] = previous_value
426 else:
427 del _GRAPH_LEARNING_PHASES[_DUMMY_EAGER_GRAPH]
428
429
430def _current_graph(op_input_list):

Callers

nothing calls this directly

Calls 2

learning_phaseFunction · 0.85

Tested by

no test coverage detected