synclight / scripts /README.md
davidserra9's picture
Add generation scripts
1d4b965 verified
|
Raw History Blame Contribute Delete
12.9 kB
# Generating SyncLight pairs
`synclight_generate.py` turns the per-light base files of this dataset into relighting pairs: two light states that differ in one light, rendered from every camera of a rig, plus a lightmap describing the edit. One script handles all three sources. The `source` field of the config selects how base files are read: EXR renders for Infinigen and BlenderKit, RAW photographs for the real captures.
```bash
pip install numpy opencv-python pyyaml scipy pillow OpenEXR rawpy # rawpy only needed for the real split
bash scripts/extract.sh ./synclight_raw infinigen train
python scripts/synclight_generate.py --config scripts/configs/infinigen.yaml \
--input ./synclight_raw/infinigen/train --output ./synclight_pairs/infinigen/train --workers 8
```
The output has the layout the SyncLight training code reads (`<scene>/png_simple/transforms.json` for Infinigen, `<scene>/png_blended/transforms.json` for the others). Finished scenes are skipped when the command is re-run.
## How it works
**1. Per-light images.** Each camera of a scene has one linear HDR image per light source, with that light alone at full intensity. Lights come in three kinds, encoded in the file names:
| kind | meaning | can be edited? |
|---|---|---|
| `camvis` | visible from this camera | yes, it appears in the lightmap |
| `rigvis` | visible only from other cameras of the rig | no, but it is switched on and off randomly |
| `nonvis` / `ambient` | not visible from any camera (window light, ambient fill) | no |
**2. Light states.** A state gives every light an intensity in [0, 1] and an RGB colour. Light is additive, so the image of a state is
```
image = tonemap( exposure · Σ_i intensity_i · colour_i · light_i )
```
**3. Samples.** A sample is a *before* state and an *after* state that differ in exactly one `camvis` light: the edit. For every reference camera, two families of samples are generated:
- **Solo sweep** (`solo_sweep`). Only when the scene has an ambient light. The before state is the ambient light alone. In the after state, one visible light is switched on in each of 8 saturated hues and `n_temperatures` colour temperatures. This teaches the model clean colour edits.
- **Random combinations** (`pairs.per_light` per editable light). The before state is random: each ambient light is on with probability `p_ambient_on`, each visible light with probability `p_visible_on`, at an intensity drawn from `on_intensity`, and all lights share one colour drawn from `colors.scene`. The after state applies one edit to the target light, chosen with the `edits` weights:
- `toggle`: on → off, or off → on at full intensity
- `intensity`: a bright light is dimmed (`dim_to`), a dim one brightened (`brighten_to`), an off one partially switched on (`partial_on`)
- `color`: the light gets a new colour drawn from `colors.edit`, and is switched on if it was off
**4. Colours.** Every colour draw is white, a colour temperature or a saturated hue, with the probabilities in `colors.scene` (the shared colour of the before state) or `colors.edit` (the new colour of a colour edit).
- **Temperatures** are picked from `colors.temperatures` (Kelvin), or uniformly from `colors.temperature_range`.
- **Saturated hues** depend on `colors.vivid.mode`:
- `named`: one of 8 fixed hues
- `jitter`: random hue, saturation and value around those 8 hues
- `any`: any hue, with saturation and value ranges you set
- **Per-light colours:** `colors.per_light: true` gives every light its own colour instead of one shared colour.
**5. Views and pairs.** Each sample is rendered for the reference camera, which gives the guide images and the lightmap, and for up to `target_views` other cameras of the same rig. Each other view gives one training pair. If the sample stores its reverse edit, it gives a second pair (after → before). So, per reference camera with *k* editable lights in a rig of *C* cameras:
```
samples = k · (8 + n_temperatures) [if there is an ambient light] + k · per_light
pairs = Σ_samples (C − 1) · (1 + reverse)
```
`pairs.max_per_scene` drops samples at random, keeping the same fraction in every camera, until the scene fits under the cap.
**6. Tone mapping.** Linear images are multiplied by `exposure` and mapped to 8-bit with `operator` and `gamma`:
- **Operators:** `reinhard` (x/(1+x)), `reinhard_white`, `aces`, `hable` (filmic) or `clip`.
- **Auto exposure:** with `auto_exposure: {percentile: 99, target: 0.9}` the exposure is chosen per sample from the reference before image. It is then used for every image of that sample, so the before and after images stay photometrically consistent.
**7. Lightmaps.** The lightmap marks the pixels of the edited light, found by thresholding its light-position map at `output.lightmap_threshold`. Each pixel holds `[activation, L, a, b]`: activation is −1 (turn off), 0 (no change) or 1 (set to the target intensity `L` and colour `a, b`). By default lightmaps are written as 16-bit PNGs; read them with `lightmap_io.load_lightmap`. Set `output.lightmap: npy` for float32 `.npy`.
**8. Determinism.** Every reference camera has its own random generator, seeded from `seed`, the scene name, the rig and the camera. The same config therefore gives the same pairs no matter how many workers you use, and `--dry-run` counts exactly what a real run produces.
## Configs
| Config | Matches |
|---|---|
| `configs/infinigen.yaml` | the released Infinigen pairs |
| `configs/blenderkit.yaml` | the released BlenderKit pairs |
| `configs/real.yaml` | the released real-capture pairs |
These configs use the same sampling rules, colour lists, tone mapping and light-map thresholds as the scripts that produced the pairs used in the paper. Because those runs were not seeded, a new run gives *different* pairs with the same distribution and the same scale:
| Source / split | Pairs released | Pairs generated | Images released | Images generated |
|---|---:|---:|---:|---:|
| Infinigen train | 898,267 | 920,878 | 1,579,444 | 1,617,594 |
| Infinigen test | 27,236 | 29,516 | 47,788 | 51,572 |
| BlenderKit train | 44,326 | 44,420 | 74,822 | 74,950 |
| BlenderKit test | 3,198 | 3,222 | 5,464 | 5,496 |
| Real train | 12,718 | 12,756 | 22,652 | 22,700 |
| Real test | 1,718 | 1,712 | 3,066 | 3,058 |
The renderer itself is exact. With `output.precision: float64`, the deterministic samples (the start of the solo sweep) are bit-identical to the released images and lightmaps for all three sources. The default `float32` is faster and differs by at most one grey level.
The configs differ on purpose:
- **Infinigen** has 5 random samples per light, a cap of 5,000 pairs per scene, no colour edits, and an occasional saturated scene colour.
- **BlenderKit and real** have 10 random samples per light, no cap, and 20% colour edits.
- **Real** uses `clip` tone mapping with exposure 1.0 and writes images with a longest side of 1280.
## Colour palettes
`colors.palette` applies a preset on top of a config. Any `colors.*` value set with `--set` still overrides it.
| Palette | Scene colour (white / temperature / saturated) | Colour edits | Notes |
|---|---|---|---|
| `neutral` | 50 / 50 / 0 | 20% white, 80% temperature | temperatures 3000–6500 K |
| `warm` | 20 / 80 / 0 | temperature only | 2200–4000 K (tungsten) |
| `cool` | 20 / 80 / 0 | temperature only | 5000–9000 K (daylight, fluorescent) |
| `colorful` | 40 / 30 / 30 | 40% temperature, 60% saturated | hues jittered around the 8 named ones |
| `wild` | 10 / 20 / 70 | 90% saturated | any hue; every light gets its own colour |
## Parameter reference
| Key | Default | Meaning |
|---|---|---|
| `source` | infinigen | `infinigen`, `blenderkit` or `real`: how base files are found and read |
| `output_subdir` | png_simple | folder written inside each output scene |
| `seed` | 0 | master seed |
| `pairs.per_light` | 5 | random-combination samples per editable light, per reference camera |
| `pairs.max_per_scene` | null | cap on pairs per scene |
| `pairs.reverse` | true | also store the reverse edit of random samples |
| `pairs.target_views` | all | other views rendered per sample (`all` or a number) |
| `pairs.min_cameras` | 2 | rigs with fewer cameras are skipped |
| `solo_sweep.enabled` | true | add the solo colour sweep |
| `solo_sweep.vivid` | 8 hues | hues of the sweep |
| `solo_sweep.n_temperatures` | 5 | colour temperatures added to the sweep, drawn from `solo_sweep.temperatures` |
| `solo_sweep.intensity` | 1.0 | intensity of the swept light |
| `solo_sweep.reverse_first` | 3 | only the first N sweep colours also store the reverse edit |
| `lights.p_ambient_on` | 0.8 | probability that each ambient light is on in the before state |
| `lights.p_visible_on` | 0.6 | probability that each visible light is on in the before state |
| `lights.on_intensity` | [0.4, 1.0] | intensity range of lights that are on |
| `edits.toggle` / `intensity` / `color` | 0.7 / 0.3 / 0 | relative weights of the edit types |
| `edits.dim_to`, `brighten_to`, `partial_on` | [0.2,0.5], [0.7,1], [0.5,1] | target intensity ranges of intensity edits |
| `edits.bright_threshold` | 0.6 | lights above it are dimmed, below it brightened |
| `colors.palette` | null | preset (see above) |
| `colors.scene` | 0.7 / 0.18 / 0.12 | white / temperature / vivid weights of the shared scene colour |
| `colors.edit` | 0 / 0.7 / 0.3 | weights of the new colour in colour edits |
| `colors.per_light` | false | every light draws its own colour |
| `colors.temperatures` | list | colour temperatures to choose from (K) |
| `colors.temperature_range` | null | continuous temperature range instead of the list |
| `colors.vivid.mode` | jitter | `named`, `jitter` or `any` |
| `colors.vivid.names` | 8 hues | hues used by `named` and `jitter` |
| `colors.vivid.saturation`, `value` | [0.7,1], [0.7,1] | ranges used by `any` |
| `tonemap.operator` | reinhard | `reinhard`, `reinhard_white`, `aces`, `hable`, `clip` |
| `tonemap.white` | 4.0 | white point of `reinhard_white` |
| `tonemap.exposure` | 1.0 | multiplier on linear radiance |
| `tonemap.auto_exposure` | null | `{percentile, target}`: exposure per sample from the reference before image |
| `tonemap.gamma` | 2.2 | display gamma, or `srgb` |
| `tonemap.quantize` | floor | `floor` (as in the release) or `round` |
| `output.max_side` | null | downscale outputs so the longest side is at most this many pixels |
| `output.resize_inputs` | false | downscale base images before mixing instead of after tone mapping: about 6× faster for RAW, with a mean difference under 1 grey level (up to ~40 on small, very bright spots) |
| `output.lightmap` | png16 | `png16` or `npy` |
| `output.lightmap_size` | image | `image` (same size as the images) or `native` (size of the light-position maps) |
| `output.lightmap_threshold` | 0.098 | light-position map value above which a pixel belongs to the light |
| `output.precision` | float32 | `float64` reproduces the original renderer bit for bit |
## Recipes
```bash
# count first: what would a config produce? (reads only file names)
python scripts/synclight_generate.py --config scripts/configs/blenderkit.yaml --input ./synclight_raw/blenderkit/train --dry-run
# twice the data, warm lights only
... --set pairs.per_light=10 colors.palette=warm
# colour edits only, any hue, every light its own colour
... --set colors.palette=wild edits.toggle=0 edits.intensity=0 edits.color=1
# filmic tone mapping with automatic exposure
... --set tonemap.operator=aces "tonemap.auto_exposure={percentile: 99, target: 0.9}"
# smaller, faster real-capture pairs
... --config scripts/configs/real.yaml --set output.max_side=768 output.resize_inputs=true
```
## Speed
Measured on one CPU core (`--workers 1`) with the paper configs, reading base files from a local SSD:
| Scene | Pairs | Images | Time | Output size |
|---|---:|---:|---:|---:|
| Infinigen `Bathroom_1000` (test) | 804 | 1,580 | 252 s | 1.1 GB |
| BlenderKit `bare_room` (test) | 1,728 | 2,944 | 477 s | 1.6 GB |
| Real `scene15` (test), exact | 312 | 536 | 907 s | 0.8 GB |
| Real `scene15` (test), `resize_inputs: true` | 312 | 536 | 138 s | 0.8 GB |
Rendering takes about 0.16 s per image for EXR scenes. Decoding full-resolution RAW photos makes real scenes slower unless `output.resize_inputs` is on. Scaled to full training splits (estimates):
| Split | Images | CPU time | With `--workers 16` | Disk |
|---|---:|---:|---:|---:|
| Infinigen train | 1.62 M | ~72 core-hours | ~4.5 h | ~1.1 TB |
| BlenderKit train | 75 K | ~3.4 core-hours | ~15 min | ~45 GB |
| Real train (exact / fast) | 23 K | ~11 / ~1.6 core-hours | ~40 / ~6 min | ~37 GB |
Peak memory per worker is under 0.5 GB for synthetic scenes and about 3.2 GB for full-resolution real captures. Use `pairs.per_light`, `pairs.max_per_scene`, `pairs.target_views` or `output.max_side` to make the output smaller and faster to produce.