import tensorflow as tf

        bounds=(0,1)):

    (clip_min, clip_max)=bounds

    grad, = tf.gradients(loss, x)

    if  ord == 1:
        red_ind = list(range(1, len(x.get_shape())))
        avoid_zero_div = 1e-8
        avoid_nan_norm = tf.maximum(avoid_zero_div,
                                    reduce_sum(tf.abs(grad),
                                               reduction_indices=red_ind,
                                               keepdims=True))
        normalized_grad = old_div(grad, avoid_nan_norm)
    elif ord == 2:
        red_ind = list(range(1, len(x.get_shape())))
        avoid_zero_div = 1e-8
        square = tf.maximum(avoid_zero_div,
                            reduce_sum(tf.square(grad),
                                       reduction_indices=red_ind,
