imagetest / imagetest.py
NathanGavenski's picture
Update imagetest.py
7b817f2 verified
raw
history blame
2.03 kB
import datasets
import json
_CITATION = ""
_DESCRIPTION = "Dataset for training agents with Maze-v0 environment."
_HOMEPAGE = "https://huggingface.co/datasets/NathanGavenski/imagetest"
_LICENSE = ""
_REPO = "https://huggingface.co/datasets/NathanGavenski/imagetest"
class ImageSet(datasets.GeneratorBasedBuilder):
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features({
"obs": datasets.Image(),
"actions": datasets.Value("int32"),
"rewards": datasets.Value("float32"),
"episode_starts": datasets.Value("bool"),
"maze": datasets.Value("string"),
"image": datasets.Image()
}),
supervised_keys=None,
homepage=_HOMEPAGE,
citation=_CITATION,
)
def _split_generators(self, dl_manager):
image_path = dl_manager.download_and_extract(f"{_REPO}/resolve/main/images.tar.gz")
info_path = dl_manager.download_and_extract(f"{_REPO}/resolve/main/dataset.tar.gz")
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"images": f"{image_path}/images",
"infos": info_path
}
),
]
def _generate_examples(self, images, infos):
print(images)
with open(f"{infos}/dataset.jsonl", encoding="utf-8") as data:
for idx, line in enumerate(data):
record = json.loads(line)
image = record["obs"].split(".")[0]
yield idx, {
"obs":
}
# for idx, ((filepath, image), info) in enumerate(zip(images, infos)):
# for idx, info in enumerate(infos):
# print(idx, info)
# yield idx, {
# # "image": {"path": filepath, "bytes": image.read()},
# }