国外平面设计网站大全,域名向谁申请,公司网站客户案例,互联网运营自学课程目录 版本问题Tensorflow 1.xx的测试代码#xff1a;Tensorflow 2.xx的测试代码#xff1a;Tensorflow 2.6版本实际的测验结果 总结 版本问题
查询资料发现#xff0c;多数检验Tensorflow是否安装成功的方法#xff0c;多数方法都是1.xx版本的#xff0c;直接使用1.xx版本… 目录 版本问题Tensorflow 1.xx的测试代码Tensorflow 2.xx的测试代码Tensorflow 2.6版本实际的测验结果 总结 版本问题
查询资料发现多数检验Tensorflow是否安装成功的方法多数方法都是1.xx版本的直接使用1.xx版本的测是代码还会报一下错误
AttributeError: module tensorflow has no attribute Session之所以出现该问题是因为tf.Session()是tensorflow1.X中的代码所以得修改一下代码。
Tensorflow 1.xx的测试代码
import tensorflow as tf # 导入TensorFlow模块,并缩写为tf
hello tf.constant(‘Hello, TensorFlow!’) #使用TensorFlow的constant方法创建一个字符串Tensor,其值为Hello, YNNU
sess tf.Session() # 创建一个TensorFlow Session对象,该对象用于启动图,调用图中的op
print(sess.run(hello)) # 调用Session的run方法运行hello op。run方法需要传入要运行的op或者Tensor,这里传入hello Tensor。# sess.run会把hello Tensor运算成一个字符串的值,并返回。Tensorflow 2.xx的测试代码
import tensorflow as tf
tf.compat.v1.disable_eager_execution()
hello tf.constant(Hello,YNNU)
sess tf.compat.v1.Session()
print(sess.run(hello))Tensorflow 2.6版本实际的测验结果
由于我自己安装的是tensorflow 2.6版本这里主要实际演示2.xx版本的实验结果如下
总结
以上就是Linux系统下检验Tensorflow 2.xx版本和1.xx版本是否安装成功学者根据自己的版本对应测试多多支持谢谢