class_docstr: To retain the output of multiple named layers during the computation
  of the given network:
  
      with TraceDict(net, ['layer1.name1', 'layer2.name2']) as ret:
          _ = net(inp)
          representation = ret['layer1.name1'].output
  
  If edit_output is provided, it should be a function that takes
  two arguments: output, and the layer name; and then it returns the
  modified output.
  
  Other arguments are the same as Trace.  If stop is True, then the
  execution of the network will be stopped after the last layer
  listed (even if it would not have been the last to be executed).
class_docstr_tok: ["To","retain","the","output","of","multiple","named","layers","during","the","computation","of","the","given","network",":","with","TraceDict","(","net",",","[","'layer1.name1","'",",","'layer2.name2","'","]",")","as","ret",":","_","=","net","(","inp",")","representation","=","ret","[","'layer1.name1","'","]",".output","If","edit_output","is","provided",",","it","should","be","a","function","that","takes","two","arguments",":","output",",","and","the","layer","name",";","and","then","it","returns","the","modified","output",".","Other","arguments","are","the","same","as","Trace",".","If","stop","is","True",",","then","the","execution","of","the","network","will","be","stopped","after","the","last","layer","listed","(","even","if","it","would","not","have","been","the","last","to","be","executed",")","."]
code: def __init__(
      self,
      module,
      layers=None,
      retain_output=True,
      retain_input=False,
      clone=False,
      detach=False,
      retain_grad=False,
      edit_output=None,
      stop=False,
  ):
      self.stop = stop
  
      def flag_last_unseen(it):
          try:
              it = iter(it)
              prev = next(it)
              seen = set([prev])
          except StopIteration:
              return
          for item in it:
              if item not in seen:
                  yield False, prev
                  seen.add(item)
                  prev = item
          yield True, prev
  
      for is_last, layer in flag_last_unseen(layers):
          self[layer] = Trace(
              module=module,
              layer=layer,
              retain_output=retain_output,
              retain_input=retain_input,
              clone=clone,
              detach=detach,
              retain_grad=retain_grad,
              edit_output=edit_output,
              stop=stop and is_last,
          )
  
imports: import contextlib
  import copy
  import inspect
  from collections import OrderedDict
  import torch
label_desc: Use image node_id 1 to create a new TraceDict object from inherited base classes: OrderedDict, contextlib with example: obj = TraceDict(module, layers, retain_output, retain_input, clone, detach, retain_grad, edit_output, stop)