class_docstr: Tool for extracting layers from models.
  
  Args:
      submod (torch.nn.Module): model to extract activations from
      layers (list of functions): list of functions where each function,
          when applied to submod, returns a desired layer. For example, one
          function could be `lambda model: model.layer1`.
  
  Returns:
      A model whose forward function returns the activations from the layers
          corresponding to the functions in `layers` (in the order that the
          functions were passed in the list).
class_docstr_tok: ["Tool","for","extracting","layers","from","models",".","Args",":","submod","(","torch.nn.Module",")",":","model","to","extract","activations","from","layers","(","list","of","functions",")",":","list","of","functions","where","each","function",",","when","applied","to","submod",",","returns","a","desired","layer",".","For","example",",","one","function","could","be","`","lambda","model",":","model.layer1","`",".","Returns",":","A","model","whose","forward","function","returns","the","activations","from","the","layers","corresponding","to","the","functions","in","`","layers","`","(","in","the","order","that","the","functions","were","passed","in","the","list",")","."]
code: def __init__(self, submod, layers):
      # layers must be in order
      super(FeatureExtractor, self).__init__()
      self.submod = submod
      self.layers = layers
      self.n = 0
  
      for layer_func in layers:
          layer = layer_func(self.submod)
  
          def hook(module, _, output):
              module.register_buffer("activations", output)
  
          layer.register_forward_hook(hook)
  
file_path: robustness/robustness/model_utils.py
imports: import torch
  from torch import nn
  import dill
  import os
  from .tools import helpers, constants
  from .attacker import AttackerModel
label_desc: Use image node_id 1 to create a new FeatureExtractor object from inherited base classes: ch.nn with example: obj = FeatureExtractor(submod, layers)