Datasets:
Create dataset.py
Browse files- dataset.py +60 -0
dataset.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from datasets import GeneratorBasedBuilder, DatasetInfo, Features, Value, Image, SplitGenerator, Split
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
class FFHQProxyReference(GeneratorBasedBuilder):
|
| 6 |
+
VERSION = "1.0.0"
|
| 7 |
+
|
| 8 |
+
def _info(self):
|
| 9 |
+
return DatasetInfo(
|
| 10 |
+
description="FFHQ Proxy Reference dataset for high-quality facial images.",
|
| 11 |
+
features=Features(
|
| 12 |
+
{
|
| 13 |
+
"image": Image(),
|
| 14 |
+
"resolution": Value("int32"),
|
| 15 |
+
"source": Value("string"),
|
| 16 |
+
}
|
| 17 |
+
),
|
| 18 |
+
supervised_keys=None,
|
| 19 |
+
homepage="https://github.com/NVlabs/ffhq-dataset",
|
| 20 |
+
license="creativeml-openrail-m",
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
def _split_generators(self, dl_manager):
|
| 24 |
+
"""
|
| 25 |
+
User MUST pass data_dir when calling load_dataset.
|
| 26 |
+
"""
|
| 27 |
+
if not self.config.data_dir:
|
| 28 |
+
raise ValueError(
|
| 29 |
+
"You must provide a local path to FFHQ images using `data_dir`."
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
return [
|
| 33 |
+
SplitGenerator(
|
| 34 |
+
name=Split.TRAIN,
|
| 35 |
+
gen_kwargs={"image_dir": self.config.data_dir},
|
| 36 |
+
)
|
| 37 |
+
]
|
| 38 |
+
|
| 39 |
+
def _generate_examples(self, image_dir):
|
| 40 |
+
"""
|
| 41 |
+
Expects a flat or nested directory of FFHQ images.
|
| 42 |
+
"""
|
| 43 |
+
idx = 0
|
| 44 |
+
for root, _, files in os.walk(image_dir):
|
| 45 |
+
for file in files:
|
| 46 |
+
if file.lower().endswith((".png", ".jpg", ".jpeg")):
|
| 47 |
+
path = os.path.join(root, file)
|
| 48 |
+
|
| 49 |
+
yield idx, {
|
| 50 |
+
"image": path,
|
| 51 |
+
"resolution": self._infer_resolution(file),
|
| 52 |
+
"source": "FFHQ",
|
| 53 |
+
}
|
| 54 |
+
idx += 1
|
| 55 |
+
|
| 56 |
+
def _infer_resolution(self, filename):
|
| 57 |
+
"""
|
| 58 |
+
Optional heuristic – FFHQ commonly uses 1024x1024.
|
| 59 |
+
"""
|
| 60 |
+
return 1024
|