code: def main(_):
      """Run the sample attack"""
      # Images for inception classifier are normalized to be in [-1, 1] interval,
      # eps is a difference between pixels so it should be in [0, 2] interval.
      # Renormalizing epsilon from [0, 255] to [0, 2].
      eps = 2.0 * FLAGS.max_epsilon / 255.0
      alpha = 2.0 * FLAGS.iter_alpha / 255.0
      num_iter = FLAGS.num_iter
      batch_shape = [
          FLAGS.batch_size,
          FLAGS.image_height,
          FLAGS.image_width,
          3,
      ]
      nb_classes = 1001
  
      tf.logging.set_verbosity(tf.logging.INFO)
  
      all_images_taget_class = load_target_class(FLAGS.input_dir)
  
      with tf.Graph().as_default():
          # Prepare graph
          x_input = tf.placeholder(tf.float32, shape=batch_shape)
          x_max = tf.clip_by_value(x_input + eps, -1.0, 1.0)
          x_min = tf.clip_by_value(x_input - eps, -1.0, 1.0)
  
          with slim.arg_scope(inception.inception_v3_arg_scope()):
              inception.inception_v3(
                  x_input, num_classes=nb_classes, is_training=False
              )
  
          x_adv = x_input
          target_class_input = tf.placeholder(
              tf.int32, shape=[FLAGS.batch_size]
          )
          one_hot_target_class = tf.one_hot(
              target_class_input, nb_classes
          )
  
          for _ in range(num_iter):
              with slim.arg_scope(inception.inception_v3_arg_scope()):
                  logits, end_points = inception.inception_v3(
                      x_adv,
                      num_classes=nb_classes,
                      is_training=False,
                      reuse=True,
                  )
              cross_entropy = tf.losses.softmax_cross_entropy(
                  one_hot_target_class,
                  logits,
                  label_smoothing=0.1,
                  weights=1.0,
              )
              cross_entropy += tf.losses.softmax_cross_entropy(
                  one_hot_target_class,
                  end_points["AuxLogits"],
                  label_smoothing=0.1,
                  weights=0.4,
              )
              x_next = x_adv - alpha * tf.sign(
                  tf.gradients(cross_entropy, x_adv)[0]
              )
              x_next = tf.clip_by_value(x_next, x_min, x_max)
              x_adv = x_next
  
          # Run computation
          saver = tf.train.Saver(slim.get_model_variables())
          session_creator = tf.train.ChiefSessionCreator(
              scaffold=tf.train.Scaffold(saver=saver),
              checkpoint_filename_with_path=FLAGS.checkpoint_path,
              master=FLAGS.master,
          )
  
          with tf.train.MonitoredSession(
              session_creator=session_creator
          ) as sess:
              for filenames, images in load_images(
                  FLAGS.input_dir, batch_shape
              ):
                  target_class_for_batch = [
                      all_images_taget_class[n] for n in filenames
                  ] + [0] * (FLAGS.batch_size - len(filenames))
                  adv_images = sess.run(
                      x_adv,
                      feed_dict={
                          x_input: images,
                          target_class_input: target_class_for_batch,
                      },
                  )
                  save_images(adv_images, filenames, FLAGS.output_dir)
  
file_path: cleverhans/cleverhans_v3.1.0/examples/nips17_adversarial_competition/dev_toolkit/sample_targeted_attacks/iter_target_class/attack_iter_target_class.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import csv
  import os
  import numpy
  import tensorflow
  from tensorflow.contrib.slim.nets import inception
  from scipy.misc import imread
  from scipy.misc import imsave
label_desc: Use image node_id 4 for calling a global function with example usage: main(_) without return types