def get_source_inputs(tensor, layer=None, node_index=None):
 if (not hasattr(tensor, '_keras_history')):
  return tensor
 if ((layer is None) or node_index):
  (layer, node_index, _) = tensor._keras_history
 if (not layer.inbound_nodes):
  return [tensor]
 else:
  node = layer.inbound_nodes[node_index]
  if (not node.inbound_layers):
   return node.input_tensors
  else:
   source_tensors = []
   for i in range(len(node.inbound_layers)):
    x = node.input_tensors[i]
    layer = node.inbound_layers[i]
    node_index = node.node_indices[i]
    previous_sources = get_source_inputs(x, layer, node_index)
    for x in previous_sources:
     if (x not in source_tensors):
      source_tensors.append(x)
   return source_tensors

def get_source_inputs ( tensor , layer = None , node_index = None ) : if ( not hasattr ( tensor , '_keras_history' ) ) : return tensor if ( ( layer is None ) or node_index ) : ( layer , node_index , _ ) = tensor . _keras_history if ( not layer . inbound_nodes ) : return [ tensor ] else : node = layer . inbound_nodes [ node_index ] if ( not node . inbound_layers ) : return node . input_tensors else : source_tensors = [ ] for i in range ( len ( node . inbound_layers ) ) : x = node . input_tensors [ i ] layer = node . inbound_layers [ i ] node_index = node . node_indices [ i ] previous_sources = get_source_inputs ( x , layer , node_index ) for x in previous_sources : if ( x not in source_tensors ) : source_tensors . append ( x ) return source_tensors
returns the list of input tensors necessary to compute tensor .