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 相关文章推荐
Python3里的super()和__class__使用介绍
Apr 23 Python
Python 转义字符详细介绍
Mar 21 Python
浅析python递归函数和河内塔问题
Apr 18 Python
python安装教程 Pycharm安装详细教程
May 02 Python
Python编程实现的简单Web服务器示例
Jun 22 Python
Python查找文件中包含中文的行方法
Dec 19 Python
python+opencv实现高斯平滑滤波
Jul 21 Python
如何使用pyinstaller打包32位的exe程序
May 26 Python
在django模板中实现超链接配置
Aug 21 Python
python+selenium select下拉选择框定位处理方法
Aug 24 Python
tensorflow中tf.reduce_mean函数的使用
Apr 19 Python
pycharm无法导入lxml的解决办法
Mar 31 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
在smarty模板中使用PHP函数的方法
2011/04/23 PHP
深入理解PHP之数组(遍历顺序)  Laruence原创
2012/06/13 PHP
PHP快速按行读取CSV大文件的封装类分享(也适用于其它超大文本文件)
2014/04/10 PHP
PHP rsa加密解密使用方法
2015/04/27 PHP
PHP中file_get_contents函数抓取https地址出错的解决方法(两种方法)
2015/09/22 PHP
php图片裁剪函数
2018/10/31 PHP
PHP实现获取url地址中顶级域名的方法示例
2019/06/05 PHP
你的 mixin 真的兼容 ECMAScript 5 吗?
2013/04/11 Javascript
通过bootstrap全面学习less
2016/11/09 Javascript
bootstrap Table插件使用demo
2017/08/07 Javascript
详细分析jsonp的原理和实现方式
2017/11/20 Javascript
JS简单添加元素新节点的方法示例
2018/02/10 Javascript
利用vue重构有赞商城的思路以及总结整理
2019/02/21 Javascript
vue单页应用的内存泄露定位和修复问题小结
2019/08/02 Javascript
vue任意关系组件通信与跨组件监听状态vue-communication
2020/10/18 Javascript
Python利用正则表达式匹配并截取指定子串及去重的方法
2015/07/30 Python
python实现简单购物商城
2016/05/21 Python
python+selenium+autoit实现文件上传功能
2017/08/23 Python
Python排序算法之选择排序定义与用法示例
2018/04/29 Python
Python 文本文件内容批量抽取实例
2018/12/10 Python
Python实现的爬取小说爬虫功能示例
2019/03/30 Python
python字典排序的方法
2019/10/12 Python
捷克厨房用品购物网站:Tescoma
2018/07/13 全球购物
Bibloo奥地利:购买女装、男装、童装、鞋和配件
2018/10/18 全球购物
台湾时尚彩瞳专门店:imeime
2019/08/16 全球购物
可以在一个PHP文件里面include另外一个PHP文件两次吗
2015/05/22 面试题
EJB3.1都有哪些改进
2012/11/17 面试题
出国导师推荐信
2014/01/16 职场文书
硕士生工作推荐信
2014/03/07 职场文书
质量月口号
2014/06/20 职场文书
检讨书模板大全
2015/05/07 职场文书
2015年科普工作总结
2015/07/23 职场文书
2015年乡镇组织委员工作总结
2015/10/23 职场文书
小学思想品德教学反思
2016/02/24 职场文书
Python 数据科学 Matplotlib图库详解
2021/07/07 Python
Python日志模块logging用法
2022/06/05 Python