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

Method __enter__

tensorflow/python/framework/ops.py:6395–6440  ·  view source on GitHub ↗

Start the scope block. Returns: The scope name. Raises: ValueError: if neither `name` nor `default_name` is provided but `values` are.

(self)

Source from the content-addressed store, hash-verified

6393 self._name_scope = value.graph.name_scope(self._name)
6394
6395 def __enter__(self):
6396 """Start the scope block.
6397
6398 Returns:
6399 The scope name.
6400
6401 Raises:
6402 ValueError: if neither `name` nor `default_name` is provided
6403 but `values` are.
6404 """
6405 if self._has_symbolic_input_in_eager:
6406 return self._name_scope.__enter__()
6407
6408 if self._in_eager_mode:
6409 scope_name, self._old_name = enter_eager_name_scope(self._ctx, self._name)
6410 return scope_name
6411 else:
6412 if self._name is None and self._values is not None:
6413 # We only raise an error if values is not None (provided) because
6414 # currently tf.name_scope(None) (values=None then) is sometimes used as
6415 # an idiom to reset to top scope.
6416 raise ValueError(
6417 "At least one of name (%s) and default_name (%s) must be provided."
6418 % (self._name, self._default_name))
6419
6420 g = get_default_graph()
6421 if self._values and not g.building_function:
6422 # Specialize based on the knowledge that `_get_graph_from_inputs()`
6423 # ignores `inputs` when building a function.
6424 g_from_inputs = _get_graph_from_inputs(self._values)
6425 if g_from_inputs is not g:
6426 g = g_from_inputs
6427 self._g_manager = g.as_default()
6428 self._g_manager.__enter__()
6429 else:
6430 self._g_manager = None
6431 else:
6432 self._g_manager = None
6433
6434 try:
6435 self._name_scope = g.name_scope(self._name)
6436 return self._name_scope.__enter__()
6437 except:
6438 if self._g_manager is not None:
6439 self._g_manager.__exit__(*sys.exc_info())
6440 raise
6441
6442 def __exit__(self, type_arg, value_arg, traceback_arg):
6443 if self._has_symbolic_input_in_eager:

Callers 3

testNestingErrorGraphMethod · 0.45
testNestingErrorEagerMethod · 0.45
__enter__Method · 0.45

Calls 6

enter_eager_name_scopeFunction · 0.85
get_default_graphFunction · 0.85
_get_graph_from_inputsFunction · 0.85
as_defaultMethod · 0.45
name_scopeMethod · 0.45
__exit__Method · 0.45

Tested by 2

testNestingErrorGraphMethod · 0.36
testNestingErrorEagerMethod · 0.36