def get_all_layers(layer, treat_as_input=None):
 try:
  queue = deque(layer)
 except TypeError:
  queue = deque([layer])
 seen = set()
 done = set()
 result = []
 if (treat_as_input is not None):
  seen.update(treat_as_input)
 while queue:
  layer = queue[0]
  if (layer is None):
   queue.popleft()
  elif (layer not in seen):
   seen.add(layer)
   if hasattr(layer, 'input_layers'):
    queue.extendleft(reversed(layer.input_layers))
   elif hasattr(layer, 'input_layer'):
    queue.appendleft(layer.input_layer)
  else:
   queue.popleft()
   if (layer not in done):
    result.append(layer)
    done.add(layer)
 return result

def get_all_layers ( layer , treat_as_input = None ) : try : queue = deque ( layer ) except TypeError : queue = deque ( [ layer ] ) seen = set ( ) done = set ( ) result = [ ] if ( treat_as_input is not None ) : seen . update ( treat_as_input ) while queue : layer = queue [ 0 ] if ( layer is None ) : queue . popleft ( ) elif ( layer not in seen ) : seen . add ( layer ) if hasattr ( layer , 'input_layers' ) : queue . extendleft ( reversed ( layer . input_layers ) ) elif hasattr ( layer , 'input_layer' ) : queue . appendleft ( layer . input_layer ) else : queue . popleft ( ) if ( layer not in done ) : result . append ( layer ) done . add ( layer ) return result
this function gathers all layers below one or more given :class:layer instances .