Skip to content
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

Merged
merged 4 commits into from
Jul 28, 2022

Conversation

xieyxclack
Copy link
Collaborator

@xieyxclack xieyxclack commented Jul 28, 2022

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 :)

@xieyxclack xieyxclack added the enhancement New feature or request label Jul 28, 2022
@xieyxclack xieyxclack requested review from Osier-Yi and yxdyc July 28, 2022 09:13
@xieyxclack xieyxclack added Feature New feature and removed enhancement New feature or request labels Jul 28, 2022
Copy link
Collaborator

@DavdGao DavdGao left a 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

federatedscope/contrib/model/resnet.py Show resolved Hide resolved
cfg.attack.setting = 'fix'
cfg.attack.freq = 10
cfg.attack.insert_round = 100000
cfg.attack.mean = [0.1307]
Copy link
Collaborator

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':
Copy link
Collaborator

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':
Copy link
Collaborator

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':
Copy link
Collaborator

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':
Copy link
Collaborator

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

Copy link
Contributor

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':
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MODE.TRAIN

Copy link
Contributor

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':
Copy link
Collaborator

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

federatedscope/attack/auxiliary/create_edgeset.py Outdated Show resolved Hide resolved
def load_poisoned_dataset_edgeset(data, ctx, mode):

transforms_funcs = get_transform(ctx, 'torchvision')['transform']
load_path = ctx.attack.edge_path
Copy link
Collaborator

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix it

Copy link
Collaborator

@Osier-Yi Osier-Yi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@DavdGao
Copy link
Collaborator

DavdGao commented Jul 28, 2022

LGTM, @Alan-Qin please remember to finish the following modifications in the future.

  • Add unit test for each backdoor attack algorithm
  • Use data.root rather than attack.edge_path, or set attack.edge_path='test_data/' in the corresponding unit test to avoid saving data in the Jenkins server.
  • Download the poison dataset from url rather than manually downloading.
  • Update the tutorial

@DavdGao DavdGao merged commit a6dd0c7 into alibaba:master Jul 28, 2022
@xieyxclack xieyxclack deleted the feature/backdoor_by_zeyu branch August 15, 2022 09:17
Schichael pushed a commit to Schichael/FederatedScope_thesis that referenced this pull request Sep 7, 2022
* add backdoor attack

Co-authored-by: Alan-Qin <[email protected]>
Co-authored-by: Osier-Yi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants