WithSavedActivations

class torchelie.nn.WithSavedActivations(model, types=(<class 'torch.nn.modules.conv.Conv2d'>, <class 'torch.nn.modules.linear.Linear'>), names=None)

Hook model in order to get intermediate activations. The activations to save can be either specified by module type or layer name.

forward(input, detach: bool)

Call self.model(input).

Parameters
  • input – input to the model

  • detach (bool) – if True, intermediate activations will be :code:`.detach()`d.

Returns

model output, a name => activation dict with saved intermediate activations.

set_keep_layers(types=(<class 'torch.nn.modules.conv.Conv2d'>, <class 'torch.nn.modules.linear.Linear'>), names=None)
training: bool