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 相关文章推荐
Django框架中处理URLconf中特定的URL的方法
Jul 20 Python
Python实现注册、登录小程序功能
Sep 21 Python
python 提取tuple类型值中json格式的key值方法
Dec 31 Python
python实现批量修改服务器密码的方法
Aug 13 Python
基于Python的图像数据增强Data Augmentation解析
Aug 13 Python
你还在@微信官方?聊聊Python生成你想要的微信头像
Sep 25 Python
详解numpy矩阵的创建与数据类型
Oct 18 Python
解决使用python print打印函数返回值多一个None的问题
Apr 09 Python
Python Dict找出value大于某值或key大于某值的所有项方式
Jun 05 Python
Python基于Faker假数据构造库
Nov 30 Python
深入理解Pytorch微调torchvision模型
Nov 11 Python
Python  lambda匿名函数和三元运算符
Apr 19 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数据库操作面向对象的优点
2006/10/09 PHP
基于mysql的论坛(6)
2006/10/09 PHP
PHP实现微信公众平台音乐点播
2014/03/20 PHP
php基于自定义函数记录log日志方法
2017/07/21 PHP
jQuery技巧大放送 学习jquery的朋友可以看下
2009/10/14 Javascript
JSON 和 JavaScript eval使用说明
2010/06/13 Javascript
从零开始学习jQuery (二) 万能的选择器
2010/10/01 Javascript
鼠标放在图片上显示大图的JS代码
2013/03/26 Javascript
A标签触发onclick事件而不跳转的多种解决方法
2013/06/27 Javascript
innerHTML,outerHTML,innerText,outerText的用法及区别解析
2013/12/16 Javascript
JavaScript点击按钮后弹出透明浮动层的方法
2015/05/11 Javascript
JavaScript中停止执行setInterval和setTimeout事件的方法
2015/05/14 Javascript
jquery实现弹出层效果实例
2015/05/19 Javascript
WordPress中利用AJAX技术进行评论提交的实现示例
2016/01/12 Javascript
js遍历map javaScript遍历map的简单实现
2016/08/26 Javascript
Javascript实现登录记住用户名和密码功能
2017/03/22 Javascript
Angular 4依赖注入学习教程之ClassProvider的使用(三)
2017/06/04 Javascript
详解最新vue-cli 2.9.1的webpack存在问题
2017/12/16 Javascript
微信小程序入门之广告条实现方法示例
2018/12/05 Javascript
layer提示框添加多个按钮选择的实例
2019/09/12 Javascript
微信小程序实现滑动操作代码
2020/04/23 Javascript
Python的Flask框架中的Jinja2模板引擎学习教程
2016/06/30 Python
全面了解python中的类,对象,方法,属性
2016/09/11 Python
Python 读写文件和file对象的方法(推荐)
2016/09/12 Python
Django权限机制实现代码详解
2018/02/05 Python
python2.7+selenium2实现淘宝滑块自动认证功能
2018/02/24 Python
Python Opencv中用compareHist函数进行直方图比较对比图片
2020/04/07 Python
Python爬虫requests库多种用法实例
2020/05/28 Python
一篇文章带你搞定Ubuntu中打开Pycharm总是卡顿崩溃
2020/11/02 Python
教你如何一步一步用Canvas写一个贪吃蛇
2018/10/22 HTML / CSS
美国校服网上商店:French Toast
2019/10/08 全球购物
Auguste The Label官网:澳大利亚一家精品女装时尚品牌
2020/06/14 全球购物
单位委托书范本
2014/04/04 职场文书
玄武湖导游词
2015/02/05 职场文书
村党组织公开承诺书
2015/04/30 职场文书
班委竞选稿范文
2015/11/21 职场文书