human
Complete this python program:
def freeze_variables():
assistant
#Here is the Python code you requested.

    """Return a context, where all trainable variables (reused or not) returned by
    ``get_variable`` will have no gradients (they will be wrapped by ``tf.stop_gradient``).
    But they will still be in ``TRAINABLE_VARIABLES`` collections so they will get
    saved correctly. This is useful to fix certain variables for fine-tuning.
    Example:
    .. code-block:: python
    with varreplace.freeze_variable():
    x = FullyConnected(\fc\, x, 1000)   # fc/* will not be trained
    """
    def custom_getter(getter, *args, **kwargs):
        v = getter(*args, **kwargs)
        if kwargs.pop('trainable', True):
            v = tf.stop_gradient(v)
        return v
    return custom_getter_scope(custom_getter)