class_docstr: The Carlini and Wagner L2 Attack, https://arxiv.org/abs/1608.04644
  
  :param predict: forward pass function.
  :param num_classes: number of clasess.
  :param confidence: confidence of the adversarial examples.
  :param targeted: if the attack is targeted.
  :param learning_rate: the learning rate for the attack algorithm
  :param binary_search_steps: number of binary search times to find the
      optimum
  :param max_iterations: the maximum number of iterations
  :param abort_early: if set to true, abort early if getting stuck in local
      min
  :param initial_const: initial value of the constant c
  :param clip_min: mininum value per input dimension.
  :param clip_max: maximum value per input dimension.
  :param loss_fn: loss function
class_docstr_tok: ["The","Carlini","and","Wagner","L2","Attack",",","https",":","\/\/arxiv.org\/abs\/1608.04644",":","param","predict",":","forward","pass","function",".",":","param","num_classes",":","number","of","clasess",".",":","param","confidence",":","confidence","of","the","adversarial","examples",".",":","param","targeted",":","if","the","attack","is","targeted",".",":","param","learning_rate",":","the","learning","rate","for","the","attack","algorithm",":","param","binary_search_steps",":","number","of","binary","search","times","to","find","the","optimum",":","param","max_iterations",":","the","maximum","number","of","iterations",":","param","abort_early",":","if","set","to","true",",","abort","early","if","getting","stuck","in","local","min",":","param","initial_const",":","initial","value","of","the","constant","c",":","param","clip_min",":","mininum","value","per","input","dimension",".",":","param","clip_max",":","maximum","value","per","input","dimension",".",":","param","loss_fn",":","loss","function"]
code: def perturb(self, x, y=None):
      x, y = self._verify_and_process_inputs(x, y)
  
      # Initialization
      if y is None:
          y = self._get_predicted_label(x)
      x = replicate_input(x)
      batch_size = len(x)
      coeff_lower_bound = x.new_zeros(batch_size)
      coeff_upper_bound = x.new_ones(batch_size) * CARLINI_COEFF_UPPER
      loss_coeffs = torch.ones_like(y).float() * self.initial_const
      final_l2distsqs = [CARLINI_L2DIST_UPPER] * batch_size
      final_labels = [INVALID_LABEL] * batch_size
      final_advs = x
      x_atanh = self._get_arctanh_x(x)
      y_onehot = to_one_hot(y, self.num_classes).float()
  
      final_l2distsqs = torch.FloatTensor(final_l2distsqs).to(x.device)
      final_labels = torch.LongTensor(final_labels).to(x.device)
  
      # Start binary search
      for outer_step in range(self.binary_search_steps):
          delta = nn.Parameter(torch.zeros_like(x))
          optimizer = optim.Adam([delta], lr=self.learning_rate)
          cur_l2distsqs = [CARLINI_L2DIST_UPPER] * batch_size
          cur_labels = [INVALID_LABEL] * batch_size
          cur_l2distsqs = torch.FloatTensor(cur_l2distsqs).to(x.device)
          cur_labels = torch.LongTensor(cur_labels).to(x.device)
          prevloss = PREV_LOSS_INIT
  
          if self.repeat and outer_step == (
              self.binary_search_steps - 1
          ):
              loss_coeffs = coeff_upper_bound
          for ii in range(self.max_iterations):
              (
                  loss,
                  l2distsq,
                  output,
                  adv_img,
              ) = self._forward_and_update_delta(
                  optimizer, x_atanh, delta, y_onehot, loss_coeffs
              )
              if self.abort_early:
                  if ii % (self.max_iterations // NUM_CHECKS or 1) == 0:
                      if loss > prevloss * ONE_MINUS_EPS:
                          break
                      prevloss = loss
  
              self._update_if_smaller_dist_succeed(
                  adv_img,
                  y,
                  output,
                  l2distsq,
                  batch_size,
                  cur_l2distsqs,
                  cur_labels,
                  final_l2distsqs,
                  final_labels,
                  final_advs,
              )
  
          self._update_loss_coeffs(
              y,
              cur_labels,
              batch_size,
              loss_coeffs,
              coeff_upper_bound,
              coeff_lower_bound,
          )
  
      return final_advs
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from __future__ import unicode_literals
  import torch
  import torch.nn
  import torch.optim
  from advertorch.utils import calc_l2distsq
  from advertorch.utils import tanh_rescale
  from advertorch.utils import torch_arctanh
  from advertorch.utils import clamp
  from advertorch.utils import to_one_hot
  from advertorch.utils import replicate_input
  from .base import Attack
  from .base import LabelMixin
  from .utils import is_successful
label_desc: Use image node_id 8 for calling the CarliniWagnerL2Attack obj's underlying member method code with example usage: obj.perturb(x, y) and returns: final_advs