Dataset Viewer

The dataset viewer is not available because its heuristics could not detect any supported data files. You can try uploading some data files, or configuring the data files location manually.

Dataset Inference: which subsets 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 1,200 subsets of 54 images. Every subset was either used entirely to train the classifier (a member) or not at all (a non-member); exactly half are members. Your job is to give every subset a score that is higher when the subset is more likely a member. This is dataset inference: combining weak per-image evidence over a whole set of images.

No membership labels are given for any subset. Scores are evaluated by TPR at 5% FPR and ranked on a Kaggle leaderboard (see Submitting).

Quick start

The whole session is one notebook, dataset_inference_tutorial.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 dataset_inference_tutorial.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-dataset-inference", 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 torchvision numpy scipy matplotlib jupyter huggingface_hub
python -c "from huggingface_hub import snapshot_download; snapshot_download(repo_id='SprintML/ml-in-pl-dataset-inference', repo_type='dataset', local_dir='data')"
cd data
jupyter lab dataset_inference_tutorial.ipynb

The download contains the notebook next to the data; open it from inside data/. Tested with Python 3.12 and PyTorch 2.6; PyTorch 2.3 or newer is needed. A GPU is needed for the slower cells (about 65,000 images are passed through the network several times).

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.

Files

file content
test_images.npy the images of all 1,200 subsets: uint8, shape (64800, 64, 64, 3) (759 MB)
test_labels.npy the true tissue class (0 to 8) of every image: int64, shape (64800,)
test_subset_ids.npy the subset each image belongs to: int64, shape (64800,); 1,200 subsets of 54 images, exactly 6 per class
class_names.json the 9 class names
model_classifier.pt the trained classifier (PyTorch state_dict, 43 MB), see below
sample_submission.csv the submission format: columns subset_id,membership
shadow_outputs.npz outputs of 8 precomputed shadow models (used in Part 10): logits (64800, 8, 9) float32, in_mask (64800, 8) bool (True where that shadow model trained on the image), model_names (17 MB)
aux_images.npy, aux_labels.npy an auxiliary set: 25,300 extra labelled images from the same distribution, uint8 (25300, 64, 64, 3) and int64 (25300,). The classifier never saw them (not for training, not in any subset). The classes are unevenly represented. Optional, see Part 10 (311 MB)
dataset_inference_tutorial.ipynb the starter notebook

All images are 64 x 64 RGB. Row i of every per-image array belongs to image i. To work with subsets:

import numpy as np
subset_ids = np.load("data/test_subset_ids.npy")
ids, inv = np.unique(subset_ids, return_inverse=True)     # inv[i] = index of the subset of image i

The classifier

A ResNet-18 adapted to small images: 3x3 stem convolution with stride 1, no max-pooling, BatchNorm, global average pooling and a linear layer with 9 outputs (11.2 million parameters).

import torch, torch.nn as nn, torchvision
model = torchvision.models.resnet18(num_classes=9)
model.conv1 = nn.Conv2d(3, 64, kernel_size=3, stride=1, padding=1, bias=False)
model.maxpool = nn.Identity()
model.load_state_dict(torch.load("data/model_classifier.pt", map_location="cpu"))
model.eval()

Input: pixels scaled to [0, 1], then normalised per channel with mean (0.7406, 0.5331, 0.7059) and standard deviation (0.1510, 0.2066, 0.1477).

Training recipe: from scratch, 30 epochs, SGD with momentum 0.9, learning rate 0.1 with cosine decay to 0, weight decay 5e-4, batch size 128, cross-entropy loss, no data augmentation, no differential privacy. It was trained on images from the same distribution as the subsets. Which images exactly is what you have to find out.

The data

The images come from the public NCT-CRC-HE-100K collection of histology patches of human colorectal cancer and healthy tissue (Kather, Halama and Marx, 2018), resized from 224 x 224 to 64 x 64 pixels. The 9 classes are ADI (adipose), BACK (background), DEB (debris), LYM (lymphocytes), MUC (mucus), MUS (smooth muscle), NORM (normal colon mucosa), STR (cancer-associated stroma) and TUM (colorectal adenocarcinoma epithelium).

Submitting

Write a CSV with one row per subset id:

subset_id,membership
0,0.511822
1,0.950464
...
  • one finite number per subset, every subset_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 subsets (many identical scores hurt the metric);
  • the notebook has a helper that writes and checks this file for you (Part 7).

Submit submission.csv on the competition page: https://www.kaggle.com/competitions/dataset-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. A subset is flagged if its score is at least a threshold. The metric is the fraction of member subsets that are flagged when at most 5% of the non-member subsets are wrongly flagged. The leaderboard you see during the session uses only a part (30%) of the subsets; the final ranking uses the other 70%, which stays hidden until the end. The notebook (Part 6) explains why the public number is noisy.

What you should not do

Do not try to obtain the membership labels (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

  • competition data 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: use a smaller batch size in the cell that computes input gradients (Part 8) and restart the runtime to free memory.
  • Colab disconnects: the free runtime stops after inactivity; save intermediate results (for example your scores with np.save).

License, source and citation

  • The data are derived from NCT-CRC-HE-100K, released under Creative Commons Attribution 4.0 International (CC BY 4.0): Kather, J. N., Halama, N., Marx, A. (2018), 100,000 histological images of human colorectal cancer and healthy tissue, Zenodo, https://doi.org/10.5281/zenodo.1214456. The images were resized to 64 x 64 pixels. If you use them, please credit the original authors.
  • The classifier weights, the shadow-model outputs 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
203