Tensorflow 打印常量hello tensorflow

简介: Data Science Workshop Dev - Tensorflow - 2.X - 打印常量hello tensorflow

环境信息

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'

参考链接

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

相关链接

备注

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

目录
相关文章
|
TensorFlow 算法框架/工具
|
机器学习/深度学习 TensorFlow 算法框架/工具
【深度学习笔记】(二)Hello, Tensorflow!
【深度学习笔记】(二)Hello, Tensorflow! 一、安装 官方安装的方式很多种,本文采用Docker方式。Docker的深入使用文案很长很多,但我们都不需要,我们的主要目的还是Tensorflow,所以只需要基本的使用即可。
2486 0
|
TensorFlow 算法框架/工具
最简单的 TensorFlow 代码,TensorFlow Hello World 。
# -*- coding:utf-8 -*- from __future__ import print_function ''' HelloWorld example using TensorFlow library.
983 0
|
机器学习/深度学习 人工智能 算法
猫狗宠物识别系统Python+TensorFlow+人工智能+深度学习+卷积网络算法
宠物识别系统使用Python和TensorFlow搭建卷积神经网络,基于37种常见猫狗数据集训练高精度模型,并保存为h5格式。通过Django框架搭建Web平台,用户上传宠物图片即可识别其名称,提供便捷的宠物识别服务。
1287 55
|
机器学习/深度学习 人工智能 算法
鸟类识别系统Python+卷积神经网络算法+深度学习+人工智能+TensorFlow+ResNet50算法模型+图像识别
鸟类识别系统。本系统采用Python作为主要开发语言,通过使用加利福利亚大学开源的200种鸟类图像作为数据集。使用TensorFlow搭建ResNet50卷积神经网络算法模型,然后进行模型的迭代训练,得到一个识别精度较高的模型,然后在保存为本地的H5格式文件。在使用Django开发Web网页端操作界面,实现用户上传一张鸟类图像,识别其名称。
778 12
鸟类识别系统Python+卷积神经网络算法+深度学习+人工智能+TensorFlow+ResNet50算法模型+图像识别
|
机器学习/深度学习 数据采集 数据可视化
TensorFlow,一款由谷歌开发的开源深度学习框架,详细讲解了使用 TensorFlow 构建深度学习模型的步骤
本文介绍了 TensorFlow,一款由谷歌开发的开源深度学习框架,详细讲解了使用 TensorFlow 构建深度学习模型的步骤,包括数据准备、模型定义、损失函数与优化器选择、模型训练与评估、模型保存与部署,并展示了构建全连接神经网络的具体示例。此外,还探讨了 TensorFlow 的高级特性,如自动微分、模型可视化和分布式训练,以及其在未来的发展前景。
1124 5
|
机器学习/深度学习 人工智能 TensorFlow
基于TensorFlow的深度学习模型训练与优化实战
基于TensorFlow的深度学习模型训练与优化实战
721 3
|
机器学习/深度学习 人工智能 算法
基于Python深度学习的【垃圾识别系统】实现~TensorFlow+人工智能+算法网络
垃圾识别分类系统。本系统采用Python作为主要编程语言,通过收集了5种常见的垃圾数据集('塑料', '玻璃', '纸张', '纸板', '金属'),然后基于TensorFlow搭建卷积神经网络算法模型,通过对图像数据集进行多轮迭代训练,最后得到一个识别精度较高的模型文件。然后使用Django搭建Web网页端可视化操作界面,实现用户在网页端上传一张垃圾图片识别其名称。
614 0
基于Python深度学习的【垃圾识别系统】实现~TensorFlow+人工智能+算法网络
|
机器学习/深度学习 人工智能 算法
【手写数字识别】Python+深度学习+机器学习+人工智能+TensorFlow+算法模型
手写数字识别系统,使用Python作为主要开发语言,基于深度学习TensorFlow框架,搭建卷积神经网络算法。并通过对数据集进行训练,最后得到一个识别精度较高的模型。并基于Flask框架,开发网页端操作平台,实现用户上传一张图片识别其名称。
763 0
【手写数字识别】Python+深度学习+机器学习+人工智能+TensorFlow+算法模型
下一篇
开通oss服务