tensorflow 打印內(nèi)存中的變量方法
法一:
循環(huán)打印
模板
for (x, y) in zip(tf.global_variables(), sess.run(tf.global_variables())): print '\n', x, y
實(shí)例
# 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})
# 法一: 循環(huán)打印
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'))
實(shí)例
# 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 打印內(nèi)存中的變量方法就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
- 解決Tensorflow sess.run導(dǎo)致的內(nèi)存溢出問(wèn)題
- 解決TensorFlow訓(xùn)練內(nèi)存不斷增長(zhǎng),進(jìn)程被殺死問(wèn)題
- 淺談tensorflow之內(nèi)存暴漲問(wèn)題
- TensorFlow內(nèi)存管理bfc算法實(shí)例
- Tensorflow 實(shí)現(xiàn)釋放內(nèi)存
- 解決tensorflow訓(xùn)練時(shí)內(nèi)存持續(xù)增加并占滿的問(wèn)題
- Tensorflow 訓(xùn)練自己的數(shù)據(jù)集將數(shù)據(jù)直接導(dǎo)入到內(nèi)存
- 解決Tensorflow 內(nèi)存泄露問(wèn)題
相關(guān)文章
Python 中Django驗(yàn)證碼功能的實(shí)現(xiàn)代碼
驗(yàn)證碼是一種區(qū)分用戶是計(jì)算機(jī)還是人的公共全自動(dòng)程序,很多用戶登錄和注冊(cè)系統(tǒng)都提供了圖形驗(yàn)證碼功能。這篇文章主要介紹了Python 中Django驗(yàn)證碼功能的實(shí)現(xiàn)代碼,需要的朋友可以參考下2019-06-06
Python使用pydub實(shí)現(xiàn)M4A轉(zhuǎn)MP3轉(zhuǎn)換器
這篇文章主要介紹了如何使用?wxPython?創(chuàng)建一個(gè)圖形用戶界面(GUI)應(yīng)用程序,能夠?qū)?.m4a?文件轉(zhuǎn)換為?.mp3?文件,感興趣的可以了解下2024-11-11
PyTorch中torch.manual_seed()的用法實(shí)例詳解
在Pytorch中可以通過(guò)相關(guān)隨機(jī)數(shù)來(lái)生成張量,并且可以指定生成隨機(jī)數(shù)的分布函數(shù)等,下面這篇文章主要給大家介紹了關(guān)于PyTorch中torch.manual_seed()用法的相關(guān)資料,需要的朋友可以參考下2022-06-06
Python實(shí)現(xiàn)圖片格式轉(zhuǎn)換
經(jīng)常會(huì)遇到圖片格式需要轉(zhuǎn)換的情況,這篇文章主要為大家詳細(xì)介紹了Python實(shí)現(xiàn)圖片格式轉(zhuǎn)換,文中示例代碼介紹的非常詳細(xì)、實(shí)用,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-08-08
Python實(shí)現(xiàn)透明數(shù)字時(shí)鐘效果
這篇文章主要為大家詳細(xì)介紹了一個(gè)使用 Python 和 Tkinter 庫(kù)實(shí)現(xiàn)的透明數(shù)字時(shí)鐘應(yīng)用,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以了解一下2025-02-02
全面了解Python的getattr(),setattr(),delattr(),hasattr()
下面小編就為大家?guī)?lái)一篇全面了解Python的getattr(),setattr(),delattr(),hasattr()。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-06-06

