Commit ·
89c644a
1
Parent(s): 97dd2a0
fix
Browse files
MAMe.py
CHANGED
|
@@ -18,9 +18,6 @@ import datasets
|
|
| 18 |
import csv
|
| 19 |
import os
|
| 20 |
|
| 21 |
-
import zipfile
|
| 22 |
-
import io
|
| 23 |
-
|
| 24 |
_CITATION = """@inproceedings{10.1007/978-3-642-33783-3_36,
|
| 25 |
author = {Palermo, Frank and Hays, James and Efros, Alexei A.},
|
| 26 |
title = {Dating Historical Color Images},
|
|
@@ -54,20 +51,21 @@ _URLS = {
|
|
| 54 |
}
|
| 55 |
|
| 56 |
|
| 57 |
-
def generate_mapping_dict(
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
|
|
|
| 71 |
return mapping_dict
|
| 72 |
|
| 73 |
|
|
@@ -146,7 +144,8 @@ class MAMe(datasets.GeneratorBasedBuilder):
|
|
| 146 |
)
|
| 147 |
|
| 148 |
def _split_generators(self, dl_manager):
|
| 149 |
-
metadata = dl_manager.
|
|
|
|
| 150 |
images = dl_manager.download_and_extract(self.config.image_data_url)
|
| 151 |
return [
|
| 152 |
datasets.SplitGenerator(
|
|
@@ -176,15 +175,10 @@ class MAMe(datasets.GeneratorBasedBuilder):
|
|
| 176 |
]
|
| 177 |
|
| 178 |
def _generate_examples(self, metadata, images, split):
|
| 179 |
-
if self.config.name ==
|
| 180 |
-
from PIL import Image
|
| 181 |
Image.MAX_IMAGE_PIXELS = None
|
| 182 |
-
|
| 183 |
-
with zipfile.ZipFile(
|
| 184 |
-
f"{metadata}/MAMe_metadata.zip"
|
| 185 |
-
) as z:
|
| 186 |
-
with io.BytesIO(z.read("MAMe_dataset.csv")) as f:
|
| 187 |
-
mapping = generate_mapping_dict(f)
|
| 188 |
subset = mapping[split]
|
| 189 |
for i, kv in enumerate(subset.items()):
|
| 190 |
k, v = kv
|
|
|
|
| 18 |
import csv
|
| 19 |
import os
|
| 20 |
|
|
|
|
|
|
|
|
|
|
| 21 |
_CITATION = """@inproceedings{10.1007/978-3-642-33783-3_36,
|
| 22 |
author = {Palermo, Frank and Hays, James and Efros, Alexei A.},
|
| 23 |
title = {Dating Historical Color Images},
|
|
|
|
| 51 |
}
|
| 52 |
|
| 53 |
|
| 54 |
+
def generate_mapping_dict(csv_file):
|
| 55 |
+
with open(csv_file) as f:
|
| 56 |
+
mapping_dict = {}
|
| 57 |
+
dictreater = csv.DictReader(f)
|
| 58 |
+
for row in dictreater:
|
| 59 |
+
split = row["Subset"]
|
| 60 |
+
image_file = row["Image file"]
|
| 61 |
+
del row["Image file"]
|
| 62 |
+
del row["Subset"]
|
| 63 |
+
# add row to subset dictionary
|
| 64 |
+
row_dict = {image_file: row}
|
| 65 |
+
if split not in mapping_dict:
|
| 66 |
+
mapping_dict[split] = row_dict
|
| 67 |
+
else:
|
| 68 |
+
mapping_dict[split].update(row_dict)
|
| 69 |
return mapping_dict
|
| 70 |
|
| 71 |
|
|
|
|
| 144 |
)
|
| 145 |
|
| 146 |
def _split_generators(self, dl_manager):
|
| 147 |
+
metadata = dl_manager.download_and_extract(_URLS["metadata"])
|
| 148 |
+
metadata = os.path.join(metadata, "MAMe_dataset.csv")
|
| 149 |
images = dl_manager.download_and_extract(self.config.image_data_url)
|
| 150 |
return [
|
| 151 |
datasets.SplitGenerator(
|
|
|
|
| 175 |
]
|
| 176 |
|
| 177 |
def _generate_examples(self, metadata, images, split):
|
| 178 |
+
if self.config.name == 'full':
|
| 179 |
+
from PIL import Image # to prevent decompression bomb warnings
|
| 180 |
Image.MAX_IMAGE_PIXELS = None
|
| 181 |
+
mapping = generate_mapping_dict(metadata)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
subset = mapping[split]
|
| 183 |
for i, kv in enumerate(subset.items()):
|
| 184 |
k, v = kv
|