分类模型中对抗性攻击的置换范数

问题描述

我创建了一个分类模型并在数据库中对其进行了训练。我还创建了一个对抗性攻击,以便我的训练模型能够错误地预测图像的类别。我想添加一个表示扰动范数的正则化项 R,例如l2(欧几里得 距离)或 l∞(最大范数),以便我的模型提出扰动 肉眼看不见。你能告诉我在训练对抗性攻击时我必须添加什么以包含正则化项吗?

def train_step(image,eps=EPS,noise = noise):
   with tf.GradientTape() as gen_tape:
    generated_perturbation = generator(noise,training=True)
    adv_img = image + eps * generated_perturbation

    pred_adv_img = cnn(adv_img,training=False)
    
    # calculate the loss with respect to the deceptive (aeroplane) label
    gen_loss = generator_loss(pred_adv_img)

# calculate the gradients of the loss function
gradients_of_generator = gen_tape.gradient(gen_loss,generator.trainable_variables)

# update the weights of the generator based on the gradient
tf.keras.optimizers.Adam(1e-4).apply_gradients(zip(gradients_of_generator,

generator.trainable_variables)) 打印(gradients_of_generator)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)