File size: 5,195 Bytes
637d7d0
 
 
 
 
 
 
 
 
 
 
e225ea6
 
5ac28af
637d7d0
 
 
 
 
 
 
 
 
 
 
e225ea6
637d7d0
 
 
271d59e
e225ea6
 
 
271d59e
637d7d0
e225ea6
5ac28af
 
637d7d0
e225ea6
5ac28af
 
 
637d7d0
e225ea6
637d7d0
5ac28af
637d7d0
 
5ac28af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
637d7d0
 
271d59e
637d7d0
5ac28af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
637d7d0
 
 
 
271d59e
e225ea6
 
637d7d0
e225ea6
637d7d0
 
271d59e
 
637d7d0
e225ea6
 
 
 
 
 
 
 
 
 
637d7d0
 
 
 
 
 
 
e225ea6
 
637d7d0
 
 
 
271d59e
 
 
 
5ac28af
 
 
 
 
 
 
271d59e
 
 
 
5ac28af
 
 
 
 
271d59e
 
637d7d0
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
---
license: mit
pretty_name: Bouncing Balls
task_categories:
  - video-classification
tags:
  - synthetic
  - video
  - bouncing-balls
  - physics
  - colorful
  - multi-object
  - collision
  - webdataset
size_categories:
  - 1K<n<10K
configs:
  - config_name: default
    data_files:
      - split: train
        path: data/train-*.parquet
---

# Bouncing Balls

A synthetic dataset of **3,000 videos**, each showing **3–5 smaller, differently colored balls** bouncing around a square.

## Dataset summary

- **Videos:** 3,000 MP4 clips
- **Balls per video:** 3, 4, or 5
- **Total ball instances:** 12,087
- **Ball radius:** 7–12 pixels
- **Resolution:** **196 × 196 pixels**
- **Duration:** 24 frames at 12 fps (2 seconds per clip)
- **Motion:** straight-line movement, wall bounces, and elastic ball-to-ball collisions
- **Parquet:** 10 shards with 300 videos per shard
- **WebDataset:** 9 train shards (2,700 videos) and 3 validation shards (300 videos)
- **Generation seed:** 42
- **Raw MP4 size:** approximately 26.3 MiB
- **Parquet size:** approximately 26.8 MiB
- **WebDataset size:** approximately 31.5 MiB
- **Complete dataset size:** approximately 86.8 MiB

Ball colors are sampled in HSV space to keep them bright and saturated. Hues are spaced within each video to make the balls visually distinct. Initial positions are sampled without overlap.

## Folder structure

```text
.
├── data/                              # Parquet version (all 3,000 videos)
│   ├── train-00000-of-00010.parquet
│   ├── ...
│   └── train-00009-of-00010.parquet
├── videos/                            # Original MP4 files
│   ├── 000000.mp4
│   ├── ...
│   └── 002999.mp4
├── wds/                               # WebDataset version
│   ├── train/                         # 2,700 videos: 000000–002699
│   │   ├── bouncing-balls-train-000000.tar
│   │   ├── ...
│   │   └── bouncing-balls-train-000008.tar
│   └── val/                           # 300 videos: 002700–002999
│       ├── bouncing-balls-val-000000.tar
│       ├── ...
│       └── bouncing-balls-val-000002.tar
├── metadata.jsonl                     # One metadata record per raw MP4
└── scripts/
    ├── generate_bouncing_balls.py
    ├── shard_bouncing_balls.py        # Parquet sharding
    ├── shard_bouncing_balls_wds.py    # WebDataset sharding
    └── requirements.txt
```

The Parquet shards are self-contained: MP4 bytes and metadata are embedded together. The original MP4 files are also included under `videos/` for direct use. `metadata.jsonl` contains one record per raw video, keyed by `file_name`.

## WebDataset shards

The `wds/` directory contains uncompressed WebDataset `.tar` archives:

| Split | Tar files | Videos | Videos per shard | Video keys |
|---|---:|---:|---:|---|
| train | 9 | 2,700 | 300 | `000000`–`002699` |
| val | 3 | 300 | 100 | `002700`–`002999` |

Each tar member is named `<key>.mp4`, for example `000000.mp4`. Metadata is not duplicated inside the tar files; use `metadata.jsonl` or the Parquet version for the ball annotations.

For a VideoSAUR-style configuration, the shard patterns are:

```text
dataset.train_shards=/path/to/bouncing-balls/wds/train/bouncing-balls-train-{000000..000008}.tar
dataset.val_shards=/path/to/bouncing-balls/wds/val/bouncing-balls-val-{000000..000002}.tar
```

With the Python `webdataset` package:

```python
import webdataset as wds

train = wds.WebDataset(
    "wds/train/bouncing-balls-train-{000000..000008}.tar"
)
val = wds.WebDataset(
    "wds/val/bouncing-balls-val-{000000..000002}.tar"
)
```

## Columns

| Column | Description |
|---|---|
| `video` | The MP4 video clip, stored as embedded bytes in Parquet |
| `num_balls` | Number of balls in the clip (3, 4, or 5) |
| `colors` | Color names for the balls |
| `background_rgb` | Background color as an RGB triplet |
| `balls` | Per-ball color, RGB, radius, initial position, and initial velocity |
| `num_frames` | Number of frames (24) |
| `fps` | Frames per second (12) |
| `width` | Frame width (196) |
| `height` | Frame height (196) |

Each entry in `balls` has:

```text
color: string
color_rgb: [int, int, int]
radius: int
initial_position: [x, y]
initial_velocity: [vx, vy]
```

## Usage

```python
from datasets import load_dataset

ds = load_dataset("jimchen2/bouncing-balls", split="train")
print(ds)
print(ds[0]["num_balls"])
print(ds[0]["balls"])
```

Decoding videos with `datasets` may require `torchcodec`.

## Reproduce

```bash
pip install -r scripts/requirements.txt

# Generate the raw videos and metadata
python scripts/generate_bouncing_balls.py \
  --count 3000 \
  --output bouncing-balls

# Create Parquet shards
python scripts/shard_bouncing_balls.py \
  --source bouncing-balls \
  --output sharded \
  --shards 10

# Create WebDataset train/val tar shards
python scripts/shard_bouncing_balls_wds.py \
  --source bouncing-balls \
  --output bouncing-balls/wds
```

## License

MIT. The videos are synthetically generated and may be used for experimentation, education, and model development.