'Generate symbolic graph for adversarial examples and return.
:param x: The model\'s symbolic inputs.
:param eps: (required float) maximum distortion of adversarial example
compared to original input
:param eps_iter: (required float) step size for each attack iteration
:param nb_iter: (required int) Number of attack iterations.
:param y: (optional) A tensor with the model labels.
:param y_target: (optional) A tensor with the labels to target. Leave
y_target=None if y is also set. Labels should be
one-hot-encoded.
:param ord: (optional) Order of the norm (mimics Numpy).
Possible values: np.inf, 1 or 2.
:param clip_min: (optional float) Minimum input component value
:param clip_max: (optional float) Maximum input component value'

def generate(self, x, **kwargs):

    import tensorflow as tf
    assert self.parse_params(**kwargs)
    eta = 0
    model_preds = self.model.get_probs(x)
    preds_max = tf.reduce_max(model_preds, 1, keep_dims=True)
    if (self.y_target is not None):
        y = self.y_target
        targeted = True
    elif (self.y is not None):
        y = self.y
        targeted = False
    else:
        y = tf.to_float(tf.equal(model_preds, preds_max))
        targeted = False
    y_kwarg = ('y_target' if targeted else 'y')
    fgm_params = {'eps': self.eps_iter, y_kwarg: y, 'ord': self.ord}
    for i in range(self.nb_iter):
        FGM = FastGradientMethod(self.model, back=self.back, sess=self.sess)
        eta = (FGM.generate((x + eta), **fgm_params) - x)
        if (self.ord == np.inf):
            eta = tf.clip_by_value(eta, (- self.eps), self.eps)
        elif (self.ord in [1, 2]):
            reduc_ind = list(xrange(1, len(eta.get_shape())))
            if (self.ord == 1):
                norm = tf.reduce_sum(tf.abs(eta), reduction_indices=reduc_ind, keep_dims=True)
            elif (self.ord == 2):
                norm = tf.sqrt(tf.reduce_sum(tf.square(eta), reduction_indices=reduc_ind, keep_dims=True))
            eta = ((eta * self.eps) / norm)
    adv_x = (x + eta)
    if ((self.clip_min is not None) and (self.clip_max is not None)):
        adv_x = tf.clip_by_value(adv_x, self.clip_min, self.clip_max)
    return adv_x
