@@ -31,11 +31,13 @@ Then it is a good time to open an issue.
## How to freeze some variables in training
1.You can simply use `tf.stop_gradient` in your model code in some situations (e.g. to freeze first several layers).
1.Learn `tf.stop_gradient`. You can simply use `tf.stop_gradient` in your model code in many situations (e.g. to freeze first several layers).
2.[varreplace.freeze_variables](../modules/tfutils.html#tensorpack.tfutils.varreplace.freeze_variables) can wrap some variables with `tf.stop_gradient`.
2.[varreplace.freeze_variables](../modules/tfutils.html#tensorpack.tfutils.varreplace.freeze_variables) returns a context where variables are freezed.
Learn to use the `custom_getter` argument of `tf.variable_scope` to gain more control over what & how variables are freezed.
3.[ScaleGradient](../modules/tfutils.html#tensorpack.tfutils.gradproc.ScaleGradient) can be used to set the gradients of some variables to 0.
But it may be slow, since variables still have gradients.
Note that the above methods only prevent variables being updated by SGD.