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

Method unique_name

tensorflow/python/framework/ops.py:4165–4215  ·  view source on GitHub ↗

Return a unique operation name for `name`. Note: You rarely need to call `unique_name()` directly. Most of the time you just need to create `with g.name_scope()` blocks to generate structured names. `unique_name` is used to generate structured names, separated by `"/"`, to hel

(self, name, mark_as_used=True)

Source from the content-addressed store, hash-verified

4163 # pylint: enable=g-doc-return-or-yield,line-too-long
4164
4165 def unique_name(self, name, mark_as_used=True):
4166 """Return a unique operation name for `name`.
4167
4168 Note: You rarely need to call `unique_name()` directly. Most of
4169 the time you just need to create `with g.name_scope()` blocks to
4170 generate structured names.
4171
4172 `unique_name` is used to generate structured names, separated by
4173 `"/"`, to help identify operations when debugging a graph.
4174 Operation names are displayed in error messages reported by the
4175 TensorFlow runtime, and in various visualization tools such as
4176 TensorBoard.
4177
4178 If `mark_as_used` is set to `True`, which is the default, a new
4179 unique name is created and marked as in use. If it's set to `False`,
4180 the unique name is returned without actually being marked as used.
4181 This is useful when the caller simply wants to know what the name
4182 to be created will be.
4183
4184 Args:
4185 name: The name for an operation.
4186 mark_as_used: Whether to mark this name as being used.
4187
4188 Returns:
4189 A string to be passed to `create_op()` that will be used
4190 to name the operation being created.
4191 """
4192 if self._name_stack:
4193 name = self._name_stack + "/" + name
4194
4195 # For the sake of checking for names in use, we treat names as case
4196 # insensitive (e.g. foo = Foo).
4197 name_key = name.lower()
4198 i = self._names_in_use.get(name_key, 0)
4199 # Increment the number for "name_key".
4200 if mark_as_used:
4201 self._names_in_use[name_key] = i + 1
4202 if i > 0:
4203 base_name_key = name_key
4204 # Make sure the composed name key is not already used.
4205 while name_key in self._names_in_use:
4206 name_key = "%s_%d" % (base_name_key, i)
4207 i += 1
4208 # Mark the composed name_key as used in case someone wants
4209 # to call unique_name("name_1").
4210 if mark_as_used:
4211 self._names_in_use[name_key] = 1
4212
4213 # Return the new name with the original capitalization of the given name.
4214 name = "%s_%d" % (name, i - 1)
4215 return name
4216
4217 def get_name_scope(self):
4218 """Returns the current name scope.

Callers 15

testBasicsMethod · 0.95
_create_op_internalMethod · 0.95
name_scopeMethod · 0.95
copy_op_handlerFunction · 0.80
__call__Method · 0.80
wrapped_computationFunction · 0.80
stagedFunction · 0.80
prefetch_joinFunction · 0.80
__init__Method · 0.80

Calls 1

getMethod · 0.45

Tested by 5

testBasicsMethod · 0.76