这里是TensorFlow中文社区的一个小例子:
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> print sess.run(hello)
Hello, TensorFlow!
>>> a = tf.constant(10)
>>> b = tf.constant(32)
>>> print sess.run(a+b)
42
>>>
在自己搭建的环境上运行,出现很多的错误
1.SyntaxError: invalid syntax;语法错误,主要是由于print sess.run(a+b)这句代码有问题,最后进行改写print(),这个错误排除了
2.又出现了2020-02-01 10:01:40.033038: I tensorflow/core/platformu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
这里加入
import os
os.environ["TF_CPP_MIN_LOG_LEVEL"]='2'
解决了错误。
注:TF_CPP_MIN_LOG_LEVEL默认值为 0 (显示所有logs),设置为 1 隐藏 INF