def correctness_and_confidence(sess, model, x, y, batch_size=None,
                               devices=None, feed=None, attack=None,
                               attack_params=None):
  """
  Report whether the model is correct and its confidence on each example in
  a dataset.
  :param sess: tf.Session
  :param model: cleverhans.model.Model
  :param x: numpy array containing input examples (e.g. MNIST().x_test )
  :param y: numpy array containing example labels (e.g. MNIST().y_test )
  :param batch_size: Number of examples to use in a single evaluation batch.
      If not specified, this function will use a reasonable guess and
      may run out of memory.
      When choosing the batch size, keep in mind that the batch will
      be divided up evenly among available devices. If you can fit 128
      examples in memory on one GPU and you have 8 GPUs, you probably
      want to use a batch size of 1024 (unless a different batch size
      runs faster with the ops you are using, etc.)
  :param devices: An optional list of string device names to use.
    If not specified, this function will use all visible GPUs.
  :param feed: An optional dictionary that is appended to the feeding
           dictionary before the session runs. Can be used to feed
           the learning phase of a Keras model for instance.
  :param attack: cleverhans.attack.Attack
    Optional. If no attack specified, evaluates the model on clean data.
    If attack is specified, evaluates the model on adversarial examples
    created by the attack.
  :param attack_params: dictionary
    If attack is specified, this dictionary is passed to attack.generate
    as keyword arguments.
  :return:
    an ndarray of bools indicating whether each example is correct
    an ndarray of probabilities assigned to the prediction for each example
  """

  _check_x(x)
  _check_y(y)
  if x.shape[0] != y.shape[0]:
    raise ValueError("Number of input examples and labels do not match.")

  factory = _CorrectAndProbFactory(model, attack, attack_params)

  out = batch_eval_multi_worker(sess, factory, [x, y], batch_size=batch_size,
                                devices=devices, feed=feed)

  correctness, confidence = out

  assert correctness.shape == (x.shape[0],)
  assert confidence.shape == (x.shape[0],)
  min_confidence = confidence.min()
  if min_confidence < 0.:
    raise ValueError("Model does not return valid probabilities: " +
                     str(min_confidence))
  max_confidence = confidence.max()
  if max_confidence > 1.:
    raise ValueError("Model does not return valid probablities: " +
                     str(max_confidence))
  assert confidence.min() >= 0., confidence.min()

  return out