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

Method __init__

tensorflow/python/client/session.py:1729–1777  ·  view source on GitHub ↗

Creates a new interactive TensorFlow session. If no `graph` argument is specified when constructing the session, the default graph will be launched in the session. If you are using more than one graph (created with `tf.Graph()`) in the same process, you will have to use different se

(self, target='', graph=None, config=None)

Source from the content-addressed store, hash-verified

1727 _active_session_count = 0 # GUARDED_BY(_count_lock)
1728
1729 def __init__(self, target='', graph=None, config=None):
1730 """Creates a new interactive TensorFlow session.
1731
1732 If no `graph` argument is specified when constructing the session,
1733 the default graph will be launched in the session. If you are
1734 using more than one graph (created with `tf.Graph()`) in the same
1735 process, you will have to use different sessions for each graph,
1736 but each graph can be used in multiple sessions. In this case, it
1737 is often clearer to pass the graph to be launched explicitly to
1738 the session constructor.
1739
1740 Args:
1741 target: (Optional.) The execution engine to connect to. Defaults to using
1742 an in-process engine.
1743 graph: (Optional.) The `Graph` to be launched (described above).
1744 config: (Optional) `ConfigProto` proto used to configure the session.
1745 """
1746 if not config:
1747 # If config is not provided, choose some reasonable defaults for
1748 # interactive use:
1749 #
1750 # - Grow GPU memory as needed at the cost of fragmentation.
1751 gpu_options = config_pb2.GPUOptions(allow_growth=True)
1752 config = config_pb2.ConfigProto(gpu_options=gpu_options)
1753 # Interactive sessions always place pruned graphs.
1754 config.graph_options.place_pruned_graph = True
1755
1756 super(InteractiveSession, self).__init__(target, graph, config)
1757 with InteractiveSession._count_lock:
1758 if InteractiveSession._active_session_count > 0:
1759 warnings.warn('An interactive session is already active. This can '
1760 'cause out-of-memory errors in some cases. You must '
1761 'explicitly call `InteractiveSession.close()` to release '
1762 'resources held by the other session(s).')
1763 InteractiveSession._active_session_count += 1
1764 # NOTE(mrry): We do not use `Session._closed` here because it has unhelpful
1765 # semantics (in particular, it is not set to true if `Session.close()` is
1766 # called on a session that has not been "opened" by running a step) and we
1767 # cannot change those semantics without breaking existing code.
1768 self._explicitly_closed = False
1769
1770 self._default_session = self.as_default()
1771 self._default_session.enforce_nesting = False
1772 self._default_session.__enter__()
1773 self._explicit_graph = graph
1774 if self._explicit_graph is not None:
1775 self._default_graph = graph.as_default()
1776 self._default_graph.enforce_nesting = False
1777 self._default_graph.__enter__()
1778
1779 def close(self):
1780 """Closes an `InteractiveSession`."""

Callers

nothing calls this directly

Calls 3

__init__Method · 0.45
as_defaultMethod · 0.45
__enter__Method · 0.45

Tested by

no test coverage detected