cs20_5-1

1. namspace(scope)

1.1 name_scope:
  • create namespaces, ops分组, 进而tensorboard可以各个ops进行分组显示,进而使得tensorboard的可视化效果更好,进而有助于debug
1.2 variable_scope:
  • 使用tf.get_variables() [不要用 tf.Variables() ]

  • create namespaces, ops分组,并且能实现变量共享
  • 本质上,variable_scope隐式地使用了name_scope()

2. Some tips

  1. tf.saver.restore()只能恢复latest checkpoint,能不能restore更多自定义的checkpoint,再查下api吧

  2. 有个tensorborad和summary,就没必要再使用matplotlib做可视化了

  3. op-level的random的特点:具有相同seed的sess.run()的第一次都是相同值,第二次,第三次的sess.run()就不会是相同的

    c = tf.random_uniform([], -10, 10, seed=2)
    with tf.Session() as sess:
     print sess.run(c) # >> 3.57493 # 第一次sess.run()
     print sess.run(c) # >> -5.97319 # 第二次sess.run()
    
    c = tf.random_uniform([], -10, 10, seed=2)
    with tf.Session() as sess:
     print sess.run(c) # >> 3.57493 # 当前这个sess的第一次sess.run()
    with tf.Session() as sess:
     print sess.run(c) # >> 3.57493 # 当前这个sess的第一次sess.run()
    
    c = tf.random_uniform([], -10, 10, seed=2)
    d = tf.random_uniform([], -10, 10, seed=2)
    with tf.Session() as sess:
     print sess.run(c) # >> 3.57493 # 这个sess的第一次sess.run()
     print sess.run(d) # >> 3.57493 #虽然是这个sess的第二次sess.run(),但是op换了
        # 并且新的op的seed和老的op是相同的,所以两次的结果相同
    
  4. graph-level的random

    • If you don’t care about the randomization for each op inside the graph, but just want to be able to replicate result on another graph (so that other people can replicate your results on their own graph), you can use tf.set_random_seed instead. Setting the current TensorFlow random seed affects the current default graph only.

    • # a.py
      import tensorflow as tf
      # tf.set_random_seed(2) # 去掉 graph-level的seed
      c = tf.random_uniform([], -10, 10)
      d = tf.random_uniform([], -10, 10)
      with tf.Session() as sess:
         print sess.run(c) # -4.00752
         print sess.run(d) # -2.98339
      
      # b.py
      import tensorflow as tf
      tf.set_random_seed(2)
      c = tf.random_uniform([], -10, 10)
      d = tf.random_uniform([], -10, 10)
      with tf.Session() as sess:
         print sess.run(c) # -4.00752
         print sess.run(d) # -4.00752
      
    1. tf-Autodiff的原理:

      801115-20181112140227733-1479248309.png

转载于:https://www.cnblogs.com/LS1314/p/10371184.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值