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
  • 相关阅读:
    62 ip与int类型的转换
    60再谈指针
    59任由制转换
    58进制转换工具
    吉哥工作
    apple
    找第一个非0元素的位置
    若干个数据之和 不考虑溢出
    汇编程序w=x*y+z-200
    4位bcd数转换为2进制数
  • 原文地址:https://www.cnblogs.com/weizhen/p/8451473.html
Copyright © 2011-2022 走看看