tensorflow/tf.set_random_seed()
来源:互联网 发布:甜虾 知乎 编辑:程序博客网 时间:2024/06/05 14:29
tensorflow中设置随机种子,可分为两类,图级seed和操作级seed,
情况1:当没有设置图级seed和操作级seed时,生成的随机数是随机的
情况2:当设置操作级seed时,生成的随机数是同一组随机数,没有设置操作级seed的操作,生成的随机数是随机的
情况3:当设置图级seed, 将会生成同一组随机数,如果设置操作级seed又和情况2相同
```python 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' ``` To generate the same repeatable sequence for an op across sessions, set the seed for the op: ```python 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' ``` To make the random sequences generated by all ops be repeatable across sessions, set a graph-level seed: ```python 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 the same # 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' ``` Args: seed: integer. """
阅读全文
0 0
- tensorflow/tf.set_random_seed()
- tensorflow API:tf.set_random_seed
- Tensorflow函数——tf.set_random_seed(seed)
- 转载!Tensorflow函数——tf.set_random_seed(seed)
- tensorflow + tf.transposs
- Tensorflow:tf.train.SyncReplicasOptimizer
- Tensorflow系列:tf.random_normal
- tensorflow tf.concat操作
- 【Tensorflow】tf.placeholder函数
- 【Tensorflow】tf.reshape 函数
- 【Tensorflow】tf.argmax函数
- TensorFlow. tf.reduce_mean
- 【TensorFlow】tf.scatter_update()
- tensorflow: tf.reshape探究
- tensorflow: tf.assign探究
- tensorflow tf.tile 实例
- 【TensorFlow】tf.concat
- tensorflow: tf.add_to_collection 探究
- [LeetCode] 143. Reorder List
- java 字符流相关的io操作原理分析
- 蓝桥杯_法训练—操作格子(线段树点更新与区间查询)
- PHP 5.3.0以上推荐使用mysqlnd驱动
- cocos 3.10 ccui.RichText修改计算行宽的计算方法
- tensorflow/tf.set_random_seed()
- 前向分步算法
- CI框架学习之--隐藏入口文件-index.php
- ajax的封装
- 关于深度学习中Dropout的理解
- 【转】Hexo的Next主题配置
- Kotlin-35.反射(Reflection)
- jquery对表单的几种简单的操作
- pf_ring userland code C code and C++ code Cross compile