zoukankan      html  css  js  c++  java
  • 113、TensorFlow变量集合

    #一个tensorflow程序断开的部分可能要创建变量
    # 如果有一种方法来访问所有的变量是非常有用的
    #因为这个原因TensorFlow提供了集合,是一些张量的集合
    #或者是其他的对象,就像tf.Variable 实例一样
    # 默认情况下 tf.Variable 对象被放置在下面的两个集合中
    # tf.GraphKeys.GLOBAL_VARIABLES
    #变量可以在多个设备之间被分享
    # tf.GraphKeys.TRAINABLE_VARIABLES 
    # TensorFlow会自动对上面集中的变量进行计算,列如自动求导
    # 如果你不想让变量被自动训练
    # 可以将它添加到 tf.GraphKeys.LOCAL_VARIABLES集合中
    # 下面的代码块解释了如何将my_local变量添加到这个集合中
    import tensorflow as tf
    
    my_local = tf.get_variable("my_local", shape=(), collections=[tf.GraphKeys.LOCAL_VARIABLES])
    # Alternatively you can specify trainable=False as an argument to tf.get_variable
    my_non_trainable = tf.get_variable("my_non_trainable", shape=(), trainable=False)
    #You can also use your own collections, any string is a valid collection name
    tf.add_to_collection("my_collection_name",my_local)
    #And to retrieve a list of all the variables (or other objects) you've placed in a collection you can use
    tf.get_collection("my_collection_name")
  • 相关阅读:
    5.9编程练习
    linux下查看torch版本和cuda版本
    4.13编程练习
    C++ Primer Plus-3.7编程练习-第2题和第5题
    More on vim tips
    Method Calling in Perl
    换零钱 动态规划解法 C语言描述
    海伦平方根算法(LISP描述)
    expect 实现模拟交互
    tmux 入门
  • 原文地址:https://www.cnblogs.com/weizhen/p/8451469.html
Copyright © 2011-2022 走看看