-
Notifications
You must be signed in to change notification settings - Fork 214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature] add backdoor attack #267
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see the inline comments @Alan-Qin
cfg.attack.setting = 'fix' | ||
cfg.attack.freq = 10 | ||
cfg.attack.insert_round = 100000 | ||
cfg.attack.mean = [0.1307] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does the mean and std default to 0.1307 and 0.3081? Maybe they should be set according to cfg.data.type?
transforms_funcs = get_transform(ctx, 'torchvision')['transform'] | ||
load_path = ctx.attack.edge_path | ||
if "femnist" in ctx.data.type: | ||
if mode == 'train': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please import federatedscope/core/auxiliaries/enums.py
and use MODE.TRAIN instead
sample = sample.numpy().transpose(1, 2, 0) | ||
data['train'].dataset.append((transforms_funcs(sample), label)) | ||
|
||
if mode == 'test' or 'val': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same as above
logger.info('adding {:d} edge-cased samples in CIFAR-10'.format( | ||
num_poisoned)) | ||
|
||
if mode == 'test' or 'val': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same as above
else: | ||
dataset_.append((img, data[1])) | ||
|
||
if mode == 'test' or 'val': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MODE.TEST or MODE.VAL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix it
|
||
load_path = ctx.attack.trigger_path | ||
|
||
if mode == 'train': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MODE.TRAIN
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fit it
shuffle=True, | ||
num_workers=ctx.data.num_workers) | ||
|
||
if mode == 'test' or 'val': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MODE.TEST or MODE.VAL
def load_poisoned_dataset_edgeset(data, ctx, mode): | ||
|
||
transforms_funcs = get_transform(ctx, 'torchvision')['transform'] | ||
load_path = ctx.attack.edge_path |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use data.root
instead, and you can create a sub directory under data.root
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
LGTM, @Alan-Qin please remember to finish the following modifications in the future.
|
* add backdoor attack Co-authored-by: Alan-Qin <[email protected]> Co-authored-by: Osier-Yi <[email protected]>
As the title says. This thread is inherited from #250, since the checking of Contributor License Agreement could not be passed for some reasons in #250.
Please note that the contributor and author of this pr is @Alan-Qin, and I only help on committing.
Thanks a lot for the contribution :)