Python2/3分别测试TensorFlow第一个程序

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Sunny_Future/article/details/84136578

搭建完成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!!

猜你喜欢

转载自blog.csdn.net/Sunny_Future/article/details/84136578