convert_layers
convert_layers
¶
convert_layers
¶
Recursively convert layers of a specific type in the model to a new type, in-place.
For GroupNorm conversion, num_groups is automatically computed as num_channels // 16 with fallback to ensure divisibility. Args: model: The model to modify in-place. layer_type_old: The type of layer to replace (e.g., nn.BatchNorm2d). layer_type_new: The type of layer to replace with (e.g., nn.GroupNorm). convert_weights: If True, copy weights and biases from old to new layers.
Returns:
| Type | Description |
|---|---|
Module
|
The modified model with layers converted. |
Source code in src/versatil/models/layers/convert_layers.py
replace_batchnorm_with_groupnorm
¶
Replace all kinds of _BatchNorm layers (including SyncBatchNorm) in the model with GroupNorm layers.
Note: The number of groups for GroupNorm will be computed automatically as num_channels // 16.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Module
|
The model to modify |
required |
Returns:
| Type | Description |
|---|---|
Module
|
The modified model with |