Skip to content

Commit dff97d6

Browse files
committed
more multimodal datasets docs
1 parent 98500dc commit dff97d6

File tree

4 files changed

+229
-10
lines changed

4 files changed

+229
-10
lines changed

docs/hub/datasets-audio.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ A dataset with a supported structure and [file formats](./datasets-adding#file-f
66

77
---
88

9-
Additional information about your audio files - such as transcriptions - is automatically loaded as long as you include this information in a metadata file (`metadata.csv`/`metadata.jsonl`).
9+
Additional information about your audio files - such as transcriptions - is automatically loaded as long as you include this information in a metadata file (`metadata.csv`/`metadata.jsonl`/`metadata.parquet`).
1010

1111
Alternatively, audio files can be in Parquet files or in TAR archives following the [WebDataset](https://github.com/webdataset/webdataset) format.
1212

@@ -90,6 +90,8 @@ You can also use a [JSONL](https://jsonlines.org/) file `metadata.jsonl`:
9090
{"file_name": "4.wav","text": "dog"}
9191
```
9292

93+
And for bigger datasets or if you are interested in advanced data retrieval features, you can use a [Parquet](https://parquet.apache.org/) file `metadata.parquet`.
94+
9395
## Relative paths
9496

9597
Metadata file must be located either in the same directory with the audio files it is linked to, or in any parent directory, like in this example:
@@ -115,7 +117,9 @@ audio/3.wav,dog
115117
audio/4.wav,dog
116118
```
117119

118-
Metadata file cannot be put in subdirectories of a directory with the audio files.
120+
Metadata files cannot be put in subdirectories of a directory with the audio files.
121+
122+
More generally, any column named `file_name` or `*_file_name` should contain the full relative path to the audio files.
119123

120124
In this example, the `test` directory is used to setup the name of the training split. See [File names and splits](./datasets-file-names-and-splits) for more information.
121125

@@ -203,8 +207,9 @@ my_dataset_repository/
203207
└── train.parquet
204208
```
205209

206-
Audio columns are of type _struct_, with a binary field `"bytes"` for the audio data and a string field `"path"` for the image file name or path.
207-
You should specify the feature types of the columns directly in YAML in the README header, for example:
210+
Parquet files with audio data can be created using `pandas` or the `datasets` library. To create Parquet files with audio data in `pandas`, you can use [pandas-audio-methods](https://github.com/lhoestq/pandas-audio-methods) and `df.to_parquet()`. In `datasets`, you can set the column type to `Audio()` and use the `ds.to_parquet(...)` method or `ds.push_to_hub(...)`. You can find a guide on loading audio datasets in `datasets` [here](/docs/datasets/audio_load).
211+
212+
Alternatively you can manually set the audio type of Parquet created using other tools. First, make sure your audio columns are of type _struct_, with a binary field `"bytes"` for the audio data and a string field `"path"` for the audio file name or path. Then you should specify the feature types of the columns directly in YAML in the README header, for example:
208213

209214
```yaml
210215
dataset_info:
@@ -215,4 +220,4 @@ dataset_info:
215220
dtype: string
216221
```
217222
218-
Alternatively, Parquet files with Audio data can be created using the `datasets` library by setting the column type to `Audio()` and using the `.to_parquet(...)` method or `.push_to_hub(...)`. You can find a guide on loading audio datasets in `datasets` [here](../datasets/audio_load).
223+
Note that Parquet is recommended for small audio files (<1MB per audio file) and small row groups (100 rows per row group, which is what `datasets` uses for audio). For larger audio files it is recommended to use the WebDataset format, or to share the original audio files (optionally with metadata files).

docs/hub/datasets-image.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This guide will show you how to configure your dataset repository with image fil
44

55
A dataset with a supported structure and [file formats](./datasets-adding#file-formats) automatically has a Dataset Viewer on its page on the Hub.
66

7-
Additional information about your images - such as captions or bounding boxes for object detection - is automatically loaded as long as you include this information in a metadata file (`metadata.csv`/`metadata.jsonl`).
7+
Additional information about your images - such as captions or bounding boxes for object detection - is automatically loaded as long as you include this information in a metadata file (`metadata.csv`/`metadata.jsonl`/`metadata.parquet`).
88

99
Alternatively, images can be in Parquet files or in TAR archives following the [WebDataset](https://github.com/webdataset/webdataset) format.
1010

@@ -90,6 +90,8 @@ You can also use a [JSONL](https://jsonlines.org/) file `metadata.jsonl`:
9090
{"file_name": "4.jpg","text": "a cartoon ball with a smile on it's face"}
9191
```
9292

93+
And for bigger datasets or if you are interested in advanced data retrieval features, you can use a [Parquet](https://parquet.apache.org/) file `metadata.parquet`.
94+
9395
## Relative paths
9496

9597
Metadata file must be located either in the same directory with the images it is linked to, or in any parent directory, like in this example:
@@ -115,7 +117,9 @@ images/3.jpg,a red and white ball with an angry look on its face
115117
images/4.jpg,a cartoon ball with a smile on it's face
116118
```
117119

118-
Metadata file cannot be put in subdirectories of a directory with the images.
120+
Metadata files cannot be put in subdirectories of a directory with the images.
121+
122+
More generally, any column named `file_name` or `*_file_name` should contain the full relative path to the images.
119123

120124
## Image classification
121125

@@ -201,8 +205,9 @@ my_dataset_repository/
201205
└── train.parquet
202206
```
203207

204-
Image columns are of type _struct_, with a binary field `"bytes"` for the image data and a string field `"path"` for the image file name or path.
205-
You should specify the feature types of the columns directly in YAML in the README header, for example:
208+
Parquet files with image data can be created using `pandas` or the `datasets` library. To create Parquet files with image data in `pandas`, you can use [pandas-image-methods](https://github.com/lhoestq/pandas-image-methods) and `df.to_parquet()`. In `datasets`, you can set the column type to `Image()` and use the `ds.to_parquet(...)` method or `ds.push_to_hub(...)`. You can find a guide on loading image datasets in `datasets` [here](/docs/datasets/image_load).
209+
210+
Alternatively you can manually set the image type of Parquet created using other tools. First, make sure your image columns are of type _struct_, with a binary field `"bytes"` for the image data and a string field `"path"` for the image file name or path. Then you should specify the feature types of the columns directly in YAML in the README header, for example:
206211

207212
```yaml
208213
dataset_info:
@@ -213,4 +218,4 @@ dataset_info:
213218
dtype: string
214219
```
215220
216-
Alternatively, Parquet files with Image data can be created using the `datasets` library by setting the column type to `Image()` and using the `.to_parquet(...)` method or `.push_to_hub(...)`. You can find a guide on loading image datasets in `datasets` [here](/docs/datasets/image_load).
221+
Note that Parquet is recommended for small images (<1MB per image) and small row groups (100 rows per row group, which is what `datasets` uses for images). For larger images it is recommended to use the WebDataset format, or to share the original image files (optionally with metadata files).

docs/hub/datasets-video.md

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
# Video Dataset
2+
3+
This guide will show you how to configure your dataset repository with video files. You can find accompanying examples of repositories in this [Video datasets examples collection](https://huggingface.co/collections/datasets-examples/video-dataset-6568e7cf28639db76eb92d65).
4+
5+
A dataset with a supported structure and [file formats](./datasets-adding#file-formats) automatically has a Dataset Viewer on its page on the Hub.
6+
7+
Additional information about your videos - such as captions or bounding boxes for object detection - is automatically loaded as long as you include this information in a metadata file (`metadata.csv`/`metadata.jsonl`/`metadata.parquet`).
8+
9+
Alternatively, videos can be in Parquet files or in TAR archives following the [WebDataset](https://github.com/webdataset/webdataset) format.
10+
11+
12+
## Only videos
13+
14+
If your dataset only consists of one column with videos, you can simply store your video files at the root:
15+
16+
```
17+
my_dataset_repository/
18+
├── 1.mp4
19+
├── 2.mp4
20+
├── 3.mp4
21+
└── 4.mp4
22+
```
23+
24+
or in a subdirectory:
25+
26+
```
27+
my_dataset_repository/
28+
└── videos
29+
├── 1.mp4
30+
├── 2.mp4
31+
├── 3.mp4
32+
└── 4.mp4
33+
```
34+
35+
Multiple [formats](./datasets-adding#file-formats) are supported at the same time, including PNG, JPEG, TIFF and WebP.
36+
37+
```
38+
my_dataset_repository/
39+
└── videos
40+
├── 1.mp4
41+
├── 2.png
42+
├── 3.tiff
43+
└── 4.webp
44+
```
45+
46+
If you have several splits, you can put your videos into directories named accordingly:
47+
48+
```
49+
my_dataset_repository/
50+
├── train
51+
│   ├── 1.mp4
52+
│   └── 2.mp4
53+
└── test
54+
├── 3.mp4
55+
└── 4.mp4
56+
```
57+
58+
See [File names and splits](./datasets-file-names-and-splits) for more information and other ways to organize data by splits.
59+
60+
## Additional columns
61+
62+
If there is additional information you'd like to include about your dataset, like text captions or bounding boxes, add it as a `metadata.csv` file in your repository. This lets you quickly create datasets for different computer vision tasks like [video generation](https://huggingface.co/tasks/text-to-video) or [object detection](https://huggingface.co/tasks/object-detection).
63+
64+
```
65+
my_dataset_repository/
66+
└── train
67+
├── 1.mp4
68+
├── 2.mp4
69+
├── 3.mp4
70+
├── 4.mp4
71+
└── metadata.csv
72+
```
73+
74+
Your `metadata.csv` file must have a `file_name` column which links video files with their metadata:
75+
76+
```csv
77+
file_name,text
78+
1.mp4,an animation of a green pokemon with red eyes
79+
2.mp4,a short video of a green and yellow toy with a red nose
80+
3.mp4,a red and white ball shows an angry look on its face
81+
4.mp4,a cartoon ball is smiling
82+
```
83+
84+
You can also use a [JSONL](https://jsonlines.org/) file `metadata.jsonl`:
85+
86+
```jsonl
87+
{"file_name": "1.mp4","text": "an animation of a green pokemon with red eyes"}
88+
{"file_name": "2.mp4","text": "a short video of a green and yellow toy with a red nose"}
89+
{"file_name": "3.mp4","text": "a red and white ball shows an angry look on its face"}
90+
{"file_name": "4.mp4","text": "a cartoon ball is smiling"}
91+
```
92+
93+
And for bigger datasets or if you are interested in advanced data retrieval features, you can use a [Parquet](https://parquet.apache.org/) file `metadata.parquet`.
94+
95+
## Relative paths
96+
97+
Metadata file must be located either in the same directory with the videos it is linked to, or in any parent directory, like in this example:
98+
99+
```
100+
my_dataset_repository/
101+
└── train
102+
├── videos
103+
│   ├── 1.mp4
104+
│   ├── 2.mp4
105+
│   ├── 3.mp4
106+
│   └── 4.mp4
107+
└── metadata.csv
108+
```
109+
110+
In this case, the `file_name` column must be a full relative path to the videos, not just the filename:
111+
112+
```csv
113+
file_name,text
114+
videos/1.mp4,an animation of a green pokemon with red eyes
115+
videos/2.mp4,a short video of a green and yellow toy with a red nose
116+
videos/3.mp4,a red and white ball shows an angry look on its face
117+
videos/4.mp4,a cartoon ball is smiling
118+
```
119+
120+
Metadata files cannot be put in subdirectories of a directory with the videos.
121+
122+
More generally, any column named `file_name` or `*_file_name` should contain the full relative path to the videos.
123+
124+
## Video classification
125+
126+
For video classification datasets, you can also use a simple setup: use directories to name the video classes. Store your video files in a directory structure like:
127+
128+
```
129+
my_dataset_repository/
130+
├── green
131+
│   ├── 1.mp4
132+
│   └── 2.mp4
133+
└── red
134+
├── 3.mp4
135+
└── 4.mp4
136+
```
137+
138+
The dataset created with this structure contains two columns: `video` and `label` (with values `green` and `red`).
139+
140+
You can also provide multiple splits. To do so, your dataset directory should have the following structure (see [File names and splits](./datasets-file-names-and-splits) for more information):
141+
142+
```
143+
my_dataset_repository/
144+
├── test
145+
│   ├── green
146+
│   │   └── 2.mp4
147+
│   └── red
148+
│   └── 4.mp4
149+
└── train
150+
├── green
151+
│   └── 1.mp4
152+
└── red
153+
└── 3.mp4
154+
```
155+
156+
You can disable this automatic addition of the `label` column in the [YAML configuration](./datasets-manual-configuration). If your directory names have no special meaning, set `drop_labels: true` in the README header:
157+
158+
```yaml
159+
configs:
160+
- config_name: default # Name of the dataset subset, if applicable.
161+
drop_labels: true
162+
```
163+
164+
## Large scale datasets
165+
166+
### WebDataset format
167+
168+
The [WebDataset](./datasets-webdataset) format is well suited for large scale video datasets.
169+
It consists of TAR archives containing videos and their metadata and is optimized for streaming. It is useful if you have a large number of videos and to get streaming data loaders for large scale training.
170+
171+
```
172+
my_dataset_repository/
173+
├── train-0000.tar
174+
├── train-0001.tar
175+
├── ...
176+
└── train-1023.tar
177+
```
178+
179+
To make a WebDataset TAR archive, create a directory containing the videos and metadata files to be archived and create the TAR archive using e.g. the `tar` command.
180+
The usual size per archive is generally around 1GB.
181+
Make sure each video and metadata pair share the same file prefix, for example:
182+
183+
```
184+
train-0000/
185+
├── 000.mp4
186+
├── 000.json
187+
├── 001.mp4
188+
├── 001.json
189+
├── ...
190+
├── 999.mp4
191+
└── 999.json
192+
```
193+
194+
Note that for user convenience and to enable the [Dataset Viewer](./datasets-viewer), every dataset hosted in the Hub is automatically converted to Parquet format up to 5GB. Since videos can be quite large, the URLs to the videos are stored in the converted Parquet data without the video bytes themselves. Read more about it in the [Parquet format](./datasets-viewer#access-the-parquet-files) documentation.

docs/hub/datasets-webdataset.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,21 @@ Labels and metadata can be in a `.json` file, in a `.txt` (for a caption, a desc
1818
A large scale WebDataset is made of many files called shards, where each shard is a TAR archive.
1919
Each shard is often ~1GB but the full dataset can be multiple terabytes!
2020

21+
## Multimodal support
22+
23+
WebDataset is designed for multimodal datasets, i.e. for image, audio and/or video datasets.
24+
25+
Indeed since media files tend to be quite big, the sequential I/O of WebDataset enables large reads and buffering. This results in obtaining the best data loading speed.
26+
27+
Here is a non-exhaustive list of supported data formats:
28+
29+
- image: jpeg, png, tiff
30+
- audio: mp3, m4a, wav, flac
31+
- video: mp4, mov, avi
32+
- other: npy, npz
33+
34+
The full list evolves over time and depends on the implementation. For examoke you can can find which formats the `webdataset` package supports in the source code [here](https://github.com/webdataset/webdataset/blob/main/webdataset/autodecode.py).
35+
2136
## Streaming
2237

2338
Streaming TAR archives is fast because it reads contiguous chunks of data.

0 commit comments

Comments
 (0)