Update imagetest.py
Browse files- imagetest.py +18 -17
imagetest.py
CHANGED
|
@@ -19,7 +19,7 @@ class ImageSet(datasets.GeneratorBasedBuilder):
|
|
| 19 |
return datasets.DatasetInfo(
|
| 20 |
description=_DESCRIPTION,
|
| 21 |
features=datasets.Features({
|
| 22 |
-
"obs": datasets.
|
| 23 |
"actions": datasets.Value("int32"),
|
| 24 |
"rewards": datasets.Value("float32"),
|
| 25 |
"episode_starts": datasets.Value("bool"),
|
|
@@ -31,9 +31,7 @@ class ImageSet(datasets.GeneratorBasedBuilder):
|
|
| 31 |
)
|
| 32 |
|
| 33 |
def _split_generators(self, dl_manager):
|
| 34 |
-
|
| 35 |
-
image_iter = dl_manager.iter_archive(image_data)
|
| 36 |
-
|
| 37 |
info_path = dl_manager.download_and_extract(f"{_REPO}/resolve/main/dataset.tar.gz")
|
| 38 |
|
| 39 |
return [
|
|
@@ -47,18 +45,21 @@ class ImageSet(datasets.GeneratorBasedBuilder):
|
|
| 47 |
]
|
| 48 |
|
| 49 |
def _generate_examples(self, images, infos):
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
with open(f"{infos}/dataset.jsonl", encoding="utf-8") as data:
|
| 52 |
-
for line in data:
|
| 53 |
record = json.loads(line)
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
"maze": dataset_info[info_idx]["maze"],
|
| 63 |
-
"obs": {"path": filepath, "bytes": image.read()},
|
| 64 |
-
}
|
|
|
|
| 19 |
return datasets.DatasetInfo(
|
| 20 |
description=_DESCRIPTION,
|
| 21 |
features=datasets.Features({
|
| 22 |
+
"obs": datasets.Value("string"),
|
| 23 |
"actions": datasets.Value("int32"),
|
| 24 |
"rewards": datasets.Value("float32"),
|
| 25 |
"episode_starts": datasets.Value("bool"),
|
|
|
|
| 31 |
)
|
| 32 |
|
| 33 |
def _split_generators(self, dl_manager):
|
| 34 |
+
image_path = dl_manager.download_and_extract(f"{_REPO}/resolve/main/images.tar.gz")
|
|
|
|
|
|
|
| 35 |
info_path = dl_manager.download_and_extract(f"{_REPO}/resolve/main/dataset.tar.gz")
|
| 36 |
|
| 37 |
return [
|
|
|
|
| 45 |
]
|
| 46 |
|
| 47 |
def _generate_examples(self, images, infos):
|
| 48 |
+
images_paths = f"{images_paths}/images"
|
| 49 |
+
images = [join(images_paths, f) for f in listdir(images_paths) if isfile(join(images_paths, f))]
|
| 50 |
+
|
| 51 |
+
images_dict = {}
|
| 52 |
+
for image in images:
|
| 53 |
+
images_dict[image.split("/")[-1].split(".")[0]] = image
|
| 54 |
+
|
| 55 |
with open(f"{infos}/dataset.jsonl", encoding="utf-8") as data:
|
| 56 |
+
for idx, line in enumerate(data):
|
| 57 |
record = json.loads(line)
|
| 58 |
+
index = record["obs"].split(".")[0]
|
| 59 |
+
yield idx, {
|
| 60 |
+
"obs": images_dict[index],
|
| 61 |
+
"actions": record["actions"],
|
| 62 |
+
"rewards": record["rewards"],
|
| 63 |
+
"episode_starts": record["episode_starts"],
|
| 64 |
+
"maze": record["maze"],
|
| 65 |
+
}
|
|
|
|
|
|
|
|
|