# Buggy code
def __init__(
    self,
    clip_values,
    input_ph,
    logits,
    output_ph=None,
    train=None,
    loss=None,
    learning=None,
    sess=None,
    channel_index=3,
    defences=None,
    preprocessing=(0, 1),
):
    """
    Initialization specifically for the Tensorflow-based implementation.

    :param clip_values: Tuple of the form `(min, max)` representing the minimum and maximum values allowed
           for features.
    :type clip_values: `tuple`
    :param input_ph: The input placeholder.
    :type input_ph: `tf.Placeholder`
    :param logits: The logits layer of the model.
    :type logits: `tf.Tensor`
    :param output_ph: The labels placeholder of the model. This parameter is necessary when training the model and
           when computing gradients w.r.t. the loss function.
    :type output_ph: `tf.Tensor`
    :param train: The train tensor for fitting, including an optimizer. Use this parameter only when training the
           model.
    :type train: `tf.Tensor`
    :param loss: The loss function for which to compute gradients. This parameter is necessary when training the
           model and when computing gradients w.r.t. the loss function.
    :type loss: `tf.Tensor`
    :param learning: The placeholder to indicate if the model is training.
    :type learning: `tf.Placeholder` of type bool.
    :param sess: Computation session.
    :type sess: `tf.Session`
    :param channel_index: Index of the axis in data containing the color channels or features.
    :type channel_index: `int`
    :param defences: Defences to be activated with the classifier.
    :type defences: `str` or `list(str)`
    :param preprocessing: Tuple of the form `(substractor, divider)` of floats or `np.ndarray` of values to be
           used for data preprocessing. The first value will be substracted from the input. The input will then
           be divided by the second one.
    :type preprocessing: `tuple`
    """
    import tensorflow as tf

    super(TFClassifier, self).__init__(
        clip_values=clip_values,
        channel_index=channel_index,
        defences=defences,
        preprocessing=preprocessing,
    )
    self._nb_classes = int(logits.get_shape()[-1])
    self._input_shape = tuple(input_ph.get_shape()[1:])
    self._input_ph = input_ph
    self._logits = logits
    self._output_ph = output_ph
    self._train = train
    self._loss = loss
    self._learning = learning

    # Assign session
    if sess is None:
        # self._sess = tf.get_default_session()
        raise ValueError("A session cannot be None.")
    else:
        self._sess = sess

    # Get the internal layers
    self._layer_names = self._get_layers()

    # Must be set here for the softmax output
    self._probs = tf.nn.softmax(logits)

    # Get the loss gradients graph
    if self._loss is not None:
        self._loss_grads = tf.gradients(self._loss, self._input_ph)[0]


# Traceback (IndexError)
Traceback (most recent call last):
File "cw_pytorch.py", line 172, in <module>
x_test_adv = cl2m.generate(inputs, **params)
File "/home/weitian/anaconda3/envs/xnor/lib/python3.6/site-packages/art/attacks/carlini.py", line 380, in generate
x_adv_batch_tanh[active_and_update_adv] = x_adv_batch_tanh[update_adv] + \
IndexError: boolean index did not match indexed array along dimension 0; dimension is 18 but corresponding boolean dimension is 17

# Fixed code
def __init__(
    self,
    clip_values,
    input_ph,
    logits,
    output_ph=None,
    train=None,
    loss=None,
    learning=None,
    sess=None,
    channel_index=3,
    defences=None,
    preprocessing=(0, 1),
):
    """
    Initialization specifically for the Tensorflow-based implementation.

    :param clip_values: Tuple of the form `(min, max)` representing the minimum and maximum values allowed
           for features.
    :type clip_values: `tuple`
    :param input_ph: The input placeholder.
    :type input_ph: `tf.Placeholder`
    :param logits: The logits layer of the model.
    :type logits: `tf.Tensor`
    :param output_ph: The labels placeholder of the model. This parameter is necessary when training the model and
           when computing gradients w.r.t. the loss function.
    :type output_ph: `tf.Tensor`
    :param train: The train tensor for fitting, including an optimizer. Use this parameter only when training the
           model.
    :type train: `tf.Tensor`
    :param loss: The loss function for which to compute gradients. This parameter is necessary when training the
           model and when computing gradients w.r.t. the loss function.
    :type loss: `tf.Tensor`
    :param learning: The placeholder to indicate if the model is training.
    :type learning: `tf.Placeholder` of type bool.
    :param sess: Computation session.
    :type sess: `tf.Session`
    :param channel_index: Index of the axis in data containing the color channels or features.
    :type channel_index: `int`
    :param defences: Defences to be activated with the classifier.
    :type defences: `str` or `list(str)`
    :param preprocessing: Tuple of the form `(substractor, divider)` of floats or `np.ndarray` of values to be
           used for data preprocessing. The first value will be substracted from the input. The input will then
           be divided by the second one.
    :type preprocessing: `tuple`
    """
    import tensorflow as tf

    super(TFClassifier, self).__init__(
        clip_values=clip_values,
        channel_index=channel_index,
        defences=defences,
        preprocessing=preprocessing,
    )
    self._nb_classes = int(logits.get_shape()[-1])
    self._input_shape = tuple(input_ph.get_shape()[1:])
    self._input_ph = input_ph
    self._logits = logits
    self._output_ph = output_ph
    self._train = train
    self._loss = loss
    self._learning = learning
    self._feed_dict = {}

    # Assign session
    if sess is None:
        # self._sess = tf.get_default_session()
        raise ValueError("A session cannot be None.")
    else:
        self._sess = sess

    # Get the internal layers
    self._layer_names = self._get_layers()

    # Must be set here for the softmax output
    self._probs = tf.nn.softmax(logits)

    # Get the loss gradients graph
    if self._loss is not None:
        self._loss_grads = tf.gradients(self._loss, self._input_ph)[0]