WLuLi commited on
Commit
8bc48e9
·
verified ·
1 Parent(s): cd580a9

Upload AlphaAnything training datasets

Browse files
.gitattributes CHANGED
@@ -58,3 +58,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
58
  # Video files - compressed
59
  *.mp4 filter=lfs diff=lfs merge=lfs -text
60
  *.webm filter=lfs diff=lfs merge=lfs -text
 
 
58
  # Video files - compressed
59
  *.mp4 filter=lfs diff=lfs merge=lfs -text
60
  *.webm filter=lfs diff=lfs merge=lfs -text
61
+ train/prismlayerspro_annotations.jsonl filter=lfs diff=lfs merge=lfs -text
LICENSE ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ AlphaAnything Training Datasets License
2
+
3
+ All original data, annotations, prompts, captions, and synthetic images in this
4
+ repository are licensed under the Creative Commons Attribution-NonCommercial 4.0
5
+ International License (CC BY-NC 4.0):
6
+
7
+ Human-readable summary: https://creativecommons.org/licenses/by-nc/4.0/
8
+ Full legal code: https://creativecommons.org/licenses/by-nc/4.0/legalcode
9
+
10
+ Under CC BY-NC 4.0, you are free to:
11
+ - Share: copy and redistribute the material in any medium or format.
12
+ - Adapt: remix, transform, and build upon the material.
13
+
14
+ Under the following terms:
15
+ - Attribution: you must give appropriate credit (including citing the
16
+ AlphaAnything paper), provide a link to the license, and indicate if changes
17
+ were made.
18
+ - NonCommercial: you may not use the material for commercial purposes.
19
+
20
+ Third-Party Source Data (Not Redistributed)
21
+
22
+ PrismLayersPro annotations (`train/prismlayerspro_annotations.jsonl`):
23
+ This repository distributes text instructions and layer reference metadata only
24
+ (licensed under CC BY-NC 4.0); no PrismLayersPro images are included. Upstream
25
+ images must be obtained separately from:
26
+ https://huggingface.co/datasets/artplus/PrismLayersPro
27
+ and are governed by their original Apache-2.0 license.
28
+
29
+ See NOTICE for upstream dataset attributions.
NOTICE ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ AlphaAnything Training Datasets — Upstream Notices
2
+
3
+ This release includes annotations referencing the following third-party dataset.
4
+ No upstream images are redistributed in this repository. We thank its authors and
5
+ maintainers.
6
+
7
+ - PrismLayersPro (PrismLayers: Open Data for High-Quality Multi-Layer
8
+ Transparent Image Generative Models)
9
+ https://huggingface.co/datasets/artplus/PrismLayersPro
10
+ License: Apache-2.0.
11
+ Upstream image source referenced by `train/prismlayerspro_annotations.jsonl`.
12
+
13
+ This notice identifies upstream sources and does not replace their original
14
+ license texts or copyright notices.
README.md ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ pretty_name: AlphaAnything Training Datasets
3
+ license: cc-by-nc-4.0
4
+ language:
5
+ - en
6
+ task_categories:
7
+ - text-to-image
8
+ - image-to-image
9
+ size_categories:
10
+ - 100K<n<1M
11
+ tags:
12
+ - image
13
+ - text
14
+ - rgba
15
+ - alphaanything
16
+ source_datasets:
17
+ - artplus/PrismLayersPro
18
+ configs:
19
+ - config_name: t2rgba_train
20
+ default: true
21
+ data_files:
22
+ - split: train
23
+ path: train/t2rgba_train.jsonl
24
+ - config_name: prismlayerspro_annotations
25
+ data_files:
26
+ - split: train
27
+ path: train/prismlayerspro_annotations.jsonl
28
+ ---
29
+
30
+ # AlphaAnything Training Datasets
31
+
32
+ [Paper](https://arxiv.org/abs/2610.32413) · [Project](https://wluli.github.io/AlphaAnything/) · [Code](https://github.com/WLuLi/AlphaAnything)
33
+
34
+ Training datasets and annotations for **AlphaAnything: Extending Pretrained RGB Generators to RGBA**.
35
+
36
+ ## Contents (`train/`)
37
+
38
+ | Subset | Description | Files |
39
+ | --- | --- | --- |
40
+ | T2RGBA training | 8,963 RGBA PNG images (1024×1024) with multi-granularity captions across 9 categories | [t2rgba_train-00000-of-00002.tar](train/t2rgba_train-00000-of-00002.tar), [t2rgba_train-00001-of-00002.tar](train/t2rgba_train-00001-of-00002.tar), [t2rgba_train.jsonl](train/t2rgba_train.jsonl) |
41
+ | PrismLayersPro annotations | 719,968 extraction instructions across 179,992 layers of [PrismLayersPro](https://huggingface.co/datasets/artplus/PrismLayersPro) (images reconstructed from upstream Parquet files) | [prismlayerspro_annotations.jsonl](train/prismlayerspro_annotations.jsonl), [prepare_prismlayerspro.py](prepare_prismlayerspro.py) |
42
+
43
+ ## Usage
44
+
45
+ Download the files into `data/` in the [code repository](https://github.com/WLuLi/AlphaAnything).
46
+
47
+ ### 1. Extract T2RGBA training data
48
+
49
+ ```bash
50
+ tar -xf data/train/t2rgba_train-00000-of-00002.tar -C data/train
51
+ tar -xf data/train/t2rgba_train-00001-of-00002.tar -C data/train
52
+ ```
53
+
54
+ This creates `data/train/t2rgba_train/train.csv` and `data/train/t2rgba_train/images/000000.png` ... `008962.png`.
55
+
56
+ ### 2. Reconstruct PrismLayersPro training images
57
+
58
+ ```bash
59
+ python data/prepare_prismlayerspro.py \
60
+ --annotations data/train/prismlayerspro_annotations.jsonl \
61
+ --prism-dir data/train/PrismLayersPro_raw \
62
+ --output-dir data/train/prismlayerspro \
63
+ --download \
64
+ --num-workers 4
65
+ ```
66
+
67
+ This writes extracted source RGB images, 1024×1024 target RGBA layers, and `data/train/prismlayerspro/train.jsonl`.
68
+
69
+ ## License
70
+
71
+ All original data, images, captions, and annotations in this repository are licensed under [CC BY-NC 4.0](https://creativecommons.org/licenses/by-nc/4.0/) (non-commercial use only). Upstream images from [artplus/PrismLayersPro](https://huggingface.co/datasets/artplus/PrismLayersPro) (Apache-2.0) are not redistributed here and must be obtained directly under their original terms. See [LICENSE](LICENSE) and [NOTICE](NOTICE) for details.
72
+
73
+ Please cite [our paper](https://arxiv.org/abs/2610.32413) when using these datasets.
prepare_prismlayerspro.py ADDED
@@ -0,0 +1,247 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Reconstruct PrismLayersPro source RGB and full-canvas target RGBA images from Parquet files."""
3
+ from __future__ import annotations
4
+
5
+ import argparse
6
+ import concurrent.futures as futures
7
+ import gzip
8
+ import io
9
+ import json
10
+ from collections import defaultdict
11
+ from pathlib import Path
12
+ from typing import Any
13
+
14
+ import pyarrow.parquet as pq
15
+ from PIL import Image
16
+ from tqdm import tqdm
17
+
18
+
19
+ def _open_annotations(path: Path):
20
+ if path.suffix == ".gz":
21
+ return gzip.open(path, "rt", encoding="utf-8")
22
+ return path.open("r", encoding="utf-8")
23
+
24
+
25
+ def _decode_parquet_image(value: Any, prism_dir: Path) -> Image.Image:
26
+ if not isinstance(value, dict):
27
+ raise ValueError("Expected a Parquet image struct with 'bytes' or 'path'.")
28
+ if value.get("bytes"):
29
+ source: Any = io.BytesIO(value["bytes"])
30
+ elif value.get("path"):
31
+ source = prism_dir / value["path"]
32
+ else:
33
+ raise ValueError("Missing image bytes/path in Parquet cell.")
34
+ with Image.open(source) as img:
35
+ img.load()
36
+ return img.copy()
37
+
38
+
39
+ def _place_layer_on_canvas(
40
+ layer_img: Image.Image,
41
+ box_xyxy: list[int],
42
+ canvas_size: tuple[int, int],
43
+ ) -> Image.Image:
44
+ x0, y0, x1, y1 = map(int, box_xyxy)
45
+ width, height = x1 - x0, y1 - y0
46
+ resized = layer_img.convert("RGBA").resize((width, height), Image.Resampling.BICUBIC)
47
+ canvas = Image.new("RGBA", canvas_size, (0, 0, 0, 0))
48
+ # Paste without a mask so straight RGBA alpha is preserved rather than squared.
49
+ canvas.paste(resized, (x0, y0))
50
+ return canvas
51
+
52
+
53
+ def _process_parquet(
54
+ parquet_rel: str,
55
+ row_specs: dict[int, dict[str, Any]],
56
+ prism_dir: Path,
57
+ output_dir: Path,
58
+ *,
59
+ download: bool,
60
+ skip_existing: bool,
61
+ ) -> tuple[int, int]:
62
+ parquet_path = prism_dir / parquet_rel
63
+ if not parquet_path.is_file():
64
+ if not download:
65
+ raise FileNotFoundError(
66
+ f"Missing {parquet_path}. Download artplus/PrismLayersPro or pass --download."
67
+ )
68
+ from huggingface_hub import hf_hub_download
69
+
70
+ hf_hub_download(
71
+ repo_id="artplus/PrismLayersPro",
72
+ repo_type="dataset",
73
+ filename=parquet_rel,
74
+ local_dir=str(prism_dir),
75
+ )
76
+
77
+ needed_layers = sorted({layer_idx for spec in row_specs.values() for layer_idx in spec["layers"]})
78
+ columns = ["whole_image"] + [f"layer_{idx:02d}" for idx in needed_layers]
79
+
80
+ pf = pq.ParquetFile(parquet_path)
81
+ saved_sources = 0
82
+ saved_layers = 0
83
+ row_offset = 0
84
+
85
+ for rg_idx in range(pf.num_row_groups):
86
+ rg_rows = pf.metadata.row_group(rg_idx).num_rows
87
+ rg_end = row_offset + rg_rows
88
+ local_indices = [r for r in row_specs if row_offset <= r < rg_end]
89
+ if not local_indices:
90
+ row_offset = rg_end
91
+ continue
92
+
93
+ table = pf.read_row_group(rg_idx, columns=columns)
94
+ for global_row in local_indices:
95
+ spec = row_specs[global_row]
96
+ local_row = global_row - row_offset
97
+ canvas_size = (int(spec["canvas_width"]), int(spec["canvas_height"]))
98
+
99
+ src_dst = output_dir / spec["condition_image"]
100
+ if not (skip_existing and src_dst.is_file()):
101
+ src_img = _decode_parquet_image(table["whole_image"][local_row].as_py(), prism_dir).convert("RGB")
102
+ src_dst.parent.mkdir(parents=True, exist_ok=True)
103
+ src_img.save(src_dst)
104
+ saved_sources += 1
105
+
106
+ for layer_idx, (target_rel, box_xyxy) in spec["layers"].items():
107
+ tgt_dst = output_dir / target_rel
108
+ if skip_existing and tgt_dst.is_file():
109
+ continue
110
+ col_name = f"layer_{layer_idx:02d}"
111
+ layer_img = _decode_parquet_image(table[col_name][local_row].as_py(), prism_dir)
112
+ canvas = _place_layer_on_canvas(layer_img, box_xyxy, canvas_size)
113
+ tgt_dst.parent.mkdir(parents=True, exist_ok=True)
114
+ canvas.save(tgt_dst)
115
+ saved_layers += 1
116
+
117
+ row_offset = rg_end
118
+
119
+ return saved_sources, saved_layers
120
+
121
+
122
+ def main() -> None:
123
+ parser = argparse.ArgumentParser(description=__doc__)
124
+ parser.add_argument(
125
+ "--annotations",
126
+ type=Path,
127
+ default=Path("data/train/prismlayerspro_annotations.jsonl"),
128
+ help="Path to prismlayerspro_annotations.jsonl (or .jsonl.gz).",
129
+ )
130
+ parser.add_argument(
131
+ "--prism-dir",
132
+ type=Path,
133
+ required=True,
134
+ help="Local directory containing artplus/PrismLayersPro (with data/*.parquet).",
135
+ )
136
+ parser.add_argument(
137
+ "--output-dir",
138
+ type=Path,
139
+ default=Path("data/train/prismlayerspro"),
140
+ help="Directory to write extracted images and train.jsonl.",
141
+ )
142
+ parser.add_argument(
143
+ "--download",
144
+ action="store_true",
145
+ help="Download missing Parquet files from artplus/PrismLayersPro on Hugging Face.",
146
+ )
147
+ parser.add_argument(
148
+ "--num-workers",
149
+ type=int,
150
+ default=4,
151
+ help="Number of Parquet files to process in parallel.",
152
+ )
153
+ parser.add_argument(
154
+ "--overwrite",
155
+ action="store_true",
156
+ help="Overwrite already extracted PNG files.",
157
+ )
158
+ parser.add_argument(
159
+ "--limit",
160
+ type=int,
161
+ default=None,
162
+ help="Optional limit on the number of annotation records to process.",
163
+ )
164
+ args = parser.parse_args()
165
+
166
+ by_parquet: dict[str, dict[int, dict[str, Any]]] = defaultdict(dict)
167
+ manifest_rows: list[dict[str, Any]] = []
168
+
169
+ with _open_annotations(args.annotations) as handle:
170
+ for line in handle:
171
+ if not line.strip():
172
+ continue
173
+ row = json.loads(line)
174
+ parquet_rel = row["source_ref"]["parquet"]
175
+ row_index = int(row["source_ref"]["row_index"])
176
+ spec = by_parquet[parquet_rel].setdefault(
177
+ row_index,
178
+ {
179
+ "condition_image": row["condition_image"],
180
+ "canvas_width": int(row["canvas_width"]),
181
+ "canvas_height": int(row["canvas_height"]),
182
+ "layers": {},
183
+ },
184
+ )
185
+ spec["layers"][int(row["layer_index"])] = (row["target_rgba"], row["box_xyxy"])
186
+ manifest_rows.append(
187
+ {
188
+ "id": row["id"],
189
+ "condition_image": row["condition_image"],
190
+ "target_rgba": row["target_rgba"],
191
+ "prompt": row["prompt"],
192
+ "canvas_width": int(row["canvas_width"]),
193
+ "canvas_height": int(row["canvas_height"]),
194
+ }
195
+ )
196
+ if args.limit is not None and len(manifest_rows) >= args.limit:
197
+ break
198
+
199
+ args.output_dir.mkdir(parents=True, exist_ok=True)
200
+ parquet_items = sorted(by_parquet.items())
201
+ total_sources = 0
202
+ total_layers = 0
203
+
204
+ if args.num_workers <= 1:
205
+ for parquet_rel, row_specs in tqdm(parquet_items, desc="Extracting PrismLayersPro"):
206
+ s, l = _process_parquet(
207
+ parquet_rel,
208
+ row_specs,
209
+ args.prism_dir,
210
+ args.output_dir,
211
+ download=args.download,
212
+ skip_existing=not args.overwrite,
213
+ )
214
+ total_sources += s
215
+ total_layers += l
216
+ else:
217
+ with futures.ProcessPoolExecutor(max_workers=args.num_workers) as pool:
218
+ futs = [
219
+ pool.submit(
220
+ _process_parquet,
221
+ parquet_rel,
222
+ row_specs,
223
+ args.prism_dir,
224
+ args.output_dir,
225
+ download=args.download,
226
+ skip_existing=not args.overwrite,
227
+ )
228
+ for parquet_rel, row_specs in parquet_items
229
+ ]
230
+ for fut in tqdm(futures.as_completed(futs), total=len(futs), desc="Extracting PrismLayersPro"):
231
+ s, l = fut.result()
232
+ total_sources += s
233
+ total_layers += l
234
+
235
+ manifest_path = args.output_dir / "train.jsonl"
236
+ with manifest_path.open("w", encoding="utf-8") as handle:
237
+ for row in manifest_rows:
238
+ handle.write(json.dumps(row, ensure_ascii=False) + "\n")
239
+
240
+ print(
241
+ f"Done: wrote {total_sources} source images, {total_layers} target RGBA layers, "
242
+ f"and {len(manifest_rows)} records to {manifest_path}"
243
+ )
244
+
245
+
246
+ if __name__ == "__main__":
247
+ main()
train/prismlayerspro_annotations.jsonl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7f94b745f45ec6c275532fd2efd85f2b3031875b3757ecbec7535c45022352e1
3
+ size 426682419
train/t2rgba_train-00000-of-00002.tar ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:09e538432a89e5a14b3b57294d231490e08ab19a00972d15f86273f17bae4174
3
+ size 4887255040
train/t2rgba_train-00001-of-00002.tar ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3060ba582be98170aaefc2f968ccc742aa1c17e8ecda1ece3bb2f4e8638c75c7
3
+ size 4882360320
train/t2rgba_train.jsonl ADDED
The diff for this file is too large to render. See raw diff