`tf.set_random_seed()` 相当于操作种子? [英] `tf.set_random_seed()` equivalent for operations seed?

查看:44
本文介绍了`tf.set_random_seed()` 相当于操作种子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标题几乎说明了一切.你知道在 tensorflow 中是否存在与 tf.set_random_seed() 等效的操作种子.我正在尝试在定义为两个不同图形的两个精确 NN 上初始化完全相同的权重,所以我想知道是否有一种方法可以全局设置所有操作的操作种子,而不必一个一个地为每个操作定义种子(在我的例子中,在 NN 每一层的内核初始化器上 --> tf.glorot_uniform_initializer(seed=777)).

Title pretty much explains everything. Do you know if there exists an equivalent to tf.set_random_seed() for the operations seed in tensorflow. I'm trying to initialize exactly same weights at two exact NN defined into two different graphs, so I was wondering if there is a way to globally set the operations seed for all operations instead of having to define the seed to each operation one by one (in my case, on the kernel initializer of each layer of the NN --> tf.glorot_uniform_initializer(seed=777)).

我一直在寻找它,但我的搜索失败了.有谁知道如何一次为图中的所有操作设置操作种子?感谢您的帮助!

I have been looking for it but failed on my search. Does anyone knows how to set up the operations seed for all the operations in the graph at once? Thanks for your help!

推荐答案

根据 tf.set_random_seed() 只设置图形级别的种子应该可以达到你想要的:

According to the documentation of tf.set_random_seed() setting only the graph level seed should achieve what you are looking for:

如果设置了图级种子,但未设置操作种子:系统确定性地选择操作种子和图级种子,以便获得唯一的随机序列.

If the graph-level seed is set, but the operation seed is not: The system deterministically picks an operation seed in conjunction with the graph-level seed so that it gets a unique random sequence.

要使所有操作生成的随机序列在会话之间可重复,请设置图形级种子

To make the random sequences generated by all ops be repeatable across sessions, set a graph-level seed

但是您必须记住使用相同的种子分别为两个图调用 tf.set_random_seed().

But you have to remember to call tf.set_random_seed() for both graphs individually with the same seed.

但这可能仍然行不通,特别是如果图表是在不同设备上执行的(我不确定).确保两个图都使用相同初始化的一个安全选项可能是简单地初始化两个图中的一个,然后将第二个中的变量设置为第一个的值.

But that might still not work, especially if the graphs are executed on different devices (I am not sure about that). A safe option to make sure both graphs are using the same initialization might be to simply initialize one of the two and then just set the variables in the second one to the values of the first.

这篇关于`tf.set_random_seed()` 相当于操作种子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆