Commit
•
81652ca
1
Parent(s):
046a4f1
Fix dataset script (#8)
Browse files- Fix dataset script (d18734917b272fca92a66b74cc5c550d21f40b92)
- Update danbooru2023.py (184e35992b7c008af465824f8a345e841288f519)
- Nit (8985e8c46a545a70ca6ce921892570e291d0b515)
- One more nit (82e775a80bb79a769eedfca933945c0f659b084e)
Co-authored-by: Mario Šaško <[email protected]>
- danbooru2023.py +23 -25
danbooru2023.py
CHANGED
@@ -1,12 +1,12 @@
|
|
1 |
import os
|
|
|
|
|
2 |
import datasets
|
3 |
-
from
|
4 |
-
from
|
5 |
-
|
6 |
|
7 |
_EXTENSION = [".png", ".jpg", ".jpeg", ".webp", ".bmp"]
|
8 |
-
_NAME = "nyanko7/danbooru2023"
|
9 |
-
_REVISION = "main"
|
10 |
|
11 |
|
12 |
class DanbooruDataset(datasets.GeneratorBasedBuilder):
|
@@ -28,23 +28,21 @@ class DanbooruDataset(datasets.GeneratorBasedBuilder):
|
|
28 |
return info
|
29 |
|
30 |
def _split_generators(self, dl_manager: DownloadManager):
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
)
|
37 |
-
|
38 |
-
for
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
post_id = int(os.path.splitext(os.path.basename(image_fname))[0])
|
50 |
-
yield image_fname, {"post_id": post_id}
|
|
|
1 |
import os
|
2 |
+
import posixpath
|
3 |
+
|
4 |
import datasets
|
5 |
+
from datasets import DatasetInfo, DownloadManager
|
6 |
+
from fsspec.core import url_to_fs
|
7 |
+
|
8 |
|
9 |
_EXTENSION = [".png", ".jpg", ".jpeg", ".webp", ".bmp"]
|
|
|
|
|
10 |
|
11 |
|
12 |
class DanbooruDataset(datasets.GeneratorBasedBuilder):
|
|
|
28 |
return info
|
29 |
|
30 |
def _split_generators(self, dl_manager: DownloadManager):
|
31 |
+
base_path = dl_manager._base_path
|
32 |
+
if base_path.startswith(datasets.config.HF_ENDPOINT):
|
33 |
+
base_path = base_path[len(datasets.config.HF_ENDPOINT):].replace("/resolve/", "@", 1)
|
34 |
+
base_path = "hf://" + base_path.lstrip("/")
|
35 |
+
fs, path = url_to_fs(base_path)
|
36 |
+
urls = fs.glob(posixpath.join(path, "**/*.tar"), detail=False)
|
37 |
+
archives = dl_manager.download(["hf://" + url for url in urls])
|
38 |
+
archives = [dl_manager.iter_archive(archives) for archives in archives]
|
39 |
+
return [datasets.SplitGenerator(name="train", gen_kwargs={"archives": archives})]
|
40 |
+
|
41 |
+
def _generate_examples(self, archives):
|
42 |
+
for archive in archives:
|
43 |
+
for path, f in archive:
|
44 |
+
path_root, path_ext = os.path.splitext(path)
|
45 |
+
if path_ext.lower() not in _EXTENSION:
|
46 |
+
continue
|
47 |
+
post_id = int(os.path.basename(path_root))
|
48 |
+
yield path, {"image": {"bytes": f.read()}, "post_id": post_id}
|
|
|
|