import tensorflow as tf

g1 = 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 tf

a = tf.constant([1.0, 2.0], name="a")
b = tf.constant([2.0, 3.0], name="b")
result = a + b
print result sess = 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)

吴裕雄 python 神经网络——TensorFlow 图、张量及会话的更多相关文章

  1. 吴裕雄 python 神经网络——TensorFlow 循环神经网络处理MNIST手写数字数据集

    #加载TF并导入数据集 import tensorflow as tf from tensorflow.contrib import rnn from tensorflow.examples.tuto ...

  2. 吴裕雄 python 神经网络——TensorFlow 训练过程的可视化 TensorBoard的应用

    #训练过程的可视化 ,TensorBoard的应用 #导入模块并下载数据集 import tensorflow as tf from tensorflow.examples.tutorials.mni ...

  3. 吴裕雄 python 神经网络——TensorFlow 使用卷积神经网络训练和预测MNIST手写数据集

    import tensorflow as tf import numpy as np from tensorflow.examples.tutorials.mnist import input_dat ...

  4. 吴裕雄 python 神经网络——TensorFlow实现搭建基础神经网络

    import numpy as np import tensorflow as tf import matplotlib.pyplot as plt def add_layer(inputs, in_ ...

  5. 吴裕雄 python 神经网络——TensorFlow图片预处理调整图片

    import numpy as np import tensorflow as tf import matplotlib.pyplot as plt def distort_color(image, ...

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

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

  7. 吴裕雄 python 神经网络——TensorFlow pb文件保存方法

    import tensorflow as tf from tensorflow.python.framework import graph_util v1 = tf.Variable(tf.const ...

  8. 吴裕雄 python 神经网络——TensorFlow ckpt文件保存方法

    import tensorflow as tf v1 = tf.Variable(tf.random_normal([1], stddev=1, seed=1)) v2 = tf.Variable(t ...

  9. 吴裕雄 python 神经网络——TensorFlow 数据集高层操作

    import tempfile import tensorflow as tf train_files = tf.train.match_filenames_once("E:\\output ...

随机推荐

  1. 虫师自动化测试robot Framework 框架的学习2

    循环的使用 1.in range和in的区别 输出结果 如果把上面的换成in range 会报错 未被定义,说明in range 后面使用的数据类型有限制,对比下,可以看出,in 可用在列表类型数据类 ...

  2. Codeforces Round #623 (Div. 1, based on VK Cup 2019-2020 - Elimination Round, Engine)A(模拟,并查集)

    #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; pair<]; bool cmp( ...

  3. 【HTML】iframe嵌套界面自适应,可高度自由收缩

    最近在做网页时需要使iframe高度自适应,以提高用户体验,网上找了挺多都很复杂,最后找到了这个 HTML: <div class="main_page"> <i ...

  4. ASP.NET Razor 语法

    主要的 Razor C# 语法规则 Razor 代码块包含在 @{ ... } 中 内联表达式(变量和函数)以 @ 开头 代码语句用分号结束 变量使用 var 关键字声明 字符串用引号括起来 C# 代 ...

  5. Leetcode找三个数字的和满足xx条件的题目总结15➕16➕259

    双指针最基础的题目是一个区间里找两个数字的和等于Target.首先将区间从小到大排序.接下来只要一个le指针,一个ri指针,分别从区间左右边界往中间推进即可.复杂度是排序的nlogn. 下面几道题都是 ...

  6. Quartus ii 初学遇到的问题以及解决

    第一次下载和运行Quartus后,发现几个问题: 下载时安装易出现问题. 解决:在官网下载后,在开始破解: 运行程序出现警告:RTL波形时出现问题? 解决:testbench程序出错. 问题3:在视频 ...

  7. 第四十一篇 入门机器学习——Numpy的基本操作——聚合操作

    No.1. 对向量元素求和使用np.sum,也可以使用类似big_array.sum()的方式 No.2. 对向量元素求最小值使用np.min,求最大值使用np.max,也可以使用类似big_arra ...

  8. 2.10 webdriver中 js 使用

    来源: 使用Webdriver执行JS小结  http://lijingshou.iteye.com/blog/2018929 selenium常用的js总结  http://www.cnblogs. ...

  9. pycharm通过unittest框架批量执行Python脚本用例

    1.如下图点击进入配置页 2.新增一个配置,“2”标签选择要执行的脚本的目录或者脚本文件,“3”标签选择要执行的脚本的目录

  10. testng如何实现用例间依赖

    todo: 参考: https://www.cnblogs.com/znicy/p/6534893.html