tensorflow 打印内存中的变量方法


Posted in Python onJuly 30, 2018

法一:

循环打印

模板

for (x, y) in zip(tf.global_variables(), sess.run(tf.global_variables())):
 print '\n', x, y

实例

# coding=utf-8

import tensorflow as tf


def func(in_put, layer_name, is_training=True):
 with tf.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)
 return bn

def main():

 with tf.Graph().as_default():
  # input_x
  input_x = tf.placeholder(dtype=tf.float32, shape=[1, 4, 4, 1])
  import numpy as np
  i_p = np.random.uniform(low=0, high=255, size=[1, 4, 4, 1])
  # outputs
  output = func(input_x, 'my', is_training=True)
  with tf.Session() as sess:
   sess.run(tf.global_variables_initializer())
   t = sess.run(output, feed_dict={input_x:i_p})

   # 法一: 循环打印
   for (x, y) in zip(tf.global_variables(), sess.run(tf.global_variables())):
    print '\n', x, y

if __name__ == "__main__":
 main()
2017-09-29 10:10:22.714213: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1052] Creating TensorFlow device (/device:GPU:0) -> (device: 0, name: GeForce GTX 1070, pci bus id: 0000:01:00.0, compute capability: 6.1)

<tf.Variable 'my/BatchNorm/beta:0' shape=(1,) dtype=float32_ref> [ 0.]

<tf.Variable 'my/BatchNorm/moving_mean:0' shape=(1,) dtype=float32_ref> [ 13.46412563]

<tf.Variable 'my/BatchNorm/moving_variance:0' shape=(1,) dtype=float32_ref> [ 452.62246704]

Process finished with exit code 0

法二:

指定变量名打印

模板

print 'my/BatchNorm/beta:0', (sess.run('my/BatchNorm/beta:0'))

实例

# coding=utf-8

import tensorflow as tf


def func(in_put, layer_name, is_training=True):
 with tf.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)
 return bn

def main():

 with tf.Graph().as_default():
  # input_x
  input_x = tf.placeholder(dtype=tf.float32, shape=[1, 4, 4, 1])
  import numpy as np
  i_p = np.random.uniform(low=0, high=255, size=[1, 4, 4, 1])
  # outputs
  output = func(input_x, 'my', is_training=True)
  with tf.Session() as sess:
   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-29 10:12:41.374055: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1052] Creating TensorFlow device (/device:GPU:0) -> (device: 0, name: GeForce GTX 1070, pci bus id: 0000:01:00.0, compute capability: 6.1)

my/BatchNorm/beta:0 [ 0.]
my/BatchNorm/moving_mean:0 [ 8.08649635]
my/BatchNorm/moving_variance:0 [ 368.03442383]

Process finished with exit code 0

以上这篇tensorflow 打印内存中的变量方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持三水点靠木。

Python 相关文章推荐
Python中使用item()方法遍历字典的例子
Aug 26 Python
python制作爬虫爬取京东商品评论教程
Dec 16 Python
python timestamp和datetime之间转换详解
Dec 11 Python
python基于ID3思想的决策树
Jan 03 Python
python生成ppt的方法
Jun 07 Python
python3实现SMTP发送邮件详细教程
Jun 19 Python
python实现QQ批量登录功能
Jun 19 Python
python词云库wordcloud的使用方法与实例详解
Feb 17 Python
Tensorflow中的降维函数tf.reduce_*使用总结
Apr 20 Python
python通过函数名调用函数的几种场景
Sep 23 Python
python实现经纬度采样的示例代码
Dec 10 Python
python使用Windows的wmic命令监控文件运行状况,如有异常发送邮件报警
Jan 30 Python
Python实现的多叉树寻找最短路径算法示例
Jul 30 #Python
tensorflow: variable的值与variable.read_value()的值区别详解
Jul 30 #Python
Tensorflow 实现修改张量特定元素的值方法
Jul 30 #Python
python用BeautifulSoup库简单爬虫实例分析
Jul 30 #Python
对TensorFlow的assign赋值用法详解
Jul 30 #Python
Python双向循环链表实现方法分析
Jul 30 #Python
tensorflow更改变量的值实例
Jul 30 #Python
You might like
php自定义urlencode,urldecode函数实例
2015/03/24 PHP
简单介绍win7下搭建apache+php+mysql开发环境
2015/08/06 PHP
举例讲解PHP面对对象编程的多态
2015/08/12 PHP
PHP中检查isset()和!empty()函数的必要性
2019/02/13 PHP
slice函数的用法 之不错的应用
2006/12/29 Javascript
WebGame《逆转裁判》完整版 代码下载(1月24日更新)
2007/01/29 Javascript
Dom操作之兼容技巧分享
2011/09/20 Javascript
在JavaScript中使用对数Math.log()方法的教程
2015/06/15 Javascript
微信小程序 POST请求(网络请求)详解及实例代码
2016/11/16 Javascript
关于微信上网页图片点击全屏放大效果
2016/12/19 Javascript
JavaScript获取中英文混合字符串长度的方法示例
2017/02/04 Javascript
jquery仿苹果的时间/日期选择效果
2017/03/08 Javascript
JavaScript无缝滚动效果的实例代码
2017/03/27 Javascript
浅谈webpack打包之后的文件过大的解决方法
2018/03/07 Javascript
JS实现秒杀倒计时特效
2020/01/02 Javascript
vue学习笔记之slot插槽基本用法实例分析
2020/02/01 Javascript
JavaScript 判断数据类型的4种方法
2020/09/11 Javascript
js中实现继承的五种方法
2021/01/25 Javascript
[38:41]2014 DOTA2国际邀请赛中国区预选赛 LGD VS CNB
2014/05/22 DOTA
用Python输出一个杨辉三角的例子
2014/06/13 Python
Python实现partial改变方法默认参数
2014/08/18 Python
Python中几种操作字符串的方法的介绍
2015/04/09 Python
python使用xmlrpclib模块实现对百度google的ping功能
2015/06/02 Python
Python 反转字符串(reverse)的方法小结
2018/02/20 Python
使用sklearn进行对数据标准化、归一化以及将数据还原的方法
2018/07/11 Python
python爬虫 猫眼电影和电影天堂数据csv和mysql存储过程解析
2019/09/05 Python
python程序文件扩展名知识点详解
2020/02/27 Python
pycharm的python_stubs问题
2020/04/08 Python
Python实现GIF图倒放
2020/07/16 Python
python生成xml时规定dtd实例方法
2020/09/21 Python
CSS实现进度条和订单进度条的示例
2020/11/05 HTML / CSS
英国在线定制百叶窗网站:Swift Direct Blinds
2020/02/25 全球购物
英语专业毕业生自荐信范文
2013/12/31 职场文书
法律进社区实施方案
2014/03/21 职场文书
大学生通用个人自我评价
2014/04/27 职场文书
Vue + iView实现Excel上传功能的完整代码
2021/06/22 Vue.js