|
import pickle |
|
|
|
import datasets |
|
import numpy as np |
|
|
|
|
|
|
|
_BASE_URL = "https://huggingface.co/datasets/marktrovinger/cartpole_gym_replay/resolve/main" |
|
_DATA_URL = f"{_BASE_URL}/replay_buffer_npz.npz" |
|
|
|
_DESCRIPTION = """ \ |
|
Testing a cartpole replay. |
|
""" |
|
|
|
_HOMEPAGE = "blah" |
|
|
|
_LICENSE = "MIT" |
|
|
|
|
|
class DecisionTransformerGymDataset(datasets.GeneratorBasedBuilder): |
|
def _info(self): |
|
|
|
features = datasets.Features( |
|
{ |
|
"observations": datasets.Sequence(datasets.Sequence(datasets.Value("float32"))), |
|
"actions": datasets.Sequence(datasets.Sequence(datasets.Value("float32"))), |
|
"rewards": datasets.Sequence(datasets.Value("float32")), |
|
"dones": datasets.Sequence(datasets.Value("float32")), |
|
|
|
} |
|
) |
|
|
|
return datasets.DatasetInfo( |
|
|
|
description=_DESCRIPTION, |
|
|
|
|
|
features=features, |
|
|
|
|
|
|
|
|
|
homepage=_HOMEPAGE, |
|
|
|
license=_LICENSE, |
|
) |
|
def _split_generators(self, dl_manager): |
|
urls = _DATA_URL |
|
data_dir = dl_manager.download_and_extract(urls) |
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
|
|
gen_kwargs={ |
|
"filepath": data_dir, |
|
"split": "train", |
|
}, |
|
) |
|
] |
|
|
|
def _generate_examples(self, filepath, split): |
|
|
|
|
|
|
|
obs = np.load(f'{filepath}/observations.npy') |
|
act = np.load(f'{filepath}/actions.npy') |
|
rew = np.load(f'{filepath}/rewards.npy') |
|
dones = np.load(f'{filepath}/dones.npy') |
|
for idx, value in enumerate(obs): |
|
yield idx, { |
|
"observations": obs[i], |
|
"actions": act[i], |
|
"rewards": rew[i], |
|
"dones": done[i], |
|
} |