VL-Adapter-datasets / README.md
ylsung's picture
Squash history: VL-Adapter CLIP-RN101 features and annotations
d983c92
|
Raw History Blame Contribute Delete
6.95 kB
---
license: mit
language:
- en
pretty_name: VL-Adapter Datasets (CLIP-RN101 features)
size_categories:
- 100K<n<1M
task_categories:
- visual-question-answering
- image-to-text
tags:
- vl-adapter
- vl-bart
- vl-t5
- clip
- vqa
- gqa
- nlvr2
- coco-captions
- parameter-efficient-fine-tuning
configs:
- config_name: COCO
data_files:
- split: train
path: features/COCO/data_clip_RN101_att/part-*.parquet
- config_name: GQA
data_files:
- split: train
path: features/GQA/data_clip_RN101_att/part-*.parquet
- config_name: VG
data_files:
- split: train
path: features/VG/data_clip_RN101_att/part-*.parquet
- config_name: nlvr
data_files:
- split: train
path: features/nlvr/data_clip_RN101_att/part-*.parquet
---
# VL-Adapter Datasets
Processed CLIP-ResNet101 grid features and annotations for
[**VL-Adapter: Parameter-Efficient Transfer Learning for Vision-and-Language Tasks**](https://arxiv.org/abs/2112.06825)
(Sung, Cho, Bansal — CVPR 2022), code at [ylsung/VL_adapter](https://github.com/ylsung/VL_adapter).
This repository replaces the original Google Drive download, which is no longer
available. It holds the same data in a Hub-native layout, plus a script that
rebuilds the exact `datasets/` directory tree the training code expects.
## Quick start — rebuild the original `datasets/` tree
```bash
pip install huggingface_hub pyarrow h5py numpy
wget https://huggingface.co/datasets/ylsung/VL-Adapter-datasets/raw/main/restore_datasets.py
python restore_datasets.py --out ./datasets
```
This downloads one shard at a time and deletes it after expanding, so it needs
less than ~1 GB of scratch space beyond the final tree. It is resumable — rerun
it and it skips what is already on disk. Budget **~47 GB of download** and
**~132 GB for the restored tree** (the `.h5` files are uncompressed).
To restore a subset:
```bash
python restore_datasets.py --out ./datasets --datasets GQA --datasets nlvr
python restore_datasets.py --out ./datasets --only annotations
```
## Using the features directly
If you just want the features and not the VL-Adapter directory layout:
```python
from datasets import load_dataset
ds = load_dataset("ylsung/VL-Adapter-datasets", "GQA", split="train", streaming=True)
row = next(iter(ds))
row["id"] # '2336439' -> the image id
row["features"] # (49, 2048) float16 CLIP-RN101 attention-pool grid features
```
Shards are written with 128-row row groups, so reading a single row costs about
an 8.6 MB fetch rather than the whole 275 MB shard — measured at ~5 s to the
first row, against ~9 minutes when the shards were a single row group.
Streaming a full pass still transfers everything, so for repeated training runs
restore the tree once with `restore_datasets.py` rather than streaming it each
epoch.
## Contents
| Path | Rows / files | Download | Restored | Notes |
|---|---|---|---|---|
| `features/COCO/data_clip_RN101_att/` | 245,496 | 16.5 GB | 49.9 GB | train2014 82,783 · val2014 40,504 · test2015 122,209 |
| `features/GQA/data_clip_RN101_att/` | 148,854 | 10.1 GB | 30.2 GB | |
| `features/VG/data_clip_RN101_att/` | 108,079 | 7.3 GB | 22.0 GB | |
| `features/nlvr/data_clip_RN101_att/` | 119,354 | 7.9 GB | 24.3 GB | NLVR2 train/dev/test1 |
| `annotations/` | 43 files | 5.7 GB | 5.7 GB | verbatim copies of the original JSON/TXT/PY files |
| `manifest.json.gz` | — | small | — | every original path with its size and CRC-32, used to verify a restore |
| **total** | | **47.4 GB** | **132 GB** | |
"Download" is the zstd-compressed parquet on the Hub; "Restored" is the
uncompressed `.h5` tree that `restore_datasets.py` writes. Restoring a single
dataset costs only its own row — `--datasets GQA` needs 30.2 GB, not 132 GB.
### Feature schema
Each row is one image:
| column | type | meaning |
|---|---|---|
| `id` | `string` | image id — the `.h5` filename stem and the HDF5 group name |
| `features` | `fixed_size_list<fixed_size_list<float16>[2048]>[49]` | CLIP-RN101 attention-pool grid features, shape `(49, 2048)` |
In the original release each of these rows was a standalone `.h5` file holding a
single group named `id` with one `(49, 2048)` float16 dataset called `features`.
621,783 such files exceed the Hub's recommended limits (<100k files per repo,
<10k per folder), so they are packed into 154 zstd-compressed parquet shards of
4,096 rows each, subdivided into 128-row row groups. `restore_datasets.py` unpacks them back to identical `.h5`
files — the arrays it writes are bit-exact and the files are the same 203,136
bytes; only an internal HDF5 heap offset differs.
### Annotations
`annotations/` mirrors the original folder layout byte-for-byte
(`annotations/vqa/karpathy_train.json` → `datasets/vqa/karpathy_train.json`).
They are left as raw JSON rather than converted to parquet because their schemas
vary widely and the training code parses them directly.
`annotations/GQA/paragraph_testdev.json` is 0 bytes, and
`COCO/clip_features/data_clip_RN101_fc/` and `paragraphs/` are empty, in the
original release too.
## NLVR2 images are not included
The original archive also contained 119,354 NLVR2 photographs. The NLVR2 authors
do not own their copyright and [ask that they not be shared
publicly](https://github.com/lil-lab/nlvr/tree/master/nlvr2), so only the CLIP
features derived from them are published here.
Every script under `VL-T5/scripts/image/` reads `clip_features` and runs without
the images. They are needed only for the end-to-end pixel training paths
(`VL-T5/src/*_raw_data.py`). Request them from the
[NLVR2 repository](https://github.com/lil-lab/nlvr/tree/master/nlvr2) and place
them at `datasets/nlvr/images/`.
Raw COCO, GQA and Visual Genome images are likewise not included; get them from
[COCO](https://cocodataset.org/#download),
[GQA](https://cs.stanford.edu/people/dorarad/gqa/download.html) and
[Visual Genome](https://homes.cs.washington.edu/~ranjay/visualgenome/api.html).
## Extracting your own features
See [`feature_extraction/`](https://github.com/ylsung/VL_adapter/tree/main/feature_extraction)
in the code repository to build features for other CLIP backbones.
## Licensing
The packaging code and the VL-Adapter project are MIT licensed. The underlying
annotations and images keep the licenses of their original sources —
[MS COCO](https://cocodataset.org/#termsofuse),
[Visual Genome](https://homes.cs.washington.edu/~ranjay/visualgenome/api.html),
[GQA](https://cs.stanford.edu/people/dorarad/gqa/about.html),
[VQA v2](https://visualqa.org/terms.html) and
[NLVR2](https://github.com/lil-lab/nlvr/tree/master/nlvr2) — and the derived
features are released for research use on the same terms.
## Citation
```bibtex
@inproceedings{sung2022vladapter,
title = {VL-Adapter: Parameter-Efficient Transfer Learning for Vision-and-Language Tasks},
author = {Yi-Lin Sung, Jaemin Cho, Mohit Bansal},
booktitle = {CVPR},
year = {2022}
}
```