lerobot/lerobot/common/datasets/factory.py

56 lines
1.9 KiB
Python
Raw Normal View History

2024-05-15 18:13:09 +08:00
#!/usr/bin/env python
# Copyright 2024 The HuggingFace Inc. team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import logging
2024-03-01 21:31:54 +08:00
import torch
from omegaconf import OmegaConf
from lerobot.common.datasets.lerobot_dataset import LeRobotDataset
def make_dataset(
2024-03-22 18:26:55 +08:00
cfg,
2024-04-16 20:20:38 +08:00
split="train",
):
2024-04-30 23:08:59 +08:00
if cfg.env.name not in cfg.dataset_repo_id:
logging.warning(
2024-04-30 23:08:59 +08:00
f"There might be a mismatch between your training dataset ({cfg.dataset_repo_id=}) and your "
f"environment ({cfg.env.name=})."
)
2024-04-30 23:08:59 +08:00
delta_timestamps = cfg.training.get("delta_timestamps")
if delta_timestamps is not None:
for key in delta_timestamps:
if isinstance(delta_timestamps[key], str):
delta_timestamps[key] = eval(delta_timestamps[key])
2024-03-05 18:20:57 +08:00
# TODO(rcadene): add data augmentations
dataset = LeRobotDataset(
2024-04-30 23:08:59 +08:00
cfg.dataset_repo_id,
2024-04-16 20:20:38 +08:00
split=split,
delta_timestamps=delta_timestamps,
)
if cfg.get("override_dataset_stats"):
for key, stats_dict in cfg.override_dataset_stats.items():
for stats_type, listconfig in stats_dict.items():
# example of stats_type: min, max, mean, std
stats = OmegaConf.to_container(listconfig, resolve=True)
dataset.stats[key][stats_type] = torch.tensor(stats, dtype=torch.float32)
return dataset