Run inference on examples given model information

  Args:
    examples: A list of examples that matches the model spec.
    serving_bundle: A `ServingBundle` object that contains the information to
      make the inference request.

  Returns:
    A ClassificationResponse or RegressionResponse proto.

def run_inference(examples, serving_bundle):
  """Run inference on examples given model information

  Args:
    examples: A list of examples that matches the model spec.
    serving_bundle: A `ServingBundle` object that contains the information to
      make the inference request.

  Returns:
    A ClassificationResponse or RegressionResponse proto.
  """
  batch_size = 64
  if serving_bundle.estimator and serving_bundle.feature_spec:
    # If provided an estimator and feature spec then run inference locally.
    preds = serving_bundle.estimator.predict(
      lambda: tf.data.Dataset.from_tensor_slices(
        tf.parse_example([ex.SerializeToString() for ex in examples],
        serving_bundle.feature_spec)).batch(batch_size))

    if serving_bundle.use_predict:
      preds_key = serving_bundle.predict_output_tensor
    elif serving_bundle.model_type == 'regression':
      preds_key = 'predictions'
    else:
      preds_key = 'probabilities'

    values = []
    for pred in preds:
      values.append(pred[preds_key])
    return common_utils.convert_prediction_values(values, serving_bundle)
  elif serving_bundle.custom_predict_fn:
    # If custom_predict_fn is provided, pass examples directly for local
    # inference.
    values = serving_bundle.custom_predict_fn(examples)
    return common_utils.convert_prediction_values(values, serving_bundle)
  else:
    return platform_utils.call_servo(examples, serving_bundle)