code: def generate_adv_whitebox(self, input_pic, target_pic):
      # Get input and output tensors
      images_placeholder = tf.get_default_graph().get_tensor_by_name(
          "input:0"
      )
      embeddings = tf.get_default_graph().get_tensor_by_name(
          "embeddings:0"
      )
      phase_train_placeholder = (
          tf.get_default_graph().get_tensor_by_name("phase_train:0")
      )
  
      target_emb = self.generate_embedding(target_pic)
  
      # loss函数目的是将起下降
      loss = tf.sqrt(tf.reduce_sum(tf.square(embeddings - target_emb)))
  
      # 定义deepfool迭代器
      adv_x = deepfool(
          images_placeholder, loss=loss, bounds=(-1.0, 1.0)
      )
  
      input_image = get_pic_from_png(input_pic)
      adv_image = np.reshape(
          input_image,
          (
              -1,
              input_image.shape[0],
              input_image.shape[1],
              input_image.shape[2],
          ),
      )
  
      # 损失函数小于adv_loss_stop 认为满足需要了 退出
      adv_loss_stop = 0.001
      # loss阈值 衡量前后两次loss差别过小 认为已经稳定了 收敛了 连续loss_cnt_threshold次小于loss_limit退出
      loss_limit = adv_loss_stop / 10
      loss_cnt_threshold = 10
      # 最大迭代次数
      num_iter = 2000
  
      last_adv_loss = 0
      cnt = 0
      flag = False
  
      for i in range(num_iter):
          feed_dict = {
              images_placeholder: adv_image,
              phase_train_placeholder: False,
          }
          # 调用迭代器
          adv_image, adv_loss = self.sess.run(
              [adv_x, loss], feed_dict=feed_dict
          )
  
          print(
              "[%d] Bias from original image: %2.6f Loss: %2.6f"
              % (
                  i,
                  np.sqrt(
                      np.sum(np.square(adv_image[0, ...] - input_image))
                  ),
                  adv_loss,
              )
          )
  
          if np.absolute(adv_loss - last_adv_loss) < loss_limit:
              if flag:
                  cnt += 1
              else:
                  flag = True
          else:
              flag = False
              cnt = 0
  
          if cnt == loss_cnt_threshold:
              print("always get too tiny loss...")
              break
  
          if adv_loss < adv_loss_stop:
              print("get final result...")
              break
  
          last_adv_loss = adv_loss
  
      if i == num_iter - 1:
          print("Out of maximum iterative number...")
      # filename = generate_inp2adv_name(input_pic, target_pic) + str(i)
      # 调试阶段 文件名不随机
      filename = "output/" + generate_inp2adv_name(
          input_pic, target_pic
      )
      save_img2png(adv_image[0, ...], filename)
  
      feed_dict = {
          images_placeholder: adv_image,
          phase_train_placeholder: False,
      }
      adv_embedding = self.sess.run(embeddings, feed_dict=feed_dict)[0]
      print(
          "The distance between input embedding and target is %2.6f"
          % Euclidian_distance(adv_embedding, target_emb)
      )
  
imports: import tensorflow
  import numpy
  from PIL import Image
  import sys
  from scipy import misc
  import os
  import time
  from adversarialbox.attacks.tf.tools import deepfool
  import facenet
label_desc: Use image node_id 4 for calling the FacenetFR obj's underlying member method code with example usage: obj.generate_adv_whitebox(input_pic, target_pic) without return types