l1
get_l1_reg(model, device='cuda')
Calculate the L1 regularization loss for a given model.
This function computes the L1 regularization loss by summing the absolute values of the weights of all Linear and Convolutional layers in the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
Module
|
The neural network model to regularize. IMPORTANT: Don't pass the bounded model here. |
required |
device
|
str
|
The device to perform the computation on. Default is 'cuda'. |
'cuda'
|
Returns:
Type | Description |
---|---|
Tensor
|
The L1 regularization loss. |
Source code in CTRAIN/train/certified/regularisers/l1.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
|