TRAINABLE_VARIABLES和UPDATE_OPS的差别

搜索自stack overflow

These are two different things.

TRAINABLE_VARIABLES

TRAINABLE_VARIABLES is the collection of variables or training parameters which should be modified when minimizing the loss. For example, these can be the weights determining the function performed by each node in the network.

How do variables get added to this collection? This happens automatically when you define a new variable with tf.get_variable, unless you specify

tf.get_variable(..., trainable=False)

  
  

When would you want a variable to be untrainable? This happens from time to time. For example, occasionally you will want to use a two-step approach in which you first train the entire network on a large, generic dataset, then fine-tune the network on a smaller dataset which is specifically related to your problem. In such cases, you might want to fine-tune only part of the network, e.g., the last layer. Specifying some variables as untrainable is one of the ways to do this.

UPDATE_OPS

UPDATE_OPS is a collection of ops (operations performed when the graph runs, like multiplication, ReLU, etc.), not variables. Specifically, this collection maintains a list of ops which need to run after every training step.

How do ops get added to this collection? By definition, update_ops occur outside the regular flow of training by loss minimization, so generally you will be adding ops to this collection only under special circumstances. For example, when performing batch normalization, you want to recompute the batch mean and variance after each training step, and this is how it's done. 

### 回答1: trainable_variables是指可以被训练的变量,通常是神经网络中的权重和偏置。这些变量会在反向传播算法中被更新,以使得模型的输出更加接近于真实值。在深度学习中,trainable_variables是非常重要的概念,因为它们直接影响着模型的性能和训练速度。 ### 回答2: trainable_variables是TensorFlow的一个属性,用于获取所有可训练的变量。在机器学习模型中,可以通过定义变量来存储和更新模型的参数。这些变量通常是需要通过训练数据来进行优化的参数,例如神经网络的权重和偏置项。trainable_variables属性可以方便地获取模型中所有可训练的变量。 当我们定义一个可训练的变量时,可以通过设置trainable参数为True来将其标记为可训练。通过trainable_variables属性,我们可以方便地获取所有被标记为可训练的变量,以便进行参数的优化和更新。 trainable_variables返回的是一个包含可训练变量的列表。每个变量都是TensorFlow中的一个tf.Variable对象,包含了变量的值和其他的属性。通过这个列表,我们可以对每个变量进行操作,例如计算梯度,应用优化算法等。 总之,trainable_variables是TensorFlow提供的一个便利的属性,用于获取模型中所有可训练的变量。通过这个属性,我们可以方便地对模型的参数进行操作和优化,以提高模型的性能和准确性。 ### 回答3: trainable_variables是TensorFlow中一个非常重要的概念,它表示可以被训练的变量。在机器学习和深度学习中,我们通常需要通过训练模型来优化参数,使得模型能够更好地拟合数据。 在TensorFlow中,我们可以使用trainable_variables来获取模型中可以进行训练的变量。这些变量通常是模型中的权重和偏置项,例如神经网络中的权重矩阵和偏置向量。通过调用trainable_variables方法,我们可以获取到这些变量的列表。 trainable_variables返回的是一个Variable列表,这些Variable对象是TensorFlow中的一种数据类型,它可以存储和操作张量。这些变量会被自动收集到默认的全局图中,这样在训练时可以方便地获取到它们的取值和进行更新。 trainable_variables的使用非常简单,我们只需要在定义模型的过程中,将需要进行训练的变量使用tf.Variable定义即可。在训练过程中,我们可以使用trainable_variables方法获取到这些变量,并将其传入优化器进行更新。 总而言之,trainable_variables 是TensorFlow中重要的一个函数,它可以方便地获取到模型中需要进行训练的变量。这对于模型的参数优化以及深度学习任务的理解都是非常关键的。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值