dgs.utils.torchtools.close_specified_layers

dgs.utils.torchtools.close_specified_layers(model: TorchMod | BaseMod, close_layers: str | list[str], open_others: bool = False, verbose: bool = False) None[source]

Close / Freeze the specified layers in the given model for training while keeping all other layers unchanged.

Parameters:
  • model – A torch module or a BaseModule containing a torch module as attribute ‘module’.

  • close_layers – Name or names of the layers to close for evaluation.

  • open_others – Whether to open all layers not present in close_layers.

  • verbose – Whether to print some debugging information.

Raises:

ValueError if a value in close_layers is not an attribute of the model.