_l2_regularization
l2_regularization
¶
Calculate L2 Norm of model weights.
l2_reg = sum(parameter**2)/2
This method can be used with TensorFlow and Pytorch tensors
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
Union[Model, Module]
|
A tensorflow or pytorch model |
required |
beta |
float
|
The multiplicative factor, to weight the l2 regularization loss with the input loss |
0.01
|
Returns:
Type | Description |
---|---|
Tensor
|
The L2 norm of model parameters |
Raises:
Type | Description |
---|---|
ValueError
|
If |