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. (转)Hadoop Combiner

    转自:http://blog.csdn.net/jokes000/article/details/7072963 众所周知,Hadoop框架使用Mapper将数据处理成一个<key,value& ...

  2. Python之旅第四天(列表、元祖、字典和习题)

    第四天,感觉时间还是过得很快,今天内容确实有点多,关于list的方法实在是太多了,元组tuple感觉有点鸡肋,可能得到后面才知道他的作用吧,然后是字典,看了很多关于字典的介绍,但是这货到底是干啥用的一 ...

  3. 【AHOI2005】约数研究

    发现luogu的UI改版后AC以后不能给题目评定难度了…… P1403 [AHOI2005]约数研究 类似素数筛的一道题,不过是约数. 先顺手写了个暴力做法,TLE定了~ #include<bi ...

  4. mysql update某个字段替换成某个值

    UPDATE xc_admin_vehicle SET brandid= REPLACE(brandid, 19, 54) UPDATE xc_admin_models SET bid= REPLAC ...

  5. python之路面向对象2

    一.利用反射查看面向对象成员的归属 二.利用反射导入模块.查找类.创建对象.查找对象中的字段 三.静态字段 静态字段存在类中,把对象每个都有的存在类中就行了,只存一份 四.静态方法 静态方法中没有se ...

  6. bootstrap联动校验(转载)

    接触bootstrapvalidator时间不久,最近需要多个字段共同验证,网上查了一下未找到,查阅api文档,发现确实可以实现. 先看dom <div class="form-gro ...

  7. PHP SDK+Oss 上传文件流

    // Endpoint以杭州为例,其它Region请按实际情况填写. $endpoint = "http://oss-cn-hangzhou.aliyuncs.com"; // 云 ...

  8. Iris配置

    package main import ( "github.com/kataras/iris" "os" "encoding/json" & ...

  9. [AGC027C]ABland Yard

    Description AGC027C 给定一张图,点有标号A或B,计算是否对于任意的一个由AB构成的字符串都在图中有对应的路径. Solution 观察可以发现,如果有个环(不一定是简单环)是AAB ...

  10. 转:为什么说Java中只有值传递

    原文:https://www.cnblogs.com/wchxj/p/8729503.html 错误理解 在开始深入讲解之前,有必要纠正一下大家以前的那些错误看法了.如果你有以下想法,那么你有必要好好 ...