Skip to content

Commit

Permalink
调整格式
Browse files Browse the repository at this point in the history
  • Loading branch information
duoergun0729 committed Oct 12, 2018
1 parent 9f2caf7 commit deeabfa
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions tutorials/imagenet_tutorial_fgsm_pytorch.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#coding=utf-8

# Copyright 2017 - 2018 Baidu Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -66,7 +68,17 @@ def main(image_path):


# Initialize the network
model = models.resnet18(pretrained=True).to(device).eval()
#Alexnet
model = models.alexnet(pretrained=True).to(device).eval()
#model = models.resnet18(pretrained=True).to(device).eval()

#print(model)

#设置为不保存梯度值 自然也无法修改
for param in model.parameters():
#print(param)
#print(param.requires_grad)
param.requires_grad = False

loss_func=nn.CrossEntropyLoss()

Expand All @@ -77,7 +89,8 @@ def main(image_path):
#attack = FGSMT(m)
attack = FGSM(m)

attack_config = {"epsilons": 0.3}
# 静态epsilons
attack_config = {"epsilons": 0.2}

inputs=img
#labels=388
Expand All @@ -88,10 +101,10 @@ def main(image_path):
adversary = Adversary(inputs, labels)
#adversary = Adversary(inputs, 388)

#tlabel = np.array([489])
#tlabel = 489
#adversary.set_target(is_targeted_attack=True, target_label=tlabel)

# FGSM non-targeted attack
# FGSM targeted attack
adversary = attack(adversary, **attack_config)


Expand Down

0 comments on commit deeabfa

Please sign in to comment.