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

Documentation update #66

Open
wants to merge 49 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
7f11ace
Add barebones examples
pwang00 Dec 28, 2020
b1996ea
Update examples
pwang00 Dec 29, 2020
a55375c
Merge remote-tracking branch 'upstream/master'
pwang00 Dec 31, 2020
e92dbd8
Keep fork up to date
pwang00 Jan 1, 2021
173a7d2
Bump PL version for more metric functions
suhacker1 Jan 1, 2021
5a6d05d
Create example with new model and enable custom Trainer args
suhacker1 Jan 2, 2021
6e613ec
Comment more
suhacker1 Jan 2, 2021
7d12a30
Replace examples with new classifier
suhacker1 Jan 2, 2021
d6528e4
Update documentation
suhacker1 Jan 3, 2021
7495b62
Update tests with new MNIST model
suhacker1 Jan 3, 2021
2c64502
Replace classifier in synthesis tests
suhacker1 Jan 3, 2021
6b52729
Remove redundant space
suhacker1 Jan 3, 2021
bf52c11
Resolve linting issues
suhacker1 Jan 3, 2021
1eaa422
Attempt to fix copycat test errors
suhacker1 Jan 3, 2021
64eaff2
Remove test deadlines and failing assertion
suhacker1 Jan 3, 2021
413a784
Resolve linting errors
suhacker1 Jan 3, 2021
9d1a2cd
Merge commit 'refs/pull/59/head' of github.com:trailofbits/PrivacyRaven
pwang00 Jan 4, 2021
6fd52a2
Update examples
pwang00 Jan 4, 2021
09e1502
Merge remote-tracking branch 'upstream/master'
pwang00 Jan 4, 2021
385c774
Keep fork up to date
pwang00 Jan 4, 2021
82f34c9
Update examples
pwang00 Jan 4, 2021
0c553ff
Update examples
pwang00 Jan 4, 2021
9cc6a00
Final examples
pwang00 Jan 4, 2021
9bb8547
Remove create_model.py
pwang00 Jan 4, 2021
1dda97c
Remove create_model.py from README.md
pwang00 Jan 4, 2021
a9ecf01
Update all examples
pwang00 Jan 6, 2021
945e592
Test support for python3.6
pwang00 Jan 9, 2021
68d68da
Updated PrivacyRaven tests and added docker support
pwang00 Jan 15, 2021
4fb5cd5
Update Dockerfile to reflect directory changes
pwang00 Jan 15, 2021
b75bfef
Update directory structure
pwang00 Jan 15, 2021
721e49b
Update directory structure
pwang00 Jan 15, 2021
2c6feb2
Remove backups
pwang00 Jan 15, 2021
22d4bec
Update noxfile
pwang00 Jan 15, 2021
2b5aef9
Remove noxfile backup
pwang00 Jan 15, 2021
cb326d0
Update README.md
pwang00 Jan 15, 2021
4c581e3
Add Dockerfile and build script
pwang00 Jan 15, 2021
b45d74b
Update examples and requirements
pwang00 Jan 15, 2021
c5ede1a
Merge branch 'master' of github.com:pwang00/PrivacyRaven
pwang00 Jan 15, 2021
91516f8
Update examples to resolve GPU issues on colab
pwang00 Jan 16, 2021
bedf0fc
Merge branch 'master' into master
pwang00 Jan 16, 2021
9476cbf
Update comments
pwang00 Jan 16, 2021
79b303a
Merge branch 'master' of github.com:pwang00/PrivacyRaven
pwang00 Jan 16, 2021
dbfa358
Update example code
pwang00 Jan 18, 2021
01083ac
Merge remote-tracking branch 'upstream/master'
pwang00 Jan 19, 2021
b455fde
Change default arg for gpus
pwang00 Jan 19, 2021
2f54c8d
Update formatting to pass linting
pwang00 Jan 19, 2021
127438e
Fix merge conflict
pwang00 Mar 21, 2021
a938e12
Update README.md
pwang00 Mar 21, 2021
edae0a0
Fix conflicts
pwang00 Apr 1, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ The other classes of attacks can be launched in a similar fashion. See the `exam

1. Install [poetry](https://python-poetry.org/docs/).
2. Git clone this repository.
3. Run `poetry install`.
3. Run `poetry update`
4. Run `poetry install`.

If you'd like to use a Jupyter Notebook environment, run `poetry shell` followed by `jupyter notebook`.

Expand Down
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions src/privacyraven/extraction/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
from privacyraven.extraction.metrics import label_agreement
from privacyraven.extraction.synthesis import synthesize, synths
from privacyraven.models.pytorch import ImagenetTransferLearning
from privacyraven.utils.model_creation import (convert_to_inference,
set_hparams, train_and_test)
from privacyraven.utils.model_creation import (
convert_to_inference,
set_hparams,
train_and_test,
)
from privacyraven.utils.query import establish_query


Expand Down
58 changes: 58 additions & 0 deletions src/privacyraven/inversion/core.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
from privacyraven.models.four_layer import FourLayerClassifier
from privacyraven.models.victim import FourLayerClassifier
from privacyraven.utils.data import get_emnist_data

# Create a query function for a target PyTorch Lightning model
def query_mnist(input_data):
# PrivacyRaven provides built-in query functions
return get_target(model, input_data, (1, 28, 28, 1))

# Truncates a prediction vector such that the m highest values are preserved, and all others are set to 0.
# (Section 4.2 of )
def trunc(k, v):

# kth smallest element
b = sorted(v)[-k - 1]
nonzero = 0

for (i, vi) in enumerate(v):
if vi < b or (vi != 0 and nonzero > k): v[i] = 0
nonzero += 1

return v

def joint_train_inversion_model(
input_size = 784,
output_size = 10,
dataset_train = None,
dataset_test = None,
data_dimensions = (1, 28, 28, 1),
t = 2,
):

# The following is a proof of concept of Figure 4 from the paper
# "Neural Network Inversion in Adversarial Setting via Background Knowledge Alignment"
# We first train a classifier on a dataset to output a prediction vector

forward_model = train_four_layer_mnist_victim(
gpus=1,
input_size = input_size,
output_size = output_size
)

# This is nowhere near complete but
# The idea here is that we query the model each time
for k in range(len(dataset_train)):

# Fwx is the training vector outputted by our model Fw
Fwx = query_mnist(forward_model, input_data, data_dimensions)

# Let Fw_t denote the truncated vector
Fwx_t = trunc(t, Fwx)



if __name__ == "__main__":
emnist_train, emnist_test = get_emnist_data()

joint_train_inversion_model(dataset_train=emnist_train)
5 changes: 5 additions & 0 deletions src/privacyraven/membership_inf/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ class TransferMembershipInferenceAttack(object):
trainer_args = attr.ib(default=None)


<<<<<<< HEAD
def train_shadow_model(self):
return MLPClassifier(random_state=1, max_iter=300).fit(self.X, self.y)
=======
def __attrs_post_init__(self):
self.query = establish_query(self.query, self.victim_input_shape)

Expand All @@ -46,3 +50,4 @@ def __attrs_post_init__(self):
config = attr.asdict(self)
extract_args = config.values()
extraction = ModelExtractionAttack(*extract_args)
>>>>>>> 04904505fa8bf32ae3218c3e879da517be210e3b
7 changes: 5 additions & 2 deletions src/privacyraven/models/victim.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
from privacyraven.models.four_layer import FourLayerClassifier
from privacyraven.models.pytorch import ThreeLayerClassifier
from privacyraven.utils.data import get_mnist_loaders
from privacyraven.utils.model_creation import (convert_to_inference,
set_hparams, train_and_test)
from privacyraven.utils.model_creation import (
convert_to_inference,
set_hparams,
train_and_test,
)


def train_four_layer_mnist_victim(
Expand Down