fluid.unique_name

generate

paddle.fluid.unique_name.generate(key)[source]

Generate unique name with prefix key.

Parameters:key (str) – The generated name prefix. All generated name will be started with this prefix.
Returns:A unique string with the prefix key.
Return type:str

Examples

import paddle.fluid as fluid
name1 = fluid.unique_name.generate('fc')
name2 = fluid.unique_name.generate('fc')
# The result is fc_0, fc_1
print name1, name2

guard

paddle.fluid.unique_name.guard(new_generator=None)[source]

Change the global namespace with with statement.

Parameters:new_generator (None|str|bytes) – New name of global namespace. Note that str in Python2 was spilted into str and bytes in Python3, so here are two types. Default is None.

Examples

import paddle.fluid as fluid
with fluid.unique_name.guard():
  name_1 = fluid.unique_name.generate('fc')
with fluid.unique_name.guard():
  name_2 = fluid.unique_name.generate('fc')
# The result is fc_0, fc_0
print name_1, name_2

with fluid.unique_name.guard('A'):
  name_1 = fluid.unique_name.generate('fc')
with fluid.unique_name.guard('B'):
  name_2 = fluid.unique_name.generate('fc')
# The result is Afc_0, Bfc_0
print name_1, name_2

switch

paddle.fluid.unique_name.switch(new_generator=None)[source]

Switch the Global namespace to a new namespace.

Parameters:new_generator (None|UniqueNameGenerator) – A new UniqueNameGenerator.
Returns:The previous UniqueNameGenerator.
Return type:UniqueNameGenerator

Examples

import paddle.fluid as fluid
name1 = fluid.unique_name.generate('fc')
name2 = fluid.unique_name.generate('fc')
# The result is fc_0, fc_1
print name1, name2

fluid.unique_name.switch()
name2 = fluid.unique_name.generate('fc')
# The result is fc_0
print name2