当前位置:网站首页>tf.set_random_seed()
tf.set_random_seed()
2022-07-22 05:07:00 【Wanderer001】
参考 tf.set_random_seed() - 云+社区 - 腾讯云
设置图级随机seed。依赖于随机seed的操作实际上从两个seed中获取:图级和操作级seed。 这将设置图级别的seed。其与操作级seed的相互作用如下:
- 如果没有设置图形级别和操作seed,则使用随机seed进行操作。
- 如果设置了图级seed,但操作seed没有设置:系统确定性地选择与图级seed一起的操作seed,以便获得唯一的随机序列。
- 如果没有设置图级seed,但是设置了操作seed:使用默认的图级seed和指定的操作seed来确定随机序列。
- 如果图级和操作seed都被设置:两个seed联合使用以确定随机序列。
为了说明用户可见的效果,请考虑以下示例:
要跨会话生成不同的序列,既不设置图级别也不设置op级别的seed:
a = tf.random_uniform([1])
b = tf.random_normal([1])
print("Session 1")
with tf.Session() as sess1:
print(sess1.run(a)) # generates 'A1'
print(sess1.run(a)) # generates 'A2'
print(sess1.run(b)) # generates 'B1'
print(sess1.run(b)) # generates 'B2'
print("Session 2")
with tf.Session() as sess2:
print(sess2.run(a)) # generates 'A3'
print(sess2.run(a)) # generates 'A4'
print(sess2.run(b)) # generates 'B3'
print(sess2.run(b)) # generates 'B4'
要为跨会话生成一个可操作的序列,请为op设置seed:为了使所有op产生的随机序列在会话之间是可重复的,请设置一个图级别的seed:
a = tf.random_uniform([1], seed=1)
b = tf.random_normal([1])
# Repeatedly running this block with the same graph will generate the same
# sequence of values for 'a', but different sequences of values for 'b'.
print("Session 1")
with tf.Session() as sess1:
print(sess1.run(a)) # generates 'A1'
print(sess1.run(a)) # generates 'A2'
print(sess1.run(b)) # generates 'B1'
print(sess1.run(b)) # generates 'B2'
print("Session 2")
with tf.Session() as sess2:
print(sess2.run(a)) # generates 'A1'
print(sess2.run(a)) # generates 'A2'
print(sess2.run(b)) # generates 'B3'
print(sess2.run(b)) # generates 'B4'
为了使所有op产生的随机序列在会话之间是可重复的,请设置一个图级别的seed:
tf.set_random_seed(1234)
a = tf.random_uniform([1])
b = tf.random_normal([1])
# Repeatedly running this block with the same graph will generate different
# sequences of 'a' and 'b'.
print("Session 1")
with tf.Session() as sess1:
print(sess1.run(a)) # generates 'A1'
print(sess1.run(a)) # generates 'A2'
print(sess1.run(b)) # generates 'B1'
print(sess1.run(b)) # generates 'B2'
print("Session 2")
with tf.Session() as sess2:
print(sess2.run(a)) # generates 'A1'
print(sess2.run(a)) # generates 'A2'
print(sess2.run(b)) # generates 'B1'
print(sess2.run(b)) # generates 'B2'
边栏推荐
猜你喜欢
BUUCTFReservewp(3)
Qt warning: C4819: 该文件包含不能在当前代码页(936)中表示的字符。请将该文件保存为 Unicode 格式以防止数据丢失
跨域问题(CORS)详细说明和解决
toString()及重写的作用与应用
Binary tree OJ question, IO question
数据湖:数据湖技术架构演进
Large file slice upload and breakpoint continuation
【网页性能优化】-—— 关于图片懒加载
高数_第2章多元函数微分学_隐函数的偏导数
Grasp the development trend of robot education towards AI intelligence
随机推荐
UE4 用灰度图构建地形
[leetcode stack and queue -- minimum stack] 155. Minimum stack
Left ear mouse: developers in the cloud native era should have these five capabilities
Bryntum Scheduler Pro 5.0.6 \Gantt\Crack
我,AI博士生,在线众筹研究主题
postgreSQL中update set a=(select ) 应该如何写?
ARC110E Shorten ABC
QUuid
【vs】 试图加载格式不正确的程序
How to install a pagoda on IBM's free machine
PHP QR code decoding qrreader class | QR code image to string
How to connect Youxuan database on this computer
Large file slice upload and breakpoint continuation
ERROR: Could not build wheels for pycocotools which use PEP 517 and cannot be installed directly
左耳朵耗子:云原生时代的开发者应具备这5大能力
【红队】ATT&CK - 浏览器扩展实现持久化
Random forest learning notes
Look at the steam education mode integrating mathematics teaching
15_额外的模型
CF464E The Classic Problem