当前位置:主页 > 查看内容

Tensorflow 打印常量hello tensorflow

发布时间:2021-07-25 00:00| 位朋友查看

简介:环境信息 Data Science Workshop Dev ? 打印常量hello tensorflow import tensorflow as tftf.__version__'2.4.0' # 定义常量hello_tf_constant = tf.constant("hello,tensorflow") # 版本不兼容,无法直接运行with tf.Session() as sess: sess.run(hello_tf……
环境信息

Data Science Workshop Dev

?

打印常量hello tensorflow
import tensorflow as tf
tf.__version__
'2.4.0'
# 定义常量
hello_tf_constant = tf.constant("hello,tensorflow")
# 版本不兼容,无法直接运行
with tf.Session() as sess:
 sess.run(hello_tf_constant)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
 ipython-input-3-4eb9d4d3287a in module 
---- 1 with tf.Session() as sess:
 2 sess.run(hello_tf_constant)
AttributeError: module 'tensorflow' has no attribute 'Session' 
with tf.compat.v1.Session() as sess:
 sess.run(hello_tf_constant)
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
 ipython-input-4-420f364e899d in module 
 1 with tf.compat.v1.Session() as sess:
---- 2 sess.run(hello_tf_constant)
/opt/conda/lib/python3.6/site-packages/tensorflow/python/client/session.py in run(self, fetches, feed_dict, options, run_metadata)
 966 try:
 967 result = self._run(None, fetches, feed_dict, options_ptr,
-- 968 run_metadata_ptr)
 969 if run_metadata:
 970 proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)
/opt/conda/lib/python3.6/site-packages/tensorflow/python/client/session.py in _run(self, handle, fetches, feed_dict, options, run_metadata)
 1114 raise RuntimeError('Attempted to use a closed Session.')
 1115 if self.graph.version == 0:
- 1116 raise RuntimeError('The Session graph is empty. Add operations to the '
 1117 'graph before calling run().')
 1118 
RuntimeError: The Session graph is empty. Add operations to the graph before calling run(). 
tf.compat.v1.disable_eager_execution()
with tf.compat.v1.Session() as sess:
 sess.run(hello_tf_constant)
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
 ipython-input-5-95efe77ef2e2 in module 
 1 tf.compat.v1.disable_eager_execution()
 2 with tf.compat.v1.Session() as sess:
---- 3 sess.run(hello_tf_constant)
/opt/conda/lib/python3.6/site-packages/tensorflow/python/client/session.py in run(self, fetches, feed_dict, options, run_metadata)
 966 try:
 967 result = self._run(None, fetches, feed_dict, options_ptr,
-- 968 run_metadata_ptr)
 969 if run_metadata:
 970 proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)
/opt/conda/lib/python3.6/site-packages/tensorflow/python/client/session.py in _run(self, handle, fetches, feed_dict, options, run_metadata)
 1114 raise RuntimeError('Attempted to use a closed Session.')
 1115 if self.graph.version == 0:
- 1116 raise RuntimeError('The Session graph is empty. Add operations to the '
 1117 'graph before calling run().')
 1118 
RuntimeError: The Session graph is empty. Add operations to the graph before calling run().
tf.compat.v1.disable_eager_execution()
hello_tf_constant = tf.constant("hello,tensorflow")
with tf.compat.v1.Session() as sess:
 print(sess.run(hello_tf_constant))
b'hello,tensorflow'

?

参考链接RuntimeError: The Session graph is empty. Add operations to the graph before calling run().解决方法AttributeError: module 'tensorflow' has no attribute 'Session'错误解决tensorflow 无法执行sess =tf .Session ()

?

相关链接阿里云人工智能助理工程师认证(ACA)阿里云 天池

?

备注

工匠精神,精益求精,踏实学习,再接再厉 O(∩_∩)O
欢迎各位同学一起来交流学习心得!


本文转自网络,原文链接:https://developer.aliyun.com/article/785726
本站部分内容转载于网络,版权归原作者所有,转载之目的在于传播更多优秀技术内容,如有侵权请联系QQ/微信:153890879删除,谢谢!
上一篇:Tensorflow 简单数据流图程序 下一篇:没有了

推荐图文


随机推荐