File size: 2,958 Bytes
65bebb2 dff3127 65bebb2 3640108 65bebb2 d6f1194 65bebb2 8757697 6a41fc5 8757697 152fd94 f938afa 8757697 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
import pickle
import datasets
import numpy as np
# The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
# This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
_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")),
# These are the features of your dataset like images, labels ...
}
)
return datasets.DatasetInfo(
# This is the description that will appear on the datasets page.
description=_DESCRIPTION,
# This defines the different columns of the dataset and their types
# Here we define them above because they are different between the two configurations
features=features,
# If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
# specify them. They'll be used if as_supervised=True in builder.as_dataset.
# supervised_keys=("sentence", "label"),
# Homepage of the dataset for documentation
homepage=_HOMEPAGE,
# License for the dataset if available
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,
# These kwargs will be passed to _generate_examples
gen_kwargs={
"filepath": data_dir,
"split": "train",
},
)
]
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
def _generate_examples(self, filepath, split):
#trajectories = pickle.load(f)
#traj = np.load(filepath)
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[idx],
"actions": act[idx],
"rewards": rew[idx],
"dones": dones[idx],
} |