# 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 keras.backend as k

    k.set_learning_phase(0)

    if isinstance(layer, six.string_types):
        if layer not in self._layer_names:
            raise ValueError("Layer name %s is not part of the graph." % layer)
        layer_name = layer
    elif isinstance(layer, int):
        if layer < 0 or layer >= len(self._layer_names):
            raise ValueError(
                "Layer index %d is outside of range (0 to %d included)."
                % (layer, len(self._layer_names) - 1)
            )
        layer_name = self._layer_names[layer]
    else:
        raise TypeError("Layer must be of type `str` or `int`.")

    layer_output = self._model.get_layer(layer_name).output
    output_func = k.function([self._input], [layer_output])

    # Apply preprocessing and defences
    if x.shape == self.input_shape:
        x_ = np.expand_dims(x, 0)
    else:
        x_ = x
    x_ = self._apply_processing(x_)
    x_ = self._apply_defences_predict(x_)

    return output_func([x_])[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 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 keras.backend as k

    if isinstance(layer, six.string_types):
        if layer not in self._layer_names:
            raise ValueError("Layer name %s is not part of the graph." % layer)
        layer_name = layer
    elif isinstance(layer, int):
        if layer < 0 or layer >= len(self._layer_names):
            raise ValueError(
                "Layer index %d is outside of range (0 to %d included)."
                % (layer, len(self._layer_names) - 1)
            )
        layer_name = self._layer_names[layer]
    else:
        raise TypeError("Layer must be of type `str` or `int`.")

    layer_output = self._model.get_layer(layer_name).output
    output_func = k.function([self._input], [layer_output])

    # Apply preprocessing and defences
    if x.shape == self.input_shape:
        x_ = np.expand_dims(x, 0)
    else:
        x_ = x
    x_ = self._apply_processing(x_)
    x_ = self._apply_defences_predict(x_)

    return output_func([x_])[0]