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

    一、变量

    • 为了训练模型,需要能够修改图以调节一些对象,比如权重值、偏置量。简单来说,变 量让你能够给图添加可训练的参数,它们在创建时候就带有类型属性和初始值。

    二、实例

    import os
    os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
    import tensorflow as tf 
    x = tf.constant([10,20,30,40])
    # 定义变量
    y = tf.Variable(initial_value=x*20+10)
    # 修改命令空间
    with tf.variable_scope('my_scope'):  
        Z = tf.Variable(initial_value=100)
    print('x:',x)
    print('y:',y)
    print('Z:',Z)
    # 初始化变量
    model = tf.global_variables_initializer()
    # 开启会话
    with tf.Session() as sess:
        # 运行初始化变量
        sess.run(model)
        y_value = sess.run(y)
        print('y_value:',y_value)
        Z_value = sess.run(Z)
        print('Z_value:',Z_value)
    

    三、结果

    正是江南好风景
  • 相关阅读:
    L1和L2正则
    Python基础(一)
    消息分发
    StringList 自定义快速排序
    Delphi Length函数
    接口的委托实现(通过接口)
    接口委托实现--通过类的对象
    排序
    Socket编程(摘抄)
    Delphi线程同步
  • 原文地址:https://www.cnblogs.com/monsterhy123/p/13088529.html
Copyright © 2011-2022 走看看