Commit
·
02a19c8
1
Parent(s):
123d311
dataset script
Browse files- stained-glass.py +52 -0
stained-glass.py
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""Dataset class for stained-glass dataset."""
|
2 |
+
|
3 |
+
import datasets
|
4 |
+
import os
|
5 |
+
import pandas as pd
|
6 |
+
|
7 |
+
_DESCRIPTION = """Dataset consists of 21 high-resolution images of stained glass art, accompanied by corresponding captions"""
|
8 |
+
_HOMEPAGE = """https://huggingface.co/datasets/abinthomasonline/stained-glass"""
|
9 |
+
_ADJECTIVES = ["", "good", "cropped", "clean", "bright", "cool", "nice", "small", "large", "dark", "weird"]
|
10 |
+
|
11 |
+
|
12 |
+
class StainedGlass(datasets.GeneratorBasedBuilder):
|
13 |
+
"""Stained Glass Images dataset"""
|
14 |
+
|
15 |
+
def _info(self):
|
16 |
+
return datasets.DatasetInfo(
|
17 |
+
description=_DESCRIPTION,
|
18 |
+
features=datasets.Features(
|
19 |
+
{
|
20 |
+
"image": datasets.Image(),
|
21 |
+
"caption": datasets.Value(),
|
22 |
+
}
|
23 |
+
),
|
24 |
+
supervised_keys=("image", "caption"),
|
25 |
+
homepage=_HOMEPAGE,
|
26 |
+
)
|
27 |
+
|
28 |
+
def _split_generators(self, dl_manager):
|
29 |
+
captions_path = dl_manager.download("captions.csv")
|
30 |
+
df = pd.read_csv(captions_path, header=None)
|
31 |
+
image_paths = [os.path.join("images", row[0]) for _, row in df.iterrows()]
|
32 |
+
image_paths = dl_manager.download(image_paths)
|
33 |
+
|
34 |
+
return [
|
35 |
+
datasets.SplitGenerator(
|
36 |
+
name=datasets.Split.TRAIN,
|
37 |
+
gen_kwargs={
|
38 |
+
"captions_path": captions_path,
|
39 |
+
"image_paths": image_paths,
|
40 |
+
},
|
41 |
+
)
|
42 |
+
]
|
43 |
+
|
44 |
+
def _generate_examples(self, captions_path, image_paths):
|
45 |
+
df = pd.read_csv(captions_path, header=None)
|
46 |
+
captions = {row[0]: row[1].replace('"', '') for _, row in df.iterrows()}
|
47 |
+
for adjective in _ADJECTIVES:
|
48 |
+
for i, image_path in enumerate(image_paths):
|
49 |
+
yield i, {
|
50 |
+
"image": image_path,
|
51 |
+
"caption": captions[os.path.basename(image_path)].format(token='<token>', adjective=adjective),
|
52 |
+
}
|