TensorFlow: Printing variables in memory

Source: Internet
Author: User
Law One:

Cycle Print Templates

for (x, y) in Zip (Tf.global_variables (), Sess.run (Tf.global_variables ())):
    print ' \ n ', X, y
Example
# 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_coll Ections=none) return bn def Main (): with TF. Graph (). As_default (): # input_x input_x = Tf.placeholder (Dtype=tf.float32, Shape=[1, 4, 4, 1]) imp ORT NumPy as NP i_p = Np.random.uniform (low=0, high=255, Size=[1, 4, 4, 1]) # outputs output = Fun C (input_x, ' my ', is_training=true) with TF. Session () as Sess:sess.run (Tf.global_variables_initializer ()) t = sess.run (output, FEED_DICT={INP
                Ut_x:i_p}) # method one: Loop print 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
Law II:

Specify the variable name print template

print ' my/batchnorm/beta:0 ', (Sess.run (' my/batchnorm/beta:0 '))
Example
# 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_coll Ections=none) return bn def Main (): with TF. Graph (). As_default (): # input_x input_x = Tf.placeholder (Dtype=tf.float32, Shape=[1, 4, 4, 1]) imp ORT NumPy as NP i_p = Np.random.uniform (low=0, high=255, Size=[1, 4, 4, 1]) # outputs output = Fun C (input_x, ' my ', is_training=true) with TF. Session () as Sess:sess.run (Tf.global_variables_initializer ()) t = sess.run (output, FEED_DICT={INP
            Ut_x:i_p}) # method Two: Specify Variable name 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/B
 Atchnorm/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 cap ability: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 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.