MCPcopy Create free account
hub / github.com/tflearn/tflearn / add_weights_regularizer

Function add_weights_regularizer

tflearn/helpers/regularizer.py:13–41  ·  view source on GitHub ↗

add_weights_regularizer. Add a weights regularizer to the provided Tensor Arguments: variable: `Variable`. Tensor to add regularization. loss: `str`. Regularization mode. weight_decay: `float`. Decay to use for regularization. add_to_collection: `str`. Add

(variable, loss="L2", weight_decay=0.001,
                            add_to_collection=None)

Source from the content-addressed store, hash-verified

11
12
13def add_weights_regularizer(variable, loss="L2", weight_decay=0.001,
14 add_to_collection=None):
15 """ add_weights_regularizer.
16
17 Add a weights regularizer to the provided Tensor
18
19 Arguments:
20 variable: `Variable`. Tensor to add regularization.
21 loss: `str`. Regularization mode.
22 weight_decay: `float`. Decay to use for regularization.
23 add_to_collection: `str`. Add the regularization loss to the
24 specified collection. Default: tf.GraphKeys.REGULARIZATION_LOSSES.
25
26 Returns:
27 `tf.Tensor`. The weight regularizer.
28
29 """
30 if not add_to_collection:
31 add_to_collection = tf.GraphKeys.REGULARIZATION_LOSSES
32 if isinstance(loss, str):
33 regul = regularizers.get(loss)
34 weights_regularizer = regul(variable, weight_decay)
35 elif loss and callable(loss):
36 weights_regularizer = loss(variable)
37 else:
38 weights_regularizer = loss
39 if add_to_collection:
40 tf.add_to_collection(add_to_collection, weights_regularizer)
41 return weights_regularizer
42
43
44def add_activation_regularizer(op, loss="L2", activ_decay=0.001,

Callers

nothing calls this directly

Calls 1

getMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…