zoukankan      html  css  js  c++  java
  • 115、TensorFlow变量的使用

    # To use the value of a tf.Variable in a Tesnorflow graph , simply treat it like a normal tf.Tensor
    import  tensorflow as tf
    v = tf.get_variable("v", shape=(), initializer=tf.zeros_initializer())
    w = v + 1  # w is a tf.Tensor which is computed based on the value of v
    # Any time a variable is used in an expression it gets automatically
    # converted to a tf.Tensor representing its value
    # To assign a value to a variable , use the methods assign , assign_add
    # and friends in the tf.Variable class . For example 
    v1 = tf.get_variable("v1", shape=(), initializer=tf.zeros_initializer())
    assignment = v1.assign_add(1)
    with tf.Session() as sess:
        tf.global_variables_initializer().run()
        print(sess.run(assignment))

    下面是输出的结果

    2018-02-17 10:55:36.215165: I C:	f_jenkinsworkspace
    el-winMwindowsPY35	ensorflowcoreplatformcpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2
    1.0
  • 相关阅读:
    编译使用luasocket
    使用openssl的一些问题
    c++调用lua注册的带参数的回调
    合服
    windows防火墙命令
    mac os .xip格式解压
    Get GPU Data Method
    Unity编译Mono
    Unity Mono运行机制分析及内存优化
    unity5 AssetBundleBuild用法
  • 原文地址:https://www.cnblogs.com/weizhen/p/8451473.html
Copyright © 2011-2022 走看看