class_docstr: Feature extractor with OrderedDict return
  
  Wrap a model and extract features as specified by the out indices, the network is
  partially re-built from contained modules.
  
  There is a strong assumption that the modules have been registered into the model in the same
  order as they are used. There should be no reuse of the same nn.Module more than once, including
  trivial modules like `self.relu = nn.ReLU`.
  
  Only submodules that are directly assigned to the model class (`model.feature1`) or at most
  one Sequential container deep (`model.features.1`, with flatten_sequent=True) can be captured.
  All Sequential containers that are directly assigned to the original model will have their
  modules assigned to this module with the name `model.features.1` being changed to `model.features_1`
class_docstr_tok: ["Feature","extractor","with","OrderedDict","return","Wrap","a","model","and","extract","features","as","specified","by","the","out","indices",",","the","network","is","partially","re-built","from","contained","modules",".","There","is","a","strong","assumption","that","the","modules","have","been","registered","into","the","model","in","the","same","order","as","they","are","used",".","There","should","be","no","reuse","of","the","same","nn.Module","more","than","once",",","including","trivial","modules","like","`","self.relu","=","nn.ReLU","`",".","Only","submodules","that","are","directly","assigned","to","the","model","class","(","`","model.feature1","`",")","or","at","most","one","Sequential","container","deep","(","`","model.features.1","`",",","with","flatten_sequent=True",")","can","be","captured",".","All","Sequential","containers","that","are","directly","assigned","to","the","original","model","will","have","their","modules","assigned","to","this","module","with","the","name","`","model.features.1","`","being","changed","to","`","model.features_1","`"]
docstr: Args:
      model: Model from which to extract features.
      out_indices: Output indices of the model features to extract.
      out_map: Return id mapping for each output index, otherwise str(index) is used.
      feature_concat: Concatenate intermediate features that are lists or tuples instead of selecting
          first element e.g. `x[0]`
      flatten_sequential: Flatten first two-levels of sequential modules in model (re-writes model modules)
docstr_tok: ["Args",":","model",":","Model","from","which","to","extract","features",".","out_indices",":","Output","indices","of","the","model","features","to","extract",".","out_map",":","Return","id","mapping","for","each","output","index",",","otherwise","str","(","index",")","is","used",".","feature_concat",":","Concatenate","intermediate","features","that","are","lists","or","tuples","instead","of","selecting","first","element","e.g",".","`","x","[","0","]","`","flatten_sequential",":","Flatten","first","two-levels","of","sequential","modules","in","model","(","re-writes","model","modules",")"]
code: def __init__(
      self,
      model: nn.Module,
      out_indices: Tuple[int, ...] = (0, 1, 2, 3, 4),
      out_map: Sequence[Union[int, str]] = None,
      output_fmt: str = "NCHW",
      feature_concat: bool = False,
      flatten_sequential: bool = False,
  ):
      """
      Args:
          model: Model from which to extract features.
          out_indices: Output indices of the model features to extract.
          out_map: Return id mapping for each output index, otherwise str(index) is used.
          feature_concat: Concatenate intermediate features that are lists or tuples instead of selecting
              first element e.g. `x[0]`
          flatten_sequential: Flatten first two-levels of sequential modules in model (re-writes model modules)
      """
      super(FeatureDictNet, self).__init__()
      self.feature_info = _get_feature_info(model, out_indices)
      self.output_fmt = Format(output_fmt)
      self.concat = feature_concat
      self.grad_checkpointing = False
      self.return_layers = {}
  
      return_layers = _get_return_layers(self.feature_info, out_map)
      modules = _module_list(
          model, flatten_sequential=flatten_sequential
      )
      remaining = set(return_layers.keys())
      layers = OrderedDict()
      for new_name, old_name, module in modules:
          layers[new_name] = module
          if old_name in remaining:
              # return id has to be consistently str type for torchscript
              self.return_layers[new_name] = str(
                  return_layers[old_name]
              )
              remaining.remove(old_name)
          if not remaining:
              break
      assert not remaining and len(self.return_layers) == len(
          return_layers
      ), f"Return layers ({remaining}) are not present in model"
      self.update(layers)
  
imports: from collections import OrderedDict, defaultdict
  from copy import deepcopy
  from functools import partial
  from typing import Dict, List, Sequence, Tuple, Union
  import torch
  import torch.nn
  from torch.utils.checkpoint import checkpoint
  from timm.layers import Format
label_desc: Use image node_id 1 to create a new FeatureDictNet object from inherited base classes: nn with example: obj = FeatureDictNet(model, out_indices, out_map, output_fmt, feature_concat, flatten_sequential)