Update CLEVR-Sudoku.py
Browse files- CLEVR-Sudoku.py +63 -47
CLEVR-Sudoku.py
CHANGED
@@ -81,24 +81,11 @@ class CLEVRSudoku(datasets.GeneratorBasedBuilder):
|
|
81 |
license=_LICENSE,
|
82 |
)
|
83 |
|
84 |
-
def get_data(self, dl_manager,
|
85 |
-
archive_path = dl_manager.extract(dl_manager.download(url))
|
86 |
-
print(archive_path)
|
87 |
|
88 |
-
|
89 |
-
|
90 |
-
print(type(archive_path))
|
91 |
-
|
92 |
-
# archive_path = os.path.join(dl_manager.download_and_extract(url), url.split('/')[-1].split('.')[0])
|
93 |
-
# print containg folders
|
94 |
-
# print(os.listdir(archive_path))
|
95 |
|
96 |
-
# image_path = os.path.join(
|
97 |
-
# dl_manager.download_and_extract(image_url),
|
98 |
-
# image_url.split("/")[-1].split(".")[0],
|
99 |
-
# )
|
100 |
-
# print(image_path)
|
101 |
-
|
102 |
x = dl_manager.iter_archive(archive_path)
|
103 |
print(x)
|
104 |
|
@@ -140,40 +127,69 @@ class CLEVRSudoku(datasets.GeneratorBasedBuilder):
|
|
140 |
# TODO: define image directory
|
141 |
meta_data_path = dl_manager.download_and_extract(self.config.data_url)
|
142 |
|
143 |
-
archive_path, sudokus, options, labels, attributes = self.get_data(
|
144 |
-
|
145 |
-
)
|
|
|
|
|
|
|
146 |
|
|
|
147 |
return [
|
148 |
datasets.SplitGenerator(
|
149 |
name=datasets.Split.TRAIN,
|
150 |
-
gen_kwargs={
|
151 |
-
|
152 |
-
"sudokus": sudokus,
|
153 |
-
"options": options,
|
154 |
-
"labels": labels,
|
155 |
-
"attributes": attributes,
|
156 |
-
},
|
157 |
-
),
|
158 |
-
datasets.SplitGenerator(
|
159 |
-
name=datasets.Split.TEST,
|
160 |
-
gen_kwargs={
|
161 |
-
"image_dir": meta_data_path,
|
162 |
-
"sudokus": sudokus,
|
163 |
-
"options": options,
|
164 |
-
"labels": labels,
|
165 |
-
"attributes": attributes,
|
166 |
-
},
|
167 |
-
),
|
168 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
169 |
|
170 |
-
|
171 |
-
for i, (sudoku, opt, label, attr) in enumerate(
|
172 |
-
|
173 |
-
):
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
|
|
81 |
license=_LICENSE,
|
82 |
)
|
83 |
|
84 |
+
def get_data(self, dl_manager, archive_url, image_url):
|
|
|
|
|
85 |
|
86 |
+
# Download and extract the dataset archive
|
87 |
+
archive_path = dl_manager.download_and_extract(archive_url)
|
|
|
|
|
|
|
|
|
|
|
88 |
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
x = dl_manager.iter_archive(archive_path)
|
90 |
print(x)
|
91 |
|
|
|
127 |
# TODO: define image directory
|
128 |
meta_data_path = dl_manager.download_and_extract(self.config.data_url)
|
129 |
|
130 |
+
# archive_path, sudokus, options, labels, attributes = self.get_data(
|
131 |
+
# dl_manager, self.config.data_url, self.config.image_url
|
132 |
+
# )
|
133 |
+
|
134 |
+
# Download and extract the dataset archive
|
135 |
+
archive_path = dl_manager.download_and_extract(self.config.data_url)
|
136 |
|
137 |
+
# Define the dataset splits
|
138 |
return [
|
139 |
datasets.SplitGenerator(
|
140 |
name=datasets.Split.TRAIN,
|
141 |
+
gen_kwargs={"archive_path": archive_path}
|
142 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
143 |
]
|
144 |
+
|
145 |
+
# return [
|
146 |
+
# datasets.SplitGenerator(
|
147 |
+
# name=datasets.Split.TRAIN,
|
148 |
+
# gen_kwargs={
|
149 |
+
# "image_dir": meta_data_path,
|
150 |
+
# "sudokus": sudokus,
|
151 |
+
# "options": options,
|
152 |
+
# "labels": labels,
|
153 |
+
# "attributes": attributes,
|
154 |
+
# },
|
155 |
+
# ),
|
156 |
+
# datasets.SplitGenerator(
|
157 |
+
# name=datasets.Split.TEST,
|
158 |
+
# gen_kwargs={
|
159 |
+
# "image_dir": meta_data_path,
|
160 |
+
# "sudokus": sudokus,
|
161 |
+
# "options": options,
|
162 |
+
# "labels": labels,
|
163 |
+
# "attributes": attributes,
|
164 |
+
# },
|
165 |
+
# ),
|
166 |
+
# ]
|
167 |
+
|
168 |
+
def _generate_examples(self, archive_path):
|
169 |
+
"""Yields examples from the archive, assuming JSON files inside a 'json' folder."""
|
170 |
+
# This uses `dl_manager.iter_archive` to iterate over files in the archive
|
171 |
+
with open(archive_path, "rb") as f:
|
172 |
+
for i, (file_name, file_handle) in enumerate(datasets.utils.iter_archive(f)):
|
173 |
+
# Only process files that are in the 'json/' folder and end with '.json'
|
174 |
+
if file_name.startswith("json/") and file_name.endswith(".json"):
|
175 |
+
# Read and parse the JSON content
|
176 |
+
json_content = json.load(file_handle)
|
177 |
+
|
178 |
+
# Yield the parsed JSON content along with the file name
|
179 |
+
yield i, {
|
180 |
+
"sudoku": sudoku,
|
181 |
+
"options": opt,
|
182 |
+
"label": label,
|
183 |
+
"attributes": attr,
|
184 |
+
}
|
185 |
|
186 |
+
|
187 |
+
# for i, (sudoku, opt, label, attr) in enumerate(
|
188 |
+
# zip(sudokus, options, labels, attributes)
|
189 |
+
# ):
|
190 |
+
# yield i, {
|
191 |
+
# "sudoku": sudoku,
|
192 |
+
# "options": opt,
|
193 |
+
# "label": label,
|
194 |
+
# "attributes": attr,
|
195 |
+
# }
|