|
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" |
|
|
|
|
|
|
|
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 = _URLS[self.config.name] |
|
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): |
|
with open(filepath, "rb") as f: |
|
|
|
trajectories = np.load(f) |
|
|
|
for idx, traj in enumerate(trajectories): |
|
yield idx, { |
|
"observations": traj["observations"], |
|
"actions": traj["actions"], |
|
"rewards": traj["rewards"], |
|
"dones": traj["dones"], |
|
} |