Delete cityscape.py
Browse files- cityscape.py +0 -130
cityscape.py
DELETED
@@ -1,130 +0,0 @@
|
|
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/train/"+f"{city}", #M
|
31 |
-
repo_type="dataset",
|
32 |
-
)
|
33 |
-
|
34 |
-
CONDITIONING_IMAGES_URL = hf_hub_url(
|
35 |
-
"MoaazId/cityscape",
|
36 |
-
filename="gtCoarse.zip/train/"+f"{city}", #M
|
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 |
-
|
65 |
-
# Iterate through the city folders in the image directory
|
66 |
-
for city_folder in os.listdir(images_dir):
|
67 |
-
city_dir = os.path.join(images_dir, city_folder)
|
68 |
-
|
69 |
-
# Iterate through image files in the city directory
|
70 |
-
for image_filename in os.listdir(city_dir):
|
71 |
-
# Extract relevant information from the image filename
|
72 |
-
parts = image_filename.split("_")
|
73 |
-
city = parts[0]
|
74 |
-
seq = parts[1]
|
75 |
-
frame = parts[2]
|
76 |
-
|
77 |
-
# Construct the paths to the image and conditioning image
|
78 |
-
image_path = os.path.join(city_dir, image_filename)
|
79 |
-
conditioning_image_filename = f"{city}_{seq}_{frame}_gtCoarse_color.png"
|
80 |
-
conditioning_image_path = os.path.join(conditioning_dir, city_folder+"/"+conditioning_image_filename)
|
81 |
-
|
82 |
-
# Create a dataset entry as a dictionary
|
83 |
-
entry = {
|
84 |
-
"text": "A view to a street from a car's front window",
|
85 |
-
"image": image_path,
|
86 |
-
"conditioning_image": conditioning_image_path,
|
87 |
-
}
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
return [
|
93 |
-
datasets.SplitGenerator(
|
94 |
-
name=datasets.Split.TRAIN,
|
95 |
-
# These kwargs will be passed to _generate_examples
|
96 |
-
gen_kwargs={
|
97 |
-
"metadata_path": metadata_path,
|
98 |
-
"images_dir": images_dir,
|
99 |
-
"conditioning_images_dir": conditioning_images_dir,
|
100 |
-
},
|
101 |
-
),
|
102 |
-
]
|
103 |
-
|
104 |
-
def _generate_examples(self, metadata_path, images_dir, conditioning_images_dir):
|
105 |
-
metadata = pd.read_json(metadata_path, lines=True)
|
106 |
-
|
107 |
-
for _, row in metadata.iterrows():
|
108 |
-
text = row["text"]
|
109 |
-
|
110 |
-
image_path = row["image"]
|
111 |
-
image_path = os.path.join(images_dir, image_path)
|
112 |
-
image = open(image_path, "rb").read()
|
113 |
-
|
114 |
-
conditioning_image_path = row["conditioning_image"]
|
115 |
-
conditioning_image_path = os.path.join(
|
116 |
-
conditioning_images_dir, row["conditioning_image"]
|
117 |
-
)
|
118 |
-
conditioning_image = open(conditioning_image_path, "rb").read()
|
119 |
-
|
120 |
-
yield row["image"], {
|
121 |
-
"text": text,
|
122 |
-
"image": {
|
123 |
-
"path": image_path,
|
124 |
-
"bytes": image,
|
125 |
-
},
|
126 |
-
"conditioning_image": {
|
127 |
-
"path": conditioning_image_path,
|
128 |
-
"bytes": conditioning_image,
|
129 |
-
},
|
130 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|