Datasets:
Update diffusiondb-pixelart.py
Browse files- diffusiondb-pixelart.py +8 -95
diffusiondb-pixelart.py
CHANGED
@@ -41,9 +41,7 @@ _VERSION = datasets.Version("0.9.1")
|
|
41 |
# hf_hub_url() provides a more flexible way to resolve the file URLs
|
42 |
# https://huggingface.co/datasets/jainr3/diffusiondb-pixelart/resolve/main/images/part-000001.zip
|
43 |
_URLS = {}
|
44 |
-
_URLS_LARGE = {}
|
45 |
_PART_IDS = range(1, 2001)
|
46 |
-
_PART_IDS_LARGE = range(1, 14001)
|
47 |
|
48 |
for i in _PART_IDS:
|
49 |
_URLS[i] = hf_hub_url(
|
@@ -52,31 +50,12 @@ for i in _PART_IDS:
|
|
52 |
repo_type="dataset",
|
53 |
)
|
54 |
|
55 |
-
for i in _PART_IDS_LARGE:
|
56 |
-
if i < 10001:
|
57 |
-
_URLS_LARGE[i] = hf_hub_url(
|
58 |
-
"jainr3/diffusiondb-pixelart",
|
59 |
-
filename=f"diffusiondb-pixelart-large-part-1/part-{i:06}.zip",
|
60 |
-
repo_type="dataset",
|
61 |
-
)
|
62 |
-
else:
|
63 |
-
_URLS_LARGE[i] = hf_hub_url(
|
64 |
-
"jainr3/diffusiondb-pixelart",
|
65 |
-
filename=f"diffusiondb-pixelart-large-part-2/part-{i:06}.zip",
|
66 |
-
repo_type="dataset",
|
67 |
-
)
|
68 |
|
69 |
# Add the metadata parquet URL as well
|
70 |
_URLS["metadata"] = hf_hub_url(
|
71 |
"jainr3/diffusiondb-pixelart", filename="metadata.parquet", repo_type="dataset"
|
72 |
)
|
73 |
|
74 |
-
_URLS_LARGE["metadata"] = hf_hub_url(
|
75 |
-
"jainr3/diffusiondb-pixelart",
|
76 |
-
filename="metadata-large.parquet",
|
77 |
-
repo_type="dataset",
|
78 |
-
)
|
79 |
-
|
80 |
_SAMPLER_DICT = {
|
81 |
1: "ddim",
|
82 |
2: "plms",
|
@@ -93,16 +72,14 @@ _SAMPLER_DICT = {
|
|
93 |
class DiffusionDBConfig(datasets.BuilderConfig):
|
94 |
"""BuilderConfig for DiffusionDB."""
|
95 |
|
96 |
-
def __init__(self, part_ids,
|
97 |
"""BuilderConfig for DiffusionDB.
|
98 |
Args:
|
99 |
part_ids([int]): A list of part_ids.
|
100 |
-
is_large(bool): If downloading data from DiffusionDB Large (14 million)
|
101 |
**kwargs: keyword arguments forwarded to super.
|
102 |
"""
|
103 |
super(DiffusionDBConfig, self).__init__(version=_VERSION, **kwargs)
|
104 |
self.part_ids = part_ids
|
105 |
-
self.is_large = is_large
|
106 |
|
107 |
|
108 |
class DiffusionDB(datasets.GeneratorBasedBuilder):
|
@@ -114,50 +91,8 @@ class DiffusionDB(datasets.GeneratorBasedBuilder):
|
|
114 |
# as the config key)
|
115 |
for num_k in [1, 5, 10, 50, 100, 500, 1000]:
|
116 |
for sampling in ["first", "random"]:
|
117 |
-
|
118 |
-
|
119 |
-
subset_str = "large_" if is_large else "2m_"
|
120 |
-
|
121 |
-
if sampling == "random":
|
122 |
-
# Name the config
|
123 |
-
cur_name = subset_str + "random_" + num_k_str
|
124 |
-
|
125 |
-
# Add a short description for each config
|
126 |
-
cur_description = (
|
127 |
-
f"Random {num_k_str} images with their prompts and parameters"
|
128 |
-
)
|
129 |
-
|
130 |
-
# Sample part_ids
|
131 |
-
total_part_ids = _PART_IDS_LARGE if is_large else _PART_IDS
|
132 |
-
part_ids = np.random.choice(
|
133 |
-
total_part_ids, num_k, replace=False
|
134 |
-
).tolist()
|
135 |
-
else:
|
136 |
-
# Name the config
|
137 |
-
cur_name = subset_str + "first_" + num_k_str
|
138 |
-
|
139 |
-
# Add a short description for each config
|
140 |
-
cur_description = f"The first {num_k_str} images in this dataset with their prompts and parameters"
|
141 |
-
|
142 |
-
# Sample part_ids
|
143 |
-
total_part_ids = _PART_IDS_LARGE if is_large else _PART_IDS
|
144 |
-
part_ids = total_part_ids[1 : num_k + 1]
|
145 |
-
|
146 |
-
# Create configs
|
147 |
-
BUILDER_CONFIGS.append(
|
148 |
-
DiffusionDBConfig(
|
149 |
-
name=cur_name,
|
150 |
-
part_ids=part_ids,
|
151 |
-
is_large=is_large,
|
152 |
-
description=cur_description,
|
153 |
-
),
|
154 |
-
)
|
155 |
-
|
156 |
-
# Add few more options for Large only
|
157 |
-
for num_k in [5000, 10000]:
|
158 |
-
for sampling in ["first", "random"]:
|
159 |
-
num_k_str = f"{num_k // 1000}m"
|
160 |
-
subset_str = "large_"
|
161 |
|
162 |
if sampling == "random":
|
163 |
# Name the config
|
@@ -169,7 +104,7 @@ class DiffusionDB(datasets.GeneratorBasedBuilder):
|
|
169 |
)
|
170 |
|
171 |
# Sample part_ids
|
172 |
-
total_part_ids =
|
173 |
part_ids = np.random.choice(
|
174 |
total_part_ids, num_k, replace=False
|
175 |
).tolist()
|
@@ -181,7 +116,7 @@ class DiffusionDB(datasets.GeneratorBasedBuilder):
|
|
181 |
cur_description = f"The first {num_k_str} images in this dataset with their prompts and parameters"
|
182 |
|
183 |
# Sample part_ids
|
184 |
-
total_part_ids =
|
185 |
part_ids = total_part_ids[1 : num_k + 1]
|
186 |
|
187 |
# Create configs
|
@@ -189,26 +124,16 @@ class DiffusionDB(datasets.GeneratorBasedBuilder):
|
|
189 |
DiffusionDBConfig(
|
190 |
name=cur_name,
|
191 |
part_ids=part_ids,
|
192 |
-
is_large=True,
|
193 |
description=cur_description,
|
194 |
),
|
195 |
)
|
196 |
|
197 |
-
|
|
|
198 |
BUILDER_CONFIGS.append(
|
199 |
DiffusionDBConfig(
|
200 |
name="2m_all",
|
201 |
part_ids=_PART_IDS,
|
202 |
-
is_large=False,
|
203 |
-
description="All images with their prompts and parameters",
|
204 |
-
),
|
205 |
-
)
|
206 |
-
|
207 |
-
BUILDER_CONFIGS.append(
|
208 |
-
DiffusionDBConfig(
|
209 |
-
name="large_all",
|
210 |
-
part_ids=_PART_IDS_LARGE,
|
211 |
-
is_large=True,
|
212 |
description="All images with their prompts and parameters",
|
213 |
),
|
214 |
)
|
@@ -218,19 +143,10 @@ class DiffusionDB(datasets.GeneratorBasedBuilder):
|
|
218 |
DiffusionDBConfig(
|
219 |
name="2m_text_only",
|
220 |
part_ids=[],
|
221 |
-
is_large=False,
|
222 |
description="Only include all prompts and parameters (no image)",
|
223 |
),
|
224 |
)
|
225 |
|
226 |
-
BUILDER_CONFIGS.append(
|
227 |
-
DiffusionDBConfig(
|
228 |
-
name="large_text_only",
|
229 |
-
part_ids=[],
|
230 |
-
is_large=True,
|
231 |
-
description="Only include all prompts and parameters (no image)",
|
232 |
-
),
|
233 |
-
)
|
234 |
|
235 |
# Default to only load 1k random images
|
236 |
DEFAULT_CONFIG_NAME = "2m_random_1k"
|
@@ -300,10 +216,7 @@ class DiffusionDB(datasets.GeneratorBasedBuilder):
|
|
300 |
json_paths = []
|
301 |
|
302 |
# Resolve the urls
|
303 |
-
|
304 |
-
urls = _URLS_LARGE
|
305 |
-
else:
|
306 |
-
urls = _URLS
|
307 |
|
308 |
for cur_part_id in self.config.part_ids:
|
309 |
cur_url = urls[cur_part_id]
|
|
|
41 |
# hf_hub_url() provides a more flexible way to resolve the file URLs
|
42 |
# https://huggingface.co/datasets/jainr3/diffusiondb-pixelart/resolve/main/images/part-000001.zip
|
43 |
_URLS = {}
|
|
|
44 |
_PART_IDS = range(1, 2001)
|
|
|
45 |
|
46 |
for i in _PART_IDS:
|
47 |
_URLS[i] = hf_hub_url(
|
|
|
50 |
repo_type="dataset",
|
51 |
)
|
52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
|
54 |
# Add the metadata parquet URL as well
|
55 |
_URLS["metadata"] = hf_hub_url(
|
56 |
"jainr3/diffusiondb-pixelart", filename="metadata.parquet", repo_type="dataset"
|
57 |
)
|
58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
_SAMPLER_DICT = {
|
60 |
1: "ddim",
|
61 |
2: "plms",
|
|
|
72 |
class DiffusionDBConfig(datasets.BuilderConfig):
|
73 |
"""BuilderConfig for DiffusionDB."""
|
74 |
|
75 |
+
def __init__(self, part_ids, **kwargs):
|
76 |
"""BuilderConfig for DiffusionDB.
|
77 |
Args:
|
78 |
part_ids([int]): A list of part_ids.
|
|
|
79 |
**kwargs: keyword arguments forwarded to super.
|
80 |
"""
|
81 |
super(DiffusionDBConfig, self).__init__(version=_VERSION, **kwargs)
|
82 |
self.part_ids = part_ids
|
|
|
83 |
|
84 |
|
85 |
class DiffusionDB(datasets.GeneratorBasedBuilder):
|
|
|
91 |
# as the config key)
|
92 |
for num_k in [1, 5, 10, 50, 100, 500, 1000]:
|
93 |
for sampling in ["first", "random"]:
|
94 |
+
num_k_str = f"{num_k}k" if num_k < 1000 else f"{num_k // 1000}m"
|
95 |
+
subset_str = "2m_"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
|
97 |
if sampling == "random":
|
98 |
# Name the config
|
|
|
104 |
)
|
105 |
|
106 |
# Sample part_ids
|
107 |
+
total_part_ids = _PART_IDS
|
108 |
part_ids = np.random.choice(
|
109 |
total_part_ids, num_k, replace=False
|
110 |
).tolist()
|
|
|
116 |
cur_description = f"The first {num_k_str} images in this dataset with their prompts and parameters"
|
117 |
|
118 |
# Sample part_ids
|
119 |
+
total_part_ids = _PART_IDS
|
120 |
part_ids = total_part_ids[1 : num_k + 1]
|
121 |
|
122 |
# Create configs
|
|
|
124 |
DiffusionDBConfig(
|
125 |
name=cur_name,
|
126 |
part_ids=part_ids,
|
|
|
127 |
description=cur_description,
|
128 |
),
|
129 |
)
|
130 |
|
131 |
+
|
132 |
+
# Need to manually add all (2m)
|
133 |
BUILDER_CONFIGS.append(
|
134 |
DiffusionDBConfig(
|
135 |
name="2m_all",
|
136 |
part_ids=_PART_IDS,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
137 |
description="All images with their prompts and parameters",
|
138 |
),
|
139 |
)
|
|
|
143 |
DiffusionDBConfig(
|
144 |
name="2m_text_only",
|
145 |
part_ids=[],
|
|
|
146 |
description="Only include all prompts and parameters (no image)",
|
147 |
),
|
148 |
)
|
149 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
150 |
|
151 |
# Default to only load 1k random images
|
152 |
DEFAULT_CONFIG_NAME = "2m_random_1k"
|
|
|
216 |
json_paths = []
|
217 |
|
218 |
# Resolve the urls
|
219 |
+
urls = _URLS
|
|
|
|
|
|
|
220 |
|
221 |
for cur_part_id in self.config.part_ids:
|
222 |
cur_url = urls[cur_part_id]
|