MoaazId commited on
Commit
dc54895
·
1 Parent(s): b3d9e2c

Upload cityscape.py

Browse files
Files changed (1) hide show
  1. cityscape.py +100 -0
cityscape.py ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ from huggingface_hub import hf_hub_url # hf_hub_url is used to construct the URL of a file from the given information.
3
+
4
+ import datasets
5
+ import os
6
+
7
+ #_VERSION = datasets.Version("0.0.2")
8
+
9
+ _DESCRIPTION = "TODO"
10
+ _HOMEPAGE = "TODO"
11
+ _LICENSE = "TODO"
12
+ _CITATION = "TODO"
13
+
14
+ _FEATURES = datasets.Features(
15
+ {
16
+ "image": datasets.Image(),
17
+ "conditioning_image": datasets.Image(),
18
+ "text": datasets.Value("string"),
19
+ },
20
+ )
21
+
22
+ METADATA_URL = hf_hub_url(
23
+ "MoaazId/cityscape",
24
+ filename="train.jsonl",
25
+ repo_type="dataset",
26
+ )
27
+
28
+ IMAGES_URL = hf_hub_url(
29
+ "MoaazId/cityscape",
30
+ filename="leftImg8bit.zip",
31
+ repo_type="dataset",
32
+ )
33
+
34
+ CONDITIONING_IMAGES_URL = hf_hub_url(
35
+ "MoaazId/cityscape",
36
+ filename="gtCoarse.zip",
37
+ repo_type="dataset",
38
+ )
39
+
40
+ _DEFAULT_CONFIG = datasets.BuilderConfig(name="default")
41
+
42
+
43
+ class cityscape(datasets.GeneratorBasedBuilder):
44
+ BUILDER_CONFIGS = [_DEFAULT_CONFIG]
45
+ DEFAULT_CONFIG_NAME = "default"
46
+
47
+ def _info(self):
48
+ return datasets.DatasetInfo(
49
+ description=_DESCRIPTION,
50
+ features=_FEATURES,
51
+ supervised_keys=None,
52
+ homepage=_HOMEPAGE,
53
+ license=_LICENSE,
54
+ citation=_CITATION,
55
+ )
56
+
57
+ def _split_generators(self, dl_manager):
58
+ metadata_path = dl_manager.download(METADATA_URL)
59
+ images_dir = dl_manager.download_and_extract(IMAGES_URL)
60
+ conditioning_images_dir = dl_manager.download_and_extract(
61
+ CONDITIONING_IMAGES_URL
62
+ )
63
+
64
+ return [
65
+ datasets.SplitGenerator(
66
+ name=datasets.Split.TRAIN,
67
+ # These kwargs will be passed to _generate_examples
68
+ gen_kwargs={
69
+ "metadata_path": metadata_path,
70
+ "images_dir": images_dir,
71
+ "conditioning_images_dir": conditioning_images_dir,
72
+ },
73
+ ),
74
+ ]
75
+
76
+ def _generate_examples(self, metadata_path, images_dir, conditioning_images_dir):
77
+ metadata = pd.read_json(metadata_path, lines=True)
78
+
79
+ for _, row in metadata.iterrows():
80
+ text = row["text"]
81
+
82
+ image_path = row["image"]
83
+ image_path = os.path.join(images_dir, image_path)
84
+ image = open(image_path, "rb").read()
85
+
86
+ conditioning_image_path = row["conditioning_image"]
87
+ conditioning_image_path = os.path.join(conditioning_images_dir, conditioning_image_path)
88
+ conditioning_image = open(conditioning_image_path, "rb").read()
89
+
90
+ yield row["image"], {
91
+ "text": text,
92
+ "image": {
93
+ "path": image_path,
94
+ "bytes": image,
95
+ },
96
+ "conditioning_image": {
97
+ "path": conditioning_image_path,
98
+ "bytes": conditioning_image,
99
+ },
100
+ }