Commit
•
b72719f
1
Parent(s):
88ab8ee
Upload 3 files
Browse files- dataset.tar.gz +3 -0
- images.tar.gz +3 -0
- imagetrain.py +80 -0
dataset.tar.gz
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:5650d9fbc9f7cf9b94bb382e13bdbc03225ef0452c2e32c8b1db93a99c86b71e
|
3 |
+
size 48219
|
images.tar.gz
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d7d1a3ae9c5a3ae0927bc99a25d62c7ed892a9447ff757d03c5c51e66d4112e3
|
3 |
+
size 8394634
|
imagetrain.py
ADDED
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import datasets
|
2 |
+
import json
|
3 |
+
from os import listdir
|
4 |
+
from os.path import isfile, join
|
5 |
+
|
6 |
+
|
7 |
+
_CITATION = ""
|
8 |
+
|
9 |
+
_DESCRIPTION = "Dataset for training agents with Maze-v0 environment."
|
10 |
+
|
11 |
+
_HOMEPAGE = "https://huggingface.co/datasets/NathanGavenski/imagetrain"
|
12 |
+
|
13 |
+
_LICENSE = ""
|
14 |
+
|
15 |
+
_REPO = "https://huggingface.co/datasets/NathanGavenski/imagetrain"
|
16 |
+
|
17 |
+
|
18 |
+
class ImageSet(datasets.GeneratorBasedBuilder):
|
19 |
+
|
20 |
+
def _info(self):
|
21 |
+
return datasets.DatasetInfo(
|
22 |
+
description=_DESCRIPTION,
|
23 |
+
features=datasets.Features({
|
24 |
+
"obs": datasets.Value("string"),
|
25 |
+
"actions": datasets.Value("int32"),
|
26 |
+
"rewards": datasets.Value("float32"),
|
27 |
+
"episode_starts": datasets.Value("bool"),
|
28 |
+
"maze": datasets.Value("string"),
|
29 |
+
}),
|
30 |
+
supervised_keys=None,
|
31 |
+
homepage=_HOMEPAGE,
|
32 |
+
citation=_CITATION,
|
33 |
+
)
|
34 |
+
|
35 |
+
def _split_generators(self, dl_manager):
|
36 |
+
image_path = dl_manager.download_and_extract(f"{_REPO}/resolve/main/images.tar.gz")
|
37 |
+
info_path = dl_manager.download_and_extract(f"{_REPO}/resolve/main/dataset.tar.gz")
|
38 |
+
return [
|
39 |
+
datasets.SplitGenerator(
|
40 |
+
name="all_routes",
|
41 |
+
gen_kwargs={
|
42 |
+
"images": image_path,
|
43 |
+
"infos": f"{info_path}/all_routes.jsonl"
|
44 |
+
}
|
45 |
+
),
|
46 |
+
datasets.SplitGenerator(
|
47 |
+
name="single_route",
|
48 |
+
gen_kwargs={
|
49 |
+
"images": image_path,
|
50 |
+
"infos": f"{info_path}/single_route.jsonl"
|
51 |
+
}
|
52 |
+
),
|
53 |
+
datasets.SplitGenerator(
|
54 |
+
name="shortest_route",
|
55 |
+
gen_kwargs={
|
56 |
+
"images": image_path,
|
57 |
+
"infos": f"{info_path}/shortest_route.jsonl"
|
58 |
+
}
|
59 |
+
),
|
60 |
+
]
|
61 |
+
|
62 |
+
def _generate_examples(self, images, infos):
|
63 |
+
images_paths = f"{images}/images"
|
64 |
+
images = [join(images_paths, f) for f in listdir(images_paths) if isfile(join(images_paths, f))]
|
65 |
+
|
66 |
+
images_dict = {}
|
67 |
+
for image in images:
|
68 |
+
images_dict[image.split("/")[-1].split(".")[0]] = image
|
69 |
+
|
70 |
+
with open(infos, encoding="utf-8") as data:
|
71 |
+
for idx, line in enumerate(data):
|
72 |
+
record = json.loads(line)
|
73 |
+
index = record["obs"].split(".")[0]
|
74 |
+
yield idx, {
|
75 |
+
"obs": images_dict[index],
|
76 |
+
"actions": record["actions"],
|
77 |
+
"rewards": record["rewards"],
|
78 |
+
"episode_starts": record["episode_starts"],
|
79 |
+
"maze": record["maze"],
|
80 |
+
}
|