parameters: (model_fn_ops, default_output_alternative_key=None)
docstring: Obtain all output alternatives using the model_fn output and heuristics.
  
    Args:
      model_fn_ops: a `ModelFnOps` object produced by a `model_fn`.  This may or
        may not have output_alternatives populated.
      default_output_alternative_key: the name of the head to serve when an
        incoming serving request does not explicitly request a specific head.
        Not needed for single-headed models.
  
    Returns:
      A tuple of (output_alternatives, actual_default_output_alternative_key),
      where the latter names the head that will actually be served by default.
      This may differ from the requested default_output_alternative_key when
      a) no output_alternatives are provided at all, so one must be generated, or
      b) there is exactly one head, which is used regardless of the requested
      default.
  
    Raises:
      ValueError: if the requested default_output_alternative_key is not available
        in output_alternatives, or if there are multiple output_alternatives and
        no default is specified.
docstring_summary: Obtain all output alternatives using the model_fn output and heuristics.
docstring_tokens: Obtain all output alternatives using the model_fn output and heuristics .
function: def get_output_alternatives(model_fn_ops, default_output_alternative_key=None):
    """Obtain all output alternatives using the model_fn output and heuristics.
  
    Args:
      model_fn_ops: a `ModelFnOps` object produced by a `model_fn`.  This may or
        may not have output_alternatives populated.
      default_output_alternative_key: the name of the head to serve when an
        incoming serving request does not explicitly request a specific head.
        Not needed for single-headed models.
  
    Returns:
      A tuple of (output_alternatives, actual_default_output_alternative_key),
      where the latter names the head that will actually be served by default.
      This may differ from the requested default_output_alternative_key when
      a) no output_alternatives are provided at all, so one must be generated, or
      b) there is exactly one head, which is used regardless of the requested
      default.
  
    Raises:
      ValueError: if the requested default_output_alternative_key is not available
        in output_alternatives, or if there are multiple output_alternatives and
        no default is specified.
    """
    output_alternatives = model_fn_ops.output_alternatives
  
    if not output_alternatives:
      if default_output_alternative_key:
        raise ValueError('Requested default_output_alternative: {}, '
                         'but available output_alternatives are: []'.format(
                             default_output_alternative_key))
  
      # Lacking provided output alternatives, the best we can do is to
      # interpret the model as single-headed of unknown type.
      default_problem_type = constants.ProblemType.UNSPECIFIED
      default_outputs = model_fn_ops.predictions
      if not isinstance(default_outputs, dict):
        default_outputs = {prediction_key.PredictionKey.GENERIC: default_outputs}
      actual_default_output_alternative_key = (
          _FALLBACK_DEFAULT_OUTPUT_ALTERNATIVE_KEY)
      output_alternatives = {
          actual_default_output_alternative_key: (default_problem_type,
                                                  default_outputs)
      }
      return output_alternatives, actual_default_output_alternative_key
  
    if default_output_alternative_key:
      # If a default head is provided, use it.
      if default_output_alternative_key in output_alternatives:
        return output_alternatives, default_output_alternative_key
  
      raise ValueError('Requested default_output_alternative: {}, '
                       'but available output_alternatives are: {}'.format(
                           default_output_alternative_key,
                           sorted(output_alternatives.keys())))
  
    if len(output_alternatives) == 1:
      # If there is only one head, use it as the default regardless of its name.
      (actual_default_output_alternative_key, _), = output_alternatives.items()
      return output_alternatives, actual_default_output_alternative_key
  
    raise ValueError('Please specify a default_output_alternative.  '
                     'Available output_alternatives are: {}'.format(
                         sorted(output_alternatives.keys())))
function_tokens: def get_output_alternatives ( model_fn_ops , default_output_alternative_key = None ) : output_alternatives = model_fn_ops . output_alternatives if not output_alternatives : if default_output_alternative_key : raise ValueError ( 'Requested default_output_alternative: {}, ' 'but available output_alternatives are: []' . format ( default_output_alternative_key ) ) # Lacking provided output alternatives, the best we can do is to # interpret the model as single-headed of unknown type. default_problem_type = constants . ProblemType . UNSPECIFIED default_outputs = model_fn_ops . predictions if not isinstance ( default_outputs , dict ) : default_outputs = { prediction_key . PredictionKey . GENERIC : default_outputs } actual_default_output_alternative_key = ( _FALLBACK_DEFAULT_OUTPUT_ALTERNATIVE_KEY ) output_alternatives = { actual_default_output_alternative_key : ( default_problem_type , default_outputs ) } return output_alternatives , actual_default_output_alternative_key if default_output_alternative_key : # If a default head is provided, use it. if default_output_alternative_key in output_alternatives : return output_alternatives , default_output_alternative_key raise ValueError ( 'Requested default_output_alternative: {}, ' 'but available output_alternatives are: {}' . format ( default_output_alternative_key , sorted ( output_alternatives . keys ( ) ) ) ) if len ( output_alternatives ) == 1 : # If there is only one head, use it as the default regardless of its name. ( actual_default_output_alternative_key , _ ) , = output_alternatives . items ( ) return output_alternatives , actual_default_output_alternative_key raise ValueError ( 'Please specify a default_output_alternative.  ' 'Available output_alternatives are: {}' . format ( sorted ( output_alternatives . keys ( ) ) ) )