tensorflow 打印内存中的变量方法
法一:
循环打印
模板
for(x,y)inzip(tf.global_variables(),sess.run(tf.global_variables())): print'\n',x,y
实例
#coding=utf-8 importtensorflowastf deffunc(in_put,layer_name,is_training=True): withtf.variable_scope(layer_name,reuse=tf.AUTO_REUSE): bn=tf.contrib.layers.batch_norm(inputs=in_put, decay=0.9, is_training=is_training, updates_collections=None) returnbn defmain(): withtf.Graph().as_default(): #input_x input_x=tf.placeholder(dtype=tf.float32,shape=[1,4,4,1]) importnumpyasnp i_p=np.random.uniform(low=0,high=255,size=[1,4,4,1]) #outputs output=func(input_x,'my',is_training=True) withtf.Session()assess: sess.run(tf.global_variables_initializer()) t=sess.run(output,feed_dict={input_x:i_p}) #法一:循环打印 for(x,y)inzip(tf.global_variables(),sess.run(tf.global_variables())): print'\n',x,y if__name__=="__main__": main()
2017-09-2910:10:22.714213:Itensorflow/core/common_runtime/gpu/gpu_device.cc:1052]CreatingTensorFlowdevice(/device:GPU:0)->(device:0,name:GeForceGTX1070,pcibusid:0000:01:00.0,computecapability:6.1)[0.] [13.46412563] [452.62246704] Processfinishedwithexitcode0
法二:
指定变量名打印
模板
print'my/BatchNorm/beta:0',(sess.run('my/BatchNorm/beta:0'))
实例
#coding=utf-8 importtensorflowastf deffunc(in_put,layer_name,is_training=True): withtf.variable_scope(layer_name,reuse=tf.AUTO_REUSE): bn=tf.contrib.layers.batch_norm(inputs=in_put, decay=0.9, is_training=is_training, updates_collections=None) returnbn defmain(): withtf.Graph().as_default(): #input_x input_x=tf.placeholder(dtype=tf.float32,shape=[1,4,4,1]) importnumpyasnp i_p=np.random.uniform(low=0,high=255,size=[1,4,4,1]) #outputs output=func(input_x,'my',is_training=True) withtf.Session()assess: sess.run(tf.global_variables_initializer()) t=sess.run(output,feed_dict={input_x:i_p}) #法二:指定变量名打印 print'my/BatchNorm/beta:0',(sess.run('my/BatchNorm/beta:0')) print'my/BatchNorm/moving_mean:0',(sess.run('my/BatchNorm/moving_mean:0')) print'my/BatchNorm/moving_variance:0',(sess.run('my/BatchNorm/moving_variance:0')) if__name__=="__main__": main()
2017-09-2910:12:41.374055:Itensorflow/core/common_runtime/gpu/gpu_device.cc:1052]CreatingTensorFlowdevice(/device:GPU:0)->(device:0,name:GeForceGTX1070,pcibusid:0000:01:00.0,computecapability:6.1) my/BatchNorm/beta:0[0.] my/BatchNorm/moving_mean:0[8.08649635] my/BatchNorm/moving_variance:0[368.03442383] Processfinishedwithexitcode0
以上这篇tensorflow打印内存中的变量方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。