def keras_evaluate(model, test_data, metric):
  """A function evaluates the model on test data.

  Args:
    model: a `tf.keras.Model` object
    test_data: a `tf.data.Dataset` object
    metric: a `tf.keras.metric` object

  Returns:
    statisitic computed by metric object.
  """
  metric.reset_states()
  for batch in test_data:
    if isinstance(batch, dict):
      x = batch["x"]
      y = batch["y"]
    else:
      x, y = batch
    preds = model(x, training=False)
    metric.update_state(y_true=y, y_pred=preds)
  return metric.result()