Sets the learning phase to a fixed value. Arguments: value: Learning phase value, either 0 or 1 (integers). Raises: ValueError: if `value` is neither `0` nor `1`.
(value)
| 333 | |
| 334 | @keras_export('keras.backend.set_learning_phase') |
| 335 | def set_learning_phase(value): |
| 336 | """Sets the learning phase to a fixed value. |
| 337 | |
| 338 | Arguments: |
| 339 | value: Learning phase value, either 0 or 1 (integers). |
| 340 | |
| 341 | Raises: |
| 342 | ValueError: if `value` is neither `0` nor `1`. |
| 343 | """ |
| 344 | global _GRAPH_LEARNING_PHASES # pylint: disable=global-variable-not-assigned |
| 345 | if value not in {0, 1}: |
| 346 | raise ValueError('Expected learning phase to be 0 or 1.') |
| 347 | with ops.init_scope(): |
| 348 | if context.executing_eagerly(): |
| 349 | # In an eager context, the learning phase values applies to both the eager |
| 350 | # context and the internal Keras graph. |
| 351 | _GRAPH_LEARNING_PHASES[_DUMMY_EAGER_GRAPH] = value |
| 352 | _GRAPH_LEARNING_PHASES[get_graph()] = value |
| 353 | |
| 354 | |
| 355 | @keras_export('keras.backend.learning_phase_scope') |
no test coverage detected