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

Function default_session

tensorflow/python/framework/ops.py:5384–5429  ·  view source on GitHub ↗

Python "with" handler for defining a default session. This function provides a means of registering a session for handling Tensor.eval() and Operation.run() calls. It is primarily intended for use by session.Session, but can be used with any object that implements the Session.run() interfac

(session)

Source from the content-addressed store, hash-verified

5382
5383
5384def default_session(session):
5385 """Python "with" handler for defining a default session.
5386
5387 This function provides a means of registering a session for handling
5388 Tensor.eval() and Operation.run() calls. It is primarily intended for use
5389 by session.Session, but can be used with any object that implements
5390 the Session.run() interface.
5391
5392 Use with the "with" keyword to specify that Tensor.eval() and Operation.run()
5393 invocations within the scope of a block should be executed by a particular
5394 session.
5395
5396 The default session applies to the current thread only, so it is always
5397 possible to inspect the call stack and determine the scope of a default
5398 session. If you create a new thread, and wish to use the default session
5399 in that thread, you must explicitly add a "with ops.default_session(sess):"
5400 block in that thread's function.
5401
5402 Example:
5403 The following code examples are equivalent:
5404
5405 # 1. Using the Session object directly:
5406 sess = ...
5407 c = tf.constant(5.0)
5408 sess.run(c)
5409
5410 # 2. Using default_session():
5411 sess = ...
5412 with ops.default_session(sess):
5413 c = tf.constant(5.0)
5414 result = c.eval()
5415
5416 # 3. Overriding default_session():
5417 sess = ...
5418 with ops.default_session(sess):
5419 c = tf.constant(5.0)
5420 with ops.default_session(...):
5421 c.eval(session=sess)
5422
5423 Args:
5424 session: The session to be installed as the default session.
5425
5426 Returns:
5427 A context manager for the default session.
5428 """
5429 return _default_session_stack.get_controller(session)
5430
5431
5432@tf_export(v1=["get_default_session"])

Callers

nothing calls this directly

Calls 1

get_controllerMethod · 0.45

Tested by

no test coverage detected