Datasets:
license: cc-by-nc-4.0
task_categories:
- image-classification
tags:
- federated-learning
- differential-privacy
pretty_name: FLAIR
Federated Learning Annotated Image Repository (FLAIR): A large labelled image dataset for benchmarking in federated learning
FLAIR was published at NeurIPS 2022 (paper)
(Preferred) Benchmarking FLAIR is available in pfl-research (repo, paper).
The ml-flair repo contains a setup for benchmarking with TensorFlow Federated and notebooks for exploring data.
FLAIR is a large dataset of images that captures a number of characteristics encountered in federated learning (FL) and privacy-preserving ML tasks. This dataset comprises approximately 430,000 images from 51,000 Flickr users, which will better reflect federated learning problems arising in practice, and it is being released to aid research in the field.
Image Labels
These images have been annotated by humans and assigned labels from a taxonomy of more than 1,600 fine-grained labels. All main subjects present in the images have been labeled, so images may have multiple labels. The taxonomy is hierarchical where the fine-grained labels can be mapped to 17 coarse-grained categories. The dataset includes both fine-grained and coarse-grained labels so researchers can vary the complexity of a machine learning task.
User Labels and their use for Federated Learning
We have used image metadata to extract artist names/IDs for the purposes of creating user datasets for federated learning. While optimization algorithms for machine learning are often designed under the assumption that each example is an independent sample from the distribution, federated learning applications deviate from this assumption in a few different ways that are reflected in our user-annotated examples. Different users differ in the number of images they have, as well as the number of classes represented in their image collection. Further, images of the same class but taken by different users are likely to have some distribution shift. These properties of the dataset better reflect federated learning applications, and we expect that benchmark tasks on this dataset will benefit from algorithms designed to handle such data heterogeneity.
Dataset split
We include a standard train/val/test. The partition is based on user ids with ratio 8:1:1, i.e. train, val and test sets have disjoint users. Below are the numbers for each partition:
Partition | Train | Val | Test |
---|---|---|---|
Number of users | 41,131 | 5,141 | 5,142 |
Number of images | 345,879 | 39,239 | 43,960 |
We recommend using the provided split for reproducible benchmarks.
Dataset structure
{'user_id': '59769174@N00',
'image_id': 14913474848,
'labels': ['equipment', 'material', 'structure'],
'partition': 'train',
'fine_grained_labels': ['bag', 'document', 'furniture', 'material', 'printed_page'],
'image': <PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=256x256>}
Field image_id
is the Flickr PhotoID and user_id
is the Flickr NSID that owns the image.
Group by user_id
to construct a realistic heterogeneous federated dataset.
Field partition
denotes which train/dev/test
partition the image belongs to.
Field fine_grained_labels
is a list of annotated labels presenting the subjects in the image and labels
is the list of coarse-grained labels obtained by mapping fine-grained labels to higher-order categories.
The file label_relationship.txt
includes the mapping from ~1,600 fine-grained labels to 17 higher-order categories.
(Recommended) Benchmark FLAIR with pfl-research
Available at https://github.com/apple/pfl-research/tree/develop/benchmarks/flair.
Benchmark FLAIR with TensorFlow Federated
Available at https://github.com/apple/ml-flair. This repo also provide scripts to explore the images and labels in more detail.
Prepare the dataset in HDF5
We found a single HDF5 file to be efficient for FL. If you want to process the dataset for general usage in FL, we recommend using this preprocessing script to construct a HDF5 file.
By default the script will group the images and labels by train/val/test split and then by user ids, making it suitable for federated learning experiments.
With the flag --not_group_data_by_user
, the script will simply group the images and labels by train/val/test split and ignore the user ids, which is the typical setup for centralized training.
⚠️ Warning: the hdf5 file take up to ~80GB disk space to store after processing.
Use dataset directly with HuggingFace
The dataset can also be used with the datasets
package.
To group datapoints by user, simply construct a mapping and then query the dataset by index:
from datasets import load_dataset
from collections import defaultdict
ds = load_dataset('apple/flair', split='val')
user_to_ix = defaultdict(list)
for i, record in enumerate(ds):
user_to_ix[record['user_id']].append(i)
def load_user_data(user_id):
return [ds[i] for i in user_to_ix[user_id]]
load_user_data('81594342@N00')
Disclaimer
The annotations and Apple’s other rights in the dataset are licensed under CC-BY-NC 4.0 license. The images are copyright of the respective owners, the license terms of which can be found using the links provided in ATTRIBUTIONS.TXT (by matching the Image ID). Apple makes no representations or warranties regarding the license status of each image and you should verify the license for each image yourself.
Citing FLAIR
@article{song2022flair,
title={FLAIR: Federated Learning Annotated Image Repository},
author={Song, Congzheng and Granqvist, Filip and Talwar, Kunal},
journal={Advances in Neural Information Processing Systems},
volume={35},
pages={37792--37805},
year={2022}
}