Returns the session object for the current thread.
(op_input_list=())
| 433 | |
| 434 | |
| 435 | def _get_session(op_input_list=()): |
| 436 | """Returns the session object for the current thread.""" |
| 437 | global _SESSION |
| 438 | default_session = ops.get_default_session() |
| 439 | if default_session is not None: |
| 440 | session = default_session |
| 441 | else: |
| 442 | if ops.inside_function(): |
| 443 | raise RuntimeError('Cannot get session inside Tensorflow graph function.') |
| 444 | # If we don't have a session, or that session does not match the current |
| 445 | # graph, create and cache a new session. |
| 446 | if (getattr(_SESSION, 'session', None) is None or |
| 447 | _SESSION.session.graph is not _current_graph(op_input_list)): |
| 448 | # If we are creating the Session inside a tf.distribute.Strategy scope, |
| 449 | # we ask the strategy for the right session options to use. |
| 450 | if distribution_strategy_context.has_strategy(): |
| 451 | configure_and_create_distributed_session( |
| 452 | distribution_strategy_context.get_strategy()) |
| 453 | else: |
| 454 | _SESSION.session = session_module.Session( |
| 455 | config=get_default_session_config()) |
| 456 | session = _SESSION.session |
| 457 | return session |
| 458 | |
| 459 | |
| 460 | @keras_export(v1=['keras.backend.get_session']) |
no test coverage detected