用另一个 Generator 对象替换全局生成器。
用法
tf.random.set_global_generator(
generator
)参数
-
generator新的Generator对象。
此函数用提供的generator 对象替换全局生成器。随机数生成器利用tf.Variable 对象来存储其状态。用户应注意 set_global_generator 如何与 tf.function 交互的注意事项:
- tf.function 对变量创建施加了限制,因此无法在
tf.function内自由创建新的随机生成器实例。要在tf.function中调用set_global_generator,必须已经即刻地创建了生成器实例。 - tf.function 在 trace-compilation 期间捕获变量,因此编译的 f.function 不会受到
set_global_generator的影响,如 random_test.py/RandomTest.testResetGlobalGeneratorBadWithDefun 所示。
对于大多数用例,避免在程序初始化后调用set_global_generator,而是更愿意重置现有全局生成器的状态,例如,
rng = tf.random.get_global_generator()
rng.reset_from_seed(30)
相关用法
- Python tf.random.set_seed用法及代码示例
- Python tf.random.stateless_uniform用法及代码示例
- Python tf.random.shuffle用法及代码示例
- Python tf.random.stateless_parameterized_truncated_normal用法及代码示例
- Python tf.random.stateless_poisson用法及代码示例
- Python tf.random.stateless_binomial用法及代码示例
- Python tf.random.stateless_categorical用法及代码示例
- Python tf.random.stateless_gamma用法及代码示例
- Python tf.random.truncated_normal用法及代码示例
- Python tf.random.Generator用法及代码示例
- Python tf.random.Generator.binomial用法及代码示例
- Python tf.random.normal用法及代码示例
- Python tf.random.experimental.stateless_split用法及代码示例
- Python tf.random.uniform用法及代码示例
- Python tf.random.categorical用法及代码示例
- Python tf.random.experimental.stateless_fold_in用法及代码示例
- Python tf.random.Generator.make_seeds用法及代码示例
- Python tf.random.poisson用法及代码示例
- Python tf.random.gamma用法及代码示例
- Python tf.random.create_rng_state用法及代码示例
注:本文由纯净天空筛选整理自tensorflow.org大神的英文原创作品 tf.random.set_global_generator。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
