# draugr.torch_utilities.optimisation.debugging.layer_fetching.IntermediateLayerGetter

class draugr.torch_utilities.optimisation.debugging.layer_fetching.IntermediateLayerGetter(model: Module, return_layers: Optional [ dict ] = None)

  Bases: `object`

  description

  __init__(model: Module, return_layers: Optional [ dict ] = None)

    Wraps a Pytorch module to get intermediate values, eg for getting intermediate activations

    Arguments: model {nn.module} – The Pytorch module to call return_layers {dict} – Dictionary with the selected submodules to return the output (format: {[current_module_name]: [desired_output_name]}, current_module_name can be a nested submodule, e.g. submodule1.submodule2.submodule3)

    Returns: (mid_outputs {OrderedDict}, model_output {any}) – mid_outputs keys are your desired_output_name (s) and their values are the returned tensors of those submodules (OrderedDict([(desired_output_name,tensor(…)), …).

    In case a submodule is called more than one time, all it’s outputs are stored in a list.

  Methods

  `__init__`(model[, return_layers]) | Wraps a Pytorch module to get intermediate values, eg for getting intermediate activations
  `reduce_getattr`(obj, attr, *args) | # using wonder's beautiful simplification: https://stackoverflow.com/questions/31174295/getattr-and-setattr-on-nested-objects/31174427?noredirect=1#comment86638618_31174427

  static reduce_getattr(obj, attr, *args)

    # using wonder’s beautiful simplification: https://stackoverflow.com/questions/31174295/getattr-and-setattr-on-nested-objects/31174427?noredirect=1#comment86638618_31174427

    Parameters

      - obj –

      - attr –

      - args –

    Returns

    Return type