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 client使用http post 到server端的代码
Feb 10 Python
Python运用于数据分析的简单教程
Mar 27 Python
Python的Flask框架中@app.route的用法教程
Mar 31 Python
python实现的简单窗口倒计时界面实例
May 05 Python
在Django的视图(View)外使用Session的方法
Jul 23 Python
Python+matplotlib+numpy实现在不同平面的二维条形图
Jan 02 Python
Python3enumrate和range对比及示例详解
Jul 13 Python
python实现字典嵌套列表取值
Dec 16 Python
tensorflow 变长序列存储实例
Jan 20 Python
Django 设置admin后台表和App(应用)为中文名的操作方法
May 10 Python
Matplotlib中%matplotlib inline如何使用
Jul 28 Python
使用Python webdriver图书馆抢座自动预约的正确方法
Mar 04 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 URL跳转代码 减少外链
2011/06/25 PHP
AutoSave/自动存储功能实现
2007/03/24 Javascript
jquery mobile的触控点击事件会多次触发问题的解决方法
2014/05/08 Javascript
js子页面获取父页面数据示例
2014/05/15 Javascript
JS给超链接加确认对话框的方法
2015/02/24 Javascript
Nodejs实战心得之eventproxy模块控制并发
2015/10/27 NodeJs
PhotoSwipe异步动态加载图片方法
2016/08/25 Javascript
Angularjs CURD 详解及实例代码
2016/09/14 Javascript
Vue中保存用户登录状态实例代码
2017/06/07 Javascript
微信小程序开发教程之增加mixin扩展
2017/08/09 Javascript
Javascript中this关键字指向问题的测试与详解
2017/08/11 Javascript
微信小程序引用公共js里的方法的实例详解
2017/08/17 Javascript
node.js中fs文件系统目录操作与文件信息操作
2018/02/24 Javascript
使用vue中的v-for遍历二维数组的方法
2018/03/07 Javascript
javascript与PHP动态往类中添加方法对比
2018/03/21 Javascript
JavaScript轮播停留效果的实现思路
2018/05/24 Javascript
JS实现点击li标签弹出对应的索引功能【案例】
2019/02/18 Javascript
[51:22]Fnatic vs IG 2018国际邀请赛小组赛BO2 第一场 8.17
2018/08/18 DOTA
python3模拟百度登录并实现百度贴吧签到示例分享(百度贴吧自动签到)
2014/02/24 Python
Python列表list内建函数用法实例分析【insert、remove、index、pop等】
2017/07/24 Python
使用Kivy将python程序打包为apk文件
2017/07/29 Python
Pythony运维入门之Socket网络编程详解
2019/04/15 Python
python实现趣味图片字符化
2019/04/30 Python
python爬虫开发之使用python爬虫库requests,urllib与今日头条搜索功能爬取搜索内容实例
2020/03/10 Python
Python中内建模块collections如何使用
2020/05/27 Python
Keras load_model 导入错误的解决方式
2020/06/09 Python
python 爬虫如何实现百度翻译
2020/11/16 Python
HTML5之WebGL 3D概述(上)—WebGL原生开发开启网页3D渲染新时代
2013/01/31 HTML / CSS
KLOOK客路:发现更好玩的世界,预订独一无二的旅行体验
2016/12/16 全球购物
德国最新街头服饰网上商店:BODYCHECK
2019/09/15 全球购物
护士的自我鉴定
2014/02/07 职场文书
需求分析说明书
2014/05/09 职场文书
2014年师德师风学习材料
2014/05/16 职场文书
优秀家长事迹材料
2014/05/17 职场文书
2015届本科毕业生自我鉴定
2014/09/27 职场文书
交通事故调解协议书
2015/05/20 职场文书