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)
| 399 | |
| 400 | @tf_contextlib.contextmanager |
| 401 | def 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 | |
| 430 | def _current_graph(op_input_list): |
nothing calls this directly
no test coverage detected