braindecode.visualization.cascading_layer_reset#

braindecode.visualization.cascading_layer_reset(model, deepcopy_first=True)[source]#

Yield model copies with progressively-randomized parameters.

Walks the modules in reverse depth-first order (output → input) and yields (layer_name, model_copy) after each layer’s reset_parameters call. Implements the cascading-randomization sanity check from Adebayo et al. (NeurIPS 2018), as applied to EEG decoders in Sujatha Ravindran & Contreras-Vidal (Sci Rep 2023). An attribution method whose maps survive every cascade level is suspicious — its output likely depends on architecture rather than on learned weights.

Parameters:
  • model (torch.nn.Module) – Trained model. The original model is not modified when deepcopy_first=True (default).

  • deepcopy_first (bool) – If True, deep-copy the model before mutating, so the caller’s model stays trained. Set False to skip the copy when memory is tight and the caller doesn’t need the trained weights again.

Yields:
  • layer_name (str) – Dotted-path name of the layer just reset (e.g. "final_layer.conv_classifier").

  • randomized_model (torch.nn.Module) – A model whose layers from this one back to the output are randomly re-initialized.

Examples using braindecode.visualization.cascading_layer_reset#

Interpretability of EEG Decoders

Interpretability of EEG Decoders