import tensorflow as tfg1 = tf.Graph()
with g1.as_default():v = tf.get_variable("v", [1], initializer = tf.zeros_initializer()) # 设置初始值为0

g2 = tf.Graph()
with g2.as_default():v = tf.get_variable("v", [1], initializer = tf.ones_initializer())  # 设置初始值为1

with tf.Session(graph = g1) as sess:tf.global_variables_initializer().run()with tf.variable_scope("", reuse=True):print(sess.run(tf.get_variable("v")))with tf.Session(graph = g2) as sess:tf.global_variables_initializer().run()with tf.variable_scope("", reuse=True):print(sess.run(tf.get_variable("v")))

import tensorflow as tfa = tf.constant([1.0, 2.0], name="a")
b = tf.constant([2.0, 3.0], name="b")
result = a + b
print resultsess = tf.InteractiveSession ()
print(result.eval())
sess.close()

# 创建一个会话。
sess = tf.Session()# 使用会话得到之前计算的结果。
print(sess.run(result))# 关闭会话使得本次运行中使用到的资源可以被释放。
sess.close()

with tf.Session() as sess:print(sess.run(result))

sess = tf.Session()
with sess.as_default():print(result.eval())

sess = tf.Session()# 下面的两个命令有相同的功能。
print(sess.run(result))
print(result.eval(session=sess))

sess = tf.InteractiveSession ()
print(result.eval())
sess.close()

config=tf.ConfigProto(allow_soft_placement=True, log_device_placement=True)
sess1 = tf.InteractiveSession(config=config)
sess2 = tf.Session(config=config)

转载于:https://www.cnblogs.com/tszr/p/10872464.html

吴裕雄 python 神经网络——TensorFlow 图、张量及会话相关推荐

  1. 吴裕雄 python 神经网络——TensorFlow 花瓣分类与迁移学习(1)

    import glob import os.path import numpy as np import tensorflow as tf from tensorflow.python.platfor ...

  2. 吴裕雄 python 神经网络——TensorFlow训练神经网络:不使用隐藏层

    import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_dataINPUT_NODE = 784 # ...

  3. python实现lenet_吴裕雄 python 神经网络TensorFlow实现LeNet模型处理手写数字识别MNIST数据集...

    importtensorflow as tf tf.reset_default_graph()#配置神经网络的参数 INPUT_NODE = 784OUTPUT_NODE= 10IMAGE_SIZE= ...

  4. 吴裕雄 python 神经网络——TensorFlow实现AlexNet模型处理手写数字识别MNIST数据集...

    import tensorflow as tf# 输入数据 from tensorflow.examples.tutorials.mnist import input_datamnist = inpu ...

  5. python识别花草_吴裕雄 python神经网络 花朵图片识别(9)

    import os import numpy as np import matplotlib.pyplot as plt from PIL import Image, ImageChops from ...

  6. python识别花草_吴裕雄 python神经网络 花朵图片识别(10)

    import os import numpy as np import matplotlib.pyplot as plt from PIL import Image, ImageChops from ...

  7. 吴恩达神经网络1-2-2_图神经网络进行药物发现-第1部分

    吴恩达神经网络1-2-2 预测溶解度 (Predicting Solubility) 相关资料 (Related Material) Jupyter Notebook for the article ...

  8. 吴恩达神经网络1-2-2_图神经网络进行药物发现-第2部分

    吴恩达神经网络1-2-2 预测毒性 (Predicting Toxicity) 相关资料 (Related Material) Jupyter Notebook for the article Jup ...

  9. 吴裕雄--天生自然 Tensorflow卷积神经网络:花朵图片识别

    import os import numpy as np import matplotlib.pyplot as plt from PIL import Image, ImageChops from ...

最新文章

  1. Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
  2. 基于 Docker 的 MySQL 导入导出数据
  3. Red Hat Enterprice Linux 5测试 Qt 4.7 Qt Creator(二)
  4. eXpressApp Framework 8.1.5 released on 27 Jue 2008 and What'a New
  5. 黑客是如何入侵电脑的,没有互联网可以入侵电脑吗?
  6. html光圈效果,PS新手教程:特效光圈效果
  7. iOS12系统这5个隐藏小技巧!你一定要知道,好用到停不下来!
  8. c语言 qt 写小游戏,Qt实现Flappy Bird游戏
  9. android朋友圈发文字换行,微信朋友圈全文展开 朋友圈文字怎么换行朋友圈发多行文字...
  10. 播动师,直播广场,一目了然看到直播态势
  11. 华为高姐寄来的新年礼物
  12. error pulling image configuration
  13. C++实现 数字游戏之拼出最大数
  14. BT 面板控制命令 宝塔 Linux 常用命令收集整理
  15. 从语音角度看湖南泸溪方言的归属
  16. 嵌入式linux启动信息完全注释
  17. egret新手引导反向遮罩
  18. 英文歌曲:A place nearby (天堂若比邻)
  19. CentOS7内核参数
  20. 一个正经的前端学习 开源 仓库(阶段十七-440)

热门文章

  1. Codeforces 1181
  2. python使用urllib模块开发的多线程豆瓣小站mp3下载器
  3. 安装phpstudy之后发现80端口被占用
  4. Swift-闭包理解
  5. F#学习之路(3) 如何组织程序(下)
  6. Eclipse-cdt 配合 gdbserver 进行 arm 程序远程调试
  7. Android 4.4.2 动态添加JNI库方法记录 (二 app应用层)
  8. springboot2 虚拟路径设置_转载—springboot配置虚拟路径以外部访问
  9. 什么叫做罗列式_陈列,罗列是什么意思?
  10. php日志导出oracle,一个php导出oracle库的php代码