(loss,
                          variables,
                          stop_grads,
                          allow_grads_to_batch_norm_vars,
                          learning_rate,
                          get_update_ops=True)
return {'updated_vars': updated_vars, 'update_ops': update_ops}
Returns the updated vars after one step of gradient descent.
Returns the updated vars after one step of gradient descent.
Returns the updated vars after one step of gradient descent .
def gradient_descent_step(loss,
                          variables,
                          stop_grads,
                          allow_grads_to_batch_norm_vars,
                          learning_rate,
                          get_update_ops=True):
  """Returns the updated vars after one step of gradient descent."""
  grads = tf.gradients(loss, variables)

  if stop_grads:
    grads = [tf.stop_gradient(dv) for dv in grads]

  def _apply_grads(variables, grads):
    """Applies gradients using SGD on a list of variables."""
    v_new, update_ops = [], []
    for (v, dv) in zip(variables, grads):
      if (not allow_grads_to_batch_norm_vars and
          ('offset' in v.name or 'scale' in v.name)):
        updated_value = v  # no update.
      else:
        updated_value = v - learning_rate * dv  # gradient descent update.
        if get_update_ops:
          update_ops.append(tf.assign(v, updated_value))
      v_new.append(updated_value)
    return v_new, update_ops

  updated_vars, update_ops = _apply_grads(variables, grads)
  return {'updated_vars': updated_vars, 'update_ops': update_ops}
def gradient_descent_step ( loss , variables , stop_grads , allow_grads_to_batch_norm_vars , learning_rate , get_update_ops = True ) : grads = tf . gradients ( loss , variables ) if stop_grads : grads = [ tf . stop_gradient ( dv ) for dv in grads ] def _apply_grads ( variables , grads ) : """Applies gradients using SGD on a list of variables.""" v_new , update_ops = [ ] , [ ] for ( v , dv ) in zip ( variables , grads ) : if ( not allow_grads_to_batch_norm_vars and ( 'offset' in v . name or 'scale' in v . name ) ) : updated_value = v # no update. else : updated_value = v - learning_rate * dv # gradient descent update. if get_update_ops : update_ops . append ( tf . assign ( v , updated_value ) ) v_new . append ( updated_value ) return v_new , update_ops updated_vars , update_ops = _apply_grads ( variables , grads ) return { 'updated_vars' : updated_vars , 'update_ops' : update_ops }