微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决分类模型中对抗性攻击的置换范数

我创建了一个分类模型并在数据库中对其进行了训练。我还创建了一个对抗性攻击,以便我的训练模型能够错误地预测图像的类别。我想添加一个表示扰动范数的正则化项 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 举报,一经查实,本站将立刻删除。