eval()函数的理解

import tensorflow as tf
import numpy as np

with tf.variable_scope("test1",initializer=tf.constant_initializer(0.4)):
    var1=tf.get_variable('firstvar',shape=[2],dtype=tf.float32)
    with tf.variable_scope("test2"):
        var2=tf.get_variable('firstvar',shape=[2],dtype=tf.float32)
        var3=tf.get_variable('var3',shape=[2],initializer=tf.constant_initializer(0.3))

with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    print('var1:',var1.eval())
    print('var2:',var2.eval())
    print('var3:',var3)
#==========================================================
'''var1: [ 0.40000001  0.40000001]
   var2: [ 0.40000001  0.40000001]
   var3: <tf.Variable 'test1/test2/var3:0' shape=(2,) dtype=float32_ref>
'''
 

eval函数就是把不能能直接显示为数字的字符串,转化为数字显示出来

猜你喜欢

转载自blog.csdn.net/weixin_41950276/article/details/84103272
今日推荐