# Buggy code
def get_activations(self, x, layer):
    """
    Return the output of the specified layer for input `x`. `layer` is specified by layer index (between 0 and
    `nb_layers - 1`) or by name. The number of layers can be determined by counting the results returned by
    calling `layer_names`.

    :param x: Input for computing the activations.
    :type x: `np.ndarray`
    :param layer: Layer for computing the activations
    :type layer: `int` or `str`
    :return: The output of `layer`, where the first dimension is the batch size corresponding to `x`.
    :rtype: `np.ndarray`
    """
    import tensorflow as tf

    # Get the computational graph
    with self._sess.graph.as_default():
        graph = tf.get_default_graph()

    if isinstance(
        layer, six.string_types
    ):  # basestring for Python 2 (str, unicode) support
        if layer not in self._layer_names:
            raise ValueError("Layer name %s is not part of the graph." % layer)
        layer_tensor = graph.get_tensor_by_name(layer)

    elif isinstance(layer, (int, np.integer)):
        layer_tensor = graph.get_tensor_by_name(self._layer_names[layer])

    else:
        raise TypeError("Layer must be of type `str` or `int`. Received '%s'", layer)

    # Get activations
    # Apply preprocessing and defences
    x_ = self._apply_processing(x)
    x_ = self._apply_defences_predict(x_)

    # Create feed_dict
    fd = {self._input_ph: x_}
    if self._learning is not None:
        fd[self._learning] = False

    # Run prediction
    result = self._sess.run(layer_tensor, feed_dict=fd)

    return result


# 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 get_activations(self, x, layer):
    """
    Return the output of the specified layer for input `x`. `layer` is specified by layer index (between 0 and
    `nb_layers - 1`) or by name. The number of layers can be determined by counting the results returned by
    calling `layer_names`.

    :param x: Input for computing the activations.
    :type x: `np.ndarray`
    :param layer: Layer for computing the activations
    :type layer: `int` or `str`
    :return: The output of `layer`, where the first dimension is the batch size corresponding to `x`.
    :rtype: `np.ndarray`
    """
    import tensorflow as tf

    # Get the computational graph
    with self._sess.graph.as_default():
        graph = tf.get_default_graph()

    if isinstance(
        layer, six.string_types
    ):  # basestring for Python 2 (str, unicode) support
        if layer not in self._layer_names:
            raise ValueError("Layer name %s is not part of the graph." % layer)
        layer_tensor = graph.get_tensor_by_name(layer)

    elif isinstance(layer, (int, np.integer)):
        layer_tensor = graph.get_tensor_by_name(self._layer_names[layer])

    else:
        raise TypeError("Layer must be of type `str` or `int`. Received '%s'", layer)

    # Get activations
    # Apply preprocessing and defences
    x_ = self._apply_processing(x)
    x_ = self._apply_defences_predict(x_)

    # Create feed_dict
    fd = {self._input_ph: x_}
    fd.update(self._feed_dict)

    # Run prediction
    result = self._sess.run(layer_tensor, feed_dict=fd)

    return result