对比tensorflow查看打印输出张量Tensor的两种方法(急切执行tf.enable_eager_execution()和tf.Session.run())
生活随笔
收集整理的這篇文章主要介紹了
对比tensorflow查看打印输出张量Tensor的两种方法(急切执行tf.enable_eager_execution()和tf.Session.run())
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
第一種:tf.enable_eager_execution()
# -*- coding: utf-8 -*- """ @File : 111.py @Time : 2020/2/12 15:06 @Author : Dontla @Email : sxana@qq.com @Software: PyCharm """ import tensorflow as tftf.enable_eager_execution() x = tf.constant([[1, 2], [3, 4]]) print(x)結果:
tf.Tensor( [[1 2][3 4]], shape=(2, 2), dtype=int32)第二種:tf.Session.run()
# -*- coding: utf-8 -*- """ @File : 222.py @Time : 2020/2/12 15:12 @Author : Dontla @Email : sxana@qq.com @Software: PyCharm """ import tensorflow as tfx = tf.constant([[1, 2], [3, 4]]) # print(x) # Tensor("Const:0", shape=(2, 2), dtype=int32)with tf.Session() as sess:print(sess.run(x))print(type(sess.run(x)))結果:
[[1 2][3 4]]<class 'numpy.ndarray'>參考文章1:tensorflow tf.enable_eager_execution()(立即執行操作,不添加到稍后在“ tf.Session”中執行的圖)
參考文章2:python tensorflow tf.Session().run()函數(運行操作并評估“fetches”中的張量)
總結
以上是生活随笔為你收集整理的对比tensorflow查看打印输出张量Tensor的两种方法(急切执行tf.enable_eager_execution()和tf.Session.run())的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: PEP Python Enhanceme
- 下一篇: 利用最小二乘法,用直线拟合点时,为什么计