1. 程式人生 > >Python2/3分別測試TensorFlow第一個程式

Python2/3分別測試TensorFlow第一個程式

搭建完成tensorflow-gpu後,測試 “Hello TensorFlow-GPU!!”

python2與python3的部分區別:python2 str is bytes, but python 3 str is unicode 即在python2的版本中 str 指的是 bytes ,但是python3的 str 指的是 unicode 編碼。

  • python2
import tensorflow as tf
hello = tf.constant("Hello TensorFlow-GPU!!")
sess = tf.Session()
print(sess.run(hello))
  • python3
import tensorflow as tf
hello = tf.constant("Hello TensorFlow-GPU!!")
sess = tf.Session()
print(sess.run(hello).decode())
  • 如此,輸出皆為
Hello TensorFlow-GPU!!