Datasets:
Update dataset.py
Browse files- dataset.py +26 -46
dataset.py
CHANGED
|
@@ -1,61 +1,41 @@
|
|
| 1 |
import os
|
| 2 |
-
from datasets import GeneratorBasedBuilder,
|
| 3 |
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
class FFHQProxyReference(GeneratorBasedBuilder):
|
| 6 |
VERSION = "1.0.0"
|
| 7 |
|
| 8 |
def _info(self):
|
| 9 |
return DatasetInfo(
|
| 10 |
-
description="
|
| 11 |
-
|
| 12 |
-
{
|
| 13 |
-
"image": Image(),
|
| 14 |
-
"resolution": Value("int32"),
|
| 15 |
-
"source": Value("string"),
|
| 16 |
-
}
|
| 17 |
-
),
|
| 18 |
-
supervised_keys=None,
|
| 19 |
-
homepage="https://drive.google.com/drive/folders/1u2xu7bSrWxrbUxk-dT-UvEJq8IjdmNTP",
|
| 20 |
-
|
| 21 |
license="creativeml-openrail-m",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
)
|
| 23 |
|
| 24 |
def _split_generators(self, dl_manager):
|
| 25 |
-
"""
|
| 26 |
-
|
| 27 |
-
"""
|
| 28 |
-
if not self.config.data_dir:
|
| 29 |
-
raise ValueError(
|
| 30 |
-
"You must provide a local path to FFHQ images using `data_dir`."
|
| 31 |
-
)
|
| 32 |
-
|
| 33 |
return [
|
| 34 |
-
SplitGenerator(
|
| 35 |
name=Split.TRAIN,
|
| 36 |
-
gen_kwargs={"
|
| 37 |
-
)
|
| 38 |
]
|
| 39 |
|
| 40 |
-
def _generate_examples(self,
|
| 41 |
-
"""
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
yield idx, {
|
| 51 |
-
"image": path,
|
| 52 |
-
"resolution": self._infer_resolution(file),
|
| 53 |
-
"source": "FFHQ",
|
| 54 |
-
}
|
| 55 |
-
idx += 1
|
| 56 |
-
|
| 57 |
-
def _infer_resolution(self, filename):
|
| 58 |
-
"""
|
| 59 |
-
Optional heuristic – FFHQ commonly uses 1024x1024.
|
| 60 |
-
"""
|
| 61 |
-
return 1024
|
|
|
|
| 1 |
import os
|
| 2 |
+
from datasets import DatasetInfo, GeneratorBasedBuilder, Split, Features, Image
|
| 3 |
|
| 4 |
+
class FFHQProxy(GeneratorBasedBuilder):
|
| 5 |
+
"""FFHQ Proxy Dataset Loader"""
|
| 6 |
|
|
|
|
| 7 |
VERSION = "1.0.0"
|
| 8 |
|
| 9 |
def _info(self):
|
| 10 |
return DatasetInfo(
|
| 11 |
+
description="Proxy repository for FFHQ: facial upscaling and restoration reference dataset.",
|
| 12 |
+
homepage="https://github.com/NVlabs/ffhq-dataset",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
license="creativeml-openrail-m",
|
| 14 |
+
features=Features({
|
| 15 |
+
"low_quality": Image(),
|
| 16 |
+
"high_quality": Image()
|
| 17 |
+
}),
|
| 18 |
+
task_categories=["image-to-image"],
|
| 19 |
+
language=["en"],
|
| 20 |
)
|
| 21 |
|
| 22 |
def _split_generators(self, dl_manager):
|
| 23 |
+
"""Define splits (train/test)"""
|
| 24 |
+
data_dir = os.path.expanduser(dl_manager.download_and_extract("https://drive.google.com/drive/folders/1u2xu7bSrWxrbUxk-dT-UvEJq8IjdmNTP"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
return [
|
| 26 |
+
self.SplitGenerator(
|
| 27 |
name=Split.TRAIN,
|
| 28 |
+
gen_kwargs={"images_dir": os.path.join(data_dir, "train")}
|
| 29 |
+
),
|
| 30 |
]
|
| 31 |
|
| 32 |
+
def _generate_examples(self, images_dir):
|
| 33 |
+
"""Yield examples."""
|
| 34 |
+
for idx, fname in enumerate(os.listdir(images_dir)):
|
| 35 |
+
if fname.endswith(".png") or fname.endswith(".jpg"):
|
| 36 |
+
low_quality_path = os.path.join(images_dir, fname)
|
| 37 |
+
high_quality_path = os.path.join(images_dir, "high_quality", fname)
|
| 38 |
+
yield idx, {
|
| 39 |
+
"low_quality": low_quality_path,
|
| 40 |
+
"high_quality": high_quality_path
|
| 41 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|