Update pidray-semantics.py
Browse files- pidray-semantics.py +32 -22
pidray-semantics.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import json
|
| 2 |
|
| 3 |
import datasets
|
|
@@ -7,25 +8,23 @@ from datasets.tasks import QuestionAnsweringExtractive
|
|
| 7 |
logger = datasets.logging.get_logger(__name__)
|
| 8 |
|
| 9 |
_URL = "https://huggingface.co/datasets/jaradat/pidray-semantics/resolve/main/pixel_values.tar.gz"
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
'ccc',
|
| 13 |
-
'ddd',
|
| 14 |
-
'eee' ]
|
| 15 |
|
| 16 |
|
| 17 |
-
class
|
| 18 |
|
| 19 |
def _info(self):
|
| 20 |
return datasets.DatasetInfo(
|
| 21 |
features=datasets.Features(
|
| 22 |
{
|
| 23 |
-
|
| 24 |
-
"
|
|
|
|
| 25 |
}
|
| 26 |
),
|
| 27 |
-
|
| 28 |
-
|
| 29 |
supervised_keys=None,
|
| 30 |
homepage="https://huggingface.co/datasets/jaradat/pidray-semantics",
|
| 31 |
|
|
@@ -33,28 +32,39 @@ class PIDrayTargz(datasets.GeneratorBasedBuilder):
|
|
| 33 |
|
| 34 |
def _split_generators(self, dl_manager):
|
| 35 |
path = dl_manager.download(_URL)
|
| 36 |
-
image_iters = dl_manager.iter_archive(path)
|
| 37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
return [
|
| 39 |
datasets.SplitGenerator(
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
|
|
|
| 43 |
}
|
| 44 |
-
)
|
| 45 |
|
| 46 |
]
|
| 47 |
|
| 48 |
-
def _generate_examples(self, images):
|
| 49 |
-
|
| 50 |
idx = 0
|
| 51 |
-
|
| 52 |
for filepath, image in images:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
|
|
|
| 54 |
yield idx, {
|
| 55 |
-
"
|
| 56 |
-
"
|
| 57 |
}
|
|
|
|
| 58 |
idx += 1
|
| 59 |
-
if idx == 4:
|
| 60 |
-
break
|
|
|
|
| 1 |
+
|
| 2 |
import json
|
| 3 |
|
| 4 |
import datasets
|
|
|
|
| 8 |
logger = datasets.logging.get_logger(__name__)
|
| 9 |
|
| 10 |
_URL = "https://huggingface.co/datasets/jaradat/pidray-semantics/resolve/main/pixel_values.tar.gz"
|
| 11 |
+
_URL2 = "https://huggingface.co/datasets/jaradat/pidray-semantics/resolve/main/label.tar.gz"
|
| 12 |
+
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
|
| 15 |
+
class pidraySemantics(datasets.GeneratorBasedBuilder):
|
| 16 |
|
| 17 |
def _info(self):
|
| 18 |
return datasets.DatasetInfo(
|
| 19 |
features=datasets.Features(
|
| 20 |
{
|
| 21 |
+
|
| 22 |
+
"pixel_values": datasets.Image(),
|
| 23 |
+
"label": datasets.Image(),
|
| 24 |
}
|
| 25 |
),
|
| 26 |
+
|
| 27 |
+
|
| 28 |
supervised_keys=None,
|
| 29 |
homepage="https://huggingface.co/datasets/jaradat/pidray-semantics",
|
| 30 |
|
|
|
|
| 32 |
|
| 33 |
def _split_generators(self, dl_manager):
|
| 34 |
path = dl_manager.download(_URL)
|
| 35 |
+
image_iters = dl_manager.iter_archive(path)
|
| 36 |
|
| 37 |
+
|
| 38 |
+
path2 = dl_manager.download(_URL2)
|
| 39 |
+
label_file = dl_manager.extract(path2)
|
| 40 |
+
with open(label_file, "r") as f:
|
| 41 |
+
label_data = json.load(f)
|
| 42 |
+
|
| 43 |
return [
|
| 44 |
datasets.SplitGenerator(
|
| 45 |
+
name=datasets.Split.TRAIN,
|
| 46 |
+
gen_kwargs={
|
| 47 |
+
"images": image_iters,
|
| 48 |
+
"label_data": label_data,
|
| 49 |
}
|
| 50 |
+
)
|
| 51 |
|
| 52 |
]
|
| 53 |
|
| 54 |
+
def _generate_examples(self, images, label_data):
|
| 55 |
+
|
| 56 |
idx = 0
|
| 57 |
+
|
| 58 |
for filepath, image in images:
|
| 59 |
+
label_info = label_data[idx]
|
| 60 |
+
label_filepath = label_info["filepath"]
|
| 61 |
+
with open(label_filepath, "rb") as f:
|
| 62 |
+
label_image = f.read()
|
| 63 |
|
| 64 |
+
|
| 65 |
yield idx, {
|
| 66 |
+
"pixel_values": {"path": filepath, "bytes": image.read()},
|
| 67 |
+
"label": {"path": label_filepath, "bytes": label_image},
|
| 68 |
}
|
| 69 |
+
|
| 70 |
idx += 1
|
|
|
|
|
|