zoukankan      html  css  js  c++  java
  • tensorflow 中 name_scope和variable_scope

    from http://blog.csdn.net/appleml/article/details/53668237
    1. import tensorflow as tf  
    2. with tf.name_scope("hello") as name_scope:  
    3.     arr1 = tf.get_variable("arr1", shape=[2,10],dtype=tf.float32)  
    4.   
    5.     print (name_scope)  
    6.     print (arr1.name)  
    7.     print ("scope_name:%s " % tf.get_variable_scope().original_name_scope)  

    运行后的结果如下:

    hello/
    arr1:0
    scope_name:  

     
    1. import tensorflow as tf  
    2. with tf.name_scope('hidden') as scope:  
    3.   a = tf.constant(5, name='alpha')  
    4.   W = tf.Variable(tf.random_uniform([1, 2], -1.0, 1.0), name='weights')  
    5.   b = tf.Variable(tf.zeros([1]), name='biases')  
    6.   print (a.name)  
    7.   print (W.name)  
    8.   print (b.name)  

    运行的结果:

    hidden/alpha:0
    hidden/weights:0
    hidden/biases:0

    红色字体要强调的部分所以把字体改成了红色,理解name_scope 对 tf.get_variable()的作用和 tf.Variable()的不同

  • 相关阅读:
    Android基础
    Android基础
    Java小项目——多线程弹球
    Java小项目——抽奖系统
    Java小项目——五子棋
    Java小项目——画板
    Java基础——swing登录界面
    Java基础——类的继承
    实验室资料说明
    20180919 百信、百度面试
  • 原文地址:https://www.cnblogs.com/mdumpling/p/8044833.html
Copyright © 2011-2022 走看看