def get_sorted_feature_names(columns_to_tensors, feature_columns):
  """List feature names: from feature_columns or columns_to_tensors.

  This function will return the list of feature names for layers or Estimators
  that use either feature_columns or directly the inputs returned by an
  input_fn.

  Args:
    columns_to_tensors: A mapping from feature column to tensors. 'string' key
      means a base feature (not-transformed). It can have FeatureColumn as a key
      too. That means that FeatureColumn is already transformed by input
      pipeline. For example, inflow may have handled transformations.
    feature_columns: Optional set containing all the feature columns. If not
      set it is assumed all features come from columns_to_tensors. Otherwise
      this defines the list of features to use.
      All items in the set should be instances of classes derived by
      FeatureColumn.

  Returns:
    List of feature names.
  """
  if feature_columns is not None:
    return [f_col.name for f_col in sorted(list(feature_columns))]
  return [k for k in sorted(columns_to_tensors.keys())]