MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / get_gradients

Method get_gradients

tensorflow/python/keras/optimizers.py:77–105  ·  view source on GitHub ↗

Returns gradients of `loss` with respect to `params`. Arguments: loss: Loss tensor. params: List of variables. Returns: List of gradient tensors. Raises: ValueError: In case any gradient cannot be computed (e.g. if gradient function not implem

(self, loss, params)

Source from the content-addressed store, hash-verified

75 raise NotImplementedError
76
77 def get_gradients(self, loss, params):
78 """Returns gradients of `loss` with respect to `params`.
79
80 Arguments:
81 loss: Loss tensor.
82 params: List of variables.
83
84 Returns:
85 List of gradient tensors.
86
87 Raises:
88 ValueError: In case any gradient cannot be computed (e.g. if gradient
89 function not implemented).
90 """
91 grads = K.gradients(loss, params)
92 if None in grads:
93 raise ValueError('An operation has `None` for gradient. '
94 'Please make sure that all of your ops have a '
95 'gradient defined (i.e. are differentiable). '
96 'Common ops without gradient: '
97 'K.argmax, K.round, K.eval.')
98 if hasattr(self, 'clipnorm'):
99 grads = [clip_ops.clip_by_norm(g, self.clipnorm) for g in grads]
100 if hasattr(self, 'clipvalue'):
101 grads = [
102 clip_ops.clip_by_value(g, -self.clipvalue, self.clipvalue)
103 for g in grads
104 ]
105 return grads
106
107 def set_weights(self, weights):
108 """Sets the weights of the optimizer, from Numpy arrays.

Callers 8

_make_histogram_opsMethod · 0.45
get_updatesMethod · 0.45
get_updatesMethod · 0.45
get_updatesMethod · 0.45
get_updatesMethod · 0.45
get_updatesMethod · 0.45
get_updatesMethod · 0.45
get_updatesMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected