Dataset Viewer
Auto-converted to Parquet Duplicate
Search is not available for this dataset
id
int64
4
28k
score
float64
0.5
0.5
16,510
0.5
14,446
0.5
4,706
0.5
3,952
0.5
6,876
0.5
25,806
0.5
17,297
0.5
6,626
0.5
15,608
0.5
18,662
0.5
7,520
0.5
6,275
0.5
27,848
0.5
27,597
0.5
4,737
0.5
16,450
0.5
16,497
0.5
20,542
0.5
13,860
0.5
1,102
0.5
23,451
0.5
3,896
0.5
12,256
0.5
11,398
0.5
18,918
0.5
21,208
0.5
19,298
0.5
19,897
0.5
6,659
0.5
21,489
0.5
4,184
0.5
22,509
0.5
24,585
0.5
25,490
0.5
1,658
0.5
20,261
0.5
1,106
0.5
1,980
0.5
8,199
0.5
25,374
0.5
19,578
0.5
24,882
0.5
21,123
0.5
3,591
0.5
25,417
0.5
22,244
0.5
9,138
0.5
22,364
0.5
979
0.5
14,448
0.5
4,604
0.5
6,378
0.5
15,195
0.5
20,120
0.5
17,713
0.5
21,015
0.5
5,691
0.5
25,592
0.5
7,464
0.5
16,832
0.5
16,417
0.5
6,034
0.5
26,486
0.5
23,928
0.5
22,768
0.5
18,264
0.5
2,361
0.5
17,680
0.5
15,960
0.5
18,105
0.5
20,243
0.5
4,074
0.5
27,664
0.5
1,654
0.5
20,775
0.5
20,013
0.5
11,925
0.5
9,474
0.5
18,279
0.5
27,011
0.5
5,750
0.5
22,866
0.5
5,034
0.5
15,109
0.5
3,805
0.5
10,108
0.5
17,071
0.5
23,920
0.5
19,342
0.5
17,665
0.5
5,432
0.5
16,171
0.5
9,879
0.5
3,174
0.5
25,032
0.5
16,410
0.5
3,136
0.5
14,748
0.5
5,352
0.5
24,167
0.5
End of preview. Expand in Data Studio

Membership Inference: which images trained the model?

Participant data and starter notebook for the hands-on part of the Security tutorial at ML in PL.

You are given a trained image classifier with its weights and 28,000 images in two files of 14,000 images each. The classifier was trained on 15,000 images, 14,000 of which are among these 28,000. Every image was either used to train the classifier (a member) or never seen by it (a non-member); in each file exactly half of the images are members. In pub.pt the membership is given. In priv.pt it is hidden, and your job is to give every priv image a score that is higher when the image is more likely a member. This is membership inference.

Scores are evaluated by TPR at 5% FPR and ranked on a Kaggle leaderboard (see Submitting).

Quick start

The whole session is one notebook, membership-inference-starter.ipynb (in this repository). It explains everything step by step and contains the exercises. A GPU is needed; a free Colab T4 is enough.

Google Colab

  1. Download membership-inference-starter.ipynb from the Files tab of this page and open it in Colab (File > Upload notebook).
  2. Select a GPU runtime (Runtime > Change runtime type > T4 GPU).
  3. Download the data into data/ (the notebook has this cell in Part 0), or run it once yourself:
    import os
    os.system("pip -q install huggingface_hub")
    from huggingface_hub import snapshot_download
    snapshot_download(repo_id="SprintML/ml-in-pl-mia", repo_type="dataset", local_dir="data")
    
  4. Run the notebook from the top. It finds the files in data/.

Your own machine

pip install torch numpy scipy scikit-learn matplotlib jupyter huggingface_hub
python -c "from huggingface_hub import snapshot_download; snapshot_download(repo_id='SprintML/ml-in-pl-mia', repo_type='dataset', local_dir='data')"
cd data
jupyter lab membership-inference-starter.ipynb

The download contains the notebook next to the data; open it from inside data/. Tested with Python 3.11 and PyTorch 2.6; PyTorch 2.3 or newer is needed. A GPU is needed for the slower cells (the notebook trains 2 more ResNet-18 shadow models on 10,000 images each).

Kaggle Notebooks

Add the competition data with Add Input; nothing needs to be downloaded. A free Kaggle account works, but make sure you have verified your identity to use the GPU and other Kaggle resources. The optional differential-privacy part (Part 9) installs opacus and therefore needs Internet switched on in the notebook settings; the rest of the notebook does not.

Files

file content
pub.pt 14,000 images with known membership: id, image, label, membership (43 MB)
priv.pt 14,000 images with hidden membership: the same keys, membership is None. This is the set you score (43 MB)
model.pt the trained classifier (PyTorch state_dict, 45 MB), see below
shadow_0.npz to shadow_5.npz 6 precomputed shadow models (used in Part 5): each file has logits, float32 (28000, 10), the model's outputs on all 28,000 images (pub first, then priv), and member, bool (28000,), True where that shadow model trained on the image (1.1 MB each)
sample_submission.csv the submission format: columns id,score (134 KB)
membership-inference-starter.ipynb the starter notebook

pub.pt and priv.pt are dictionaries saved with torch.save; load them with torch.load(path, weights_only=True):

key pub.pt priv.pt
id int64, shape (14000,) int64, shape (14000,)
image uint8, shape (14000, 32, 32, 3) uint8, shape (14000, 32, 32, 3)
label int64, shape (14000,), class 0 to 9 int64, shape (14000,), class 0 to 9
membership int64, shape (14000,), 1 = member, 0 = non-member None

All images are 32 x 32 RGB. Row i of every array belongs to image i. The rows are shuffled with a fixed seed: the position of a row carries no information about membership.

import torch

pub = torch.load("data/pub.pt", weights_only=True)
priv = torch.load("data/priv.pt", weights_only=True)
print(pub["image"].shape, int(pub["membership"].sum()), priv["membership"])      # torch.Size([14000, 32, 32, 3])  7000  None

The classifier

A ResNet-18 adapted to small images: 3x3 stem convolution with stride 1, no max-pooling, GroupNorm instead of BatchNorm, global average pooling and a linear layer with 10 outputs (11.2 million parameters). The class ResNet18 is defined in Part 1 of the notebook; model.pt is its state_dict:

model = ResNet18()                      # copy the class from Part 1 of the notebook
model.load_state_dict(torch.load("data/model.pt", map_location="cpu", weights_only=True))
model.eval()

Input: pixels scaled to [0, 1], then normalised per channel with mean (0.4914, 0.4822, 0.4465) and standard deviation (0.2470, 0.2435, 0.2616).

Training recipe: from scratch, 60 epochs, SGD with Nesterov momentum 0.9, learning rate 0.05 with cosine decay, batch size 256, cross-entropy loss, no data augmentation, no weight decay, no differential privacy. It was trained on 15,000 images from the same distribution as pub and priv. Which images exactly is what you have to find out.

The data

The images come from the public CIFAR-10 collection (Krizhevsky, 2009): 32 x 32 colour images in 10 classes. The training and test images were pooled and split at random into the member and non-member images of this challenge; label is the CIFAR-10 class index from 0 to 9.

Submitting

Write a CSV with one row per priv image:

id,score
0,0.511822
1,0.950464
...
  • one finite number in [0, 1] for every id of sample_submission.csv exactly once; higher = more likely a member;
  • scores need not be probabilities; do not submit hard 0/1 values, the metric ranks the images (many identical scores hurt the metric);
  • the notebook has a helper that writes and checks this file for you (Part 2).

Submit submission.csv on the competition page: https://www.kaggle.com/competitions/membership-inference (it opens when the organizers launch the competition; you need a free Kaggle account and have to accept the rules). You can submit up to 25 times per day.

Metric: TPR at 5% FPR. An image is flagged if its score is at least a threshold. The metric is the share of members that are flagged when at most 5% of the non-members are wrongly flagged. The leaderboard you see during the session uses only a part (30%) of the priv images (4,200 images); the final ranking uses the other 70% (9,800 images), which stays hidden until the end. The notebook (Part 2) explains why the public number is noisy.

What you should not do

Do not try to obtain the membership labels of priv (for example by probing the leaderboard with many submissions): submissions are limited and the final ranking uses the hidden part. The aim of the session is to learn how such attacks work and what they can and cannot show.

Troubleshooting

  • pub.pt not found: the notebook looks for the files in data/, in the current folder, in /content/data/ and under /kaggle/input/. Run the download first, and open the notebook from inside data/ (own machine) or upload it to Colab next to the data/ folder.
  • Out of memory on the GPU: restart the runtime to free memory; in the differential-privacy part (Part 9) lower the batch size in the settings cell.
  • Training the missing shadow models takes too long (Part 5): free GPUs can be several times slower than a workstation GPU (about 8 minutes per model). Six shadow models come with the data; set N_SHADOWS = 6 in the settings cell to train none, or stop the cell and the finished ones are kept.
  • Colab disconnects: the free runtime stops after inactivity; save intermediate results (for example your scores with np.save).

License, source and citation

  • The images are derived from CIFAR-10: Krizhevsky, A. (2009), Learning Multiple Layers of Features from Tiny Images, https://www.cs.toronto.edu/~kriz/cifar.html. The source does not state a license. If you use the images, please credit the original authors.
  • The classifier weights and the notebook were produced for this tutorial and are provided for educational use.

Organizers

Organizers of the Security tutorial at ML in PL.

Downloads last month
59