Giter VIP home page Giter VIP logo

attack_splitnn's Introduction

Attacking SplitNN

Attacking_SplitNN allows you to easily experiment with various combinations of attack and defense algorithms against SplitNN within PyTorch and scikit-learn.

Install

    pip install git+https://github.com/Koukyosyumei/Attack_SplitNN

SplitNN

You can easily create two-SplitNN with this package as follows.
The client only has input data, and the server has only labels. This package implements SplitNN as the custom torch.nn.modules, so you can train SplitNN like the normal torch models.

    Examples:
            model_1 = FirstNet()
            model_1 = model_1.to(device)

            model_2 = SecondNet()
            model_2 = model_2.to(device)

            opt_1 = optim.Adam(model_1.parameters(), lr=1e-3)
            opt_2 = optim.Adam(model_2.parameters(), lr=1e-3)

            criterion = nn.BCELoss()

            client = Client(model_1)
            server = Server(model_2)

            splitnn = SplitNN(client, server, opt_1, opt_2)

            splitnn.train()
            for epoch in range(3):
            epoch_loss = 0
            epoch_outputs = []
            epoch_labels = []
            for i, data in enumerate(train_loader):
                    splitnn.zero_grads()
                    inputs, labels = data
                    inputs = inputs.to(device)
                    labels = labels.to(device)

                    outputs = splitnn(inputs)
                    loss = criterion(outputs, labels)
                    loss.backward()
                    epoch_loss += loss.item() / len(train_loader.dataset)

                    epoch_outputs.append(outputs)
                    epoch_labels.append(labels)

                    splitnn.backward()
                    splitnn.step()

            print(epoch_loss, torch_auc(torch.cat(epoch_labels),
                                            torch.cat(epoch_outputs)))

Attack

Attacking_SplitNN offers several attack methods with the same interface.

type example Reference
Intermidiate Level Attack evasion attack notebook original paper
Norm Attack label leakage attack notebook original paper
Transfer Inherit Attack membership inference attack notebook original paper
Black Box Model Inversion Attack model inversion attack notebook blog

Defense

example Reference
Max Norm notebook original paper
NoPeek notebook original paper
Shredder notebook original paper

License

This software is released under the MIT License, see LICENSE.txt.

attack_splitnn's People

Contributors

koukyosyumei avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

attack_splitnn's Issues

FSHA.ipynb

Hello,First of all, thank you for sharing your relevant reproducing work, but I ran the code about FSHA, but why the result was so different from the original text under the same configuration? I also modified it, but the result was still so different from the original text

Reimplement FSHA

The current implementation of the FSHA attack is not compatible with AbstractAttacker.

Shredder.ipynb

So sorry to bother you. I have some questions.
In Shredder.ipynb, the class SplitNN is not the subclass of nn.Module, and also does not define the attribute of train. So why there is a code of splitnn.train() in first line of nineteenth block, aslo the questions is the same as splitnn.zero_grads(),splitnn.backward().
The code and the reason of fault is as following.
THX
`splitnn.train()
for epoch in range(3):
epoch_loss = 0
epoch_outputs = []
epoch_labels = []
for i, data in enumerate(victim_train_dataloader):
splitnn.zero_grads()
inputs, labels = data
inputs = inputs.to(device)
labels = labels.to(device)

    outputs = splitnn(inputs)
    loss = criterion(outputs, labels)
    loss.backward()
    epoch_loss += loss.item() / len(victim_train_dataloader.dataset)
    
    epoch_outputs.append(outputs)
    epoch_labels.append(labels)
    
    splitnn.backward()
    splitnn.step()
    
print(epoch_loss, accuracy(torch.cat(epoch_labels),
                            torch.cat(epoch_outputs)))`

`---->Shredder.ipynb#ch0000013vscode-remote?line=0) splitnn.train()
Shredder.ipynb#ch0000013vscode-remote?line=1) for epoch in range(3):
Shredder.ipynb#ch0000013vscode-remote?line=2) epoch_loss = 0

AttributeError: 'SplitNN' object has no attribute 'train'`

Multi-party SplitNN

Attack_SplitNN currently only supports two-party SplitNN.

・We have to implement a more sophisticated SplitNN which supports multi-party.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.