Dataloader¶
Source path: AlphaBrain/dataloader/
Aggregates the data pipelines used by VLA training: LeRobot / PaliGemma / VLM / Cosmos / GR00T / Qwen-VL LLaVA-JSON.
Top-level factory¶
dataloader ¶
save_dataset_statistics ¶
Saves a dataset_statistics.json file.
Source code in AlphaBrain/dataloader/__init__.py
LeRobot datasets¶
lerobot_datasets ¶
make_LeRobotSingleDataset ¶
make_LeRobotSingleDataset(data_root_dir: Path | str, data_name: str, robot_type: str, delete_pause_frame: bool = False, data_cfg: dict | None = None) -> LeRobotSingleDataset
Make a LeRobotSingleDataset object.
:param data_root_dir: The root directory of the dataset. :param data_name: The name of the dataset. :param robot_type: The robot type config to use. :param crop_obs_camera: Whether to crop the observation camera images. :return: A LeRobotSingleDataset object.
Source code in AlphaBrain/dataloader/lerobot_datasets.py
get_vla_dataset ¶
get_vla_dataset(data_cfg: dict, mode: str = 'train', balance_dataset_weights: bool = False, balance_trajectory_weights: bool = False, seed: int = 42, **kwargs: dict) -> LeRobotMixtureDataset
Get a LeRobotMixtureDataset object.
Source code in AlphaBrain/dataloader/lerobot_datasets.py
PaliGemma datasets¶
paligemma_datasets ¶
PaliGemmaOFT Data Pipeline
Adapts VLAE's existing LeRobot data loading to PaliGemmaOFT format. Reuses the existing lerobot_datasets.py infrastructure, adding Pi0-specific transforms.
Pi0 expects
- images: dict of {camera_name: [B, H, W, 3] uint8 tensors}
- image_masks: dict of {camera_name: [B] bool tensors}
- state: [B, state_dim] float32
- tokenized_prompt: [B, max_token_len] int32
- tokenized_prompt_mask: [B, max_token_len] bool
- actions: [B, action_horizon, action_dim] float32
Pi0DataConfig dataclass ¶
Pi0DataConfig(image_resolution: tuple = (224, 224), max_token_len: int = 200, action_horizon: int = 50, action_dim: int = 7, camera_names: tuple = ('image_0',), include_state: bool = True, state_dim: int = 7)
Configuration for Pi0-specific data processing.
Pi0DataTransform ¶
Transform VLAE LeRobot data samples into PaliGemmaOFT format.
Input (from LeRobot dataloader): dict with keys: image (List[PIL.Image]), lang (str), action (np.ndarray), state (np.ndarray)
Output (for PaliGemmaOFT.forward()): dict with same keys, but images resized and ready for Pi0 processing
Source code in AlphaBrain/dataloader/paligemma_datasets.py
Pi0DatasetWrapper ¶
get_pi0_dataset ¶
Get dataset for PaliGemmaOFT training.
Reuses VLAE's existing LeRobot data loading, wrapping it with Pi0-specific transforms.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_cfg | dataset config (same as used by other VLAE frameworks) | required | |
mode | "train" or "eval" | 'train' |
Returns:
| Type | Description |
|---|---|
| dataset wrapped with Pi0DataTransform |
Source code in AlphaBrain/dataloader/paligemma_datasets.py
VLM datasets¶
vlm_datasets ¶
LazySupervisedDataset ¶
Bases: Dataset
Dataset for supervised fine-tuning.
Source code in AlphaBrain/dataloader/vlm_datasets.py
pre_filter_long_case ¶
filter out conversations with total words exceeding max_words
Source code in AlphaBrain/dataloader/vlm_datasets.py
DataCollatorForSupervisedDataset dataclass ¶
Bases: object
Collate examples for supervised fine-tuning.
FlattenedDataCollatorForSupervisedDataset dataclass ¶
Bases: DataCollatorForSupervisedDataset
Collate examples into packed sequence with multi-modal support.
make_supervised_data_module ¶
Make dataset and collator for supervised fine-tuning.
Source code in AlphaBrain/dataloader/vlm_datasets.py
Cosmos datasets¶
cosmos_datasets ¶
LIBERO-Cosmos-Policy dataset loader for AlphaBrain training.
Dataset format
success_only/
CosmosLIBERODataset ¶
CosmosLIBERODataset(data_dir: str, chunk_size: int = 16, final_image_size: int = 224, num_duplicates_per_image: int = 4, demonstration_sampling_prob: float = 0.5, success_rollout_sampling_prob: float = 0.5, use_image_aug: bool = True, use_stronger_image_aug: bool = True, normalize_actions: bool = True, normalize_proprio: bool = True, gamma: float = 0.99)
Bases: Dataset
Dataset for LIBERO-Cosmos-Policy format.
Loads demo data (success_only/) eagerly and rollout data (all_episodes/) lazily. Returns samples compatible with the cosmos-policy training pipeline.
Source code in AlphaBrain/dataloader/cosmos_datasets.py
cosmos_collate_fn ¶
Default collate; tensors are stacked, scalars become tensors.
GR00T LeRobot subpackage¶
gr00t_lerobot ¶
data_config ¶
RobommePandaDataConfig ¶
Data config for RoboMME benchmark with Panda robot. 8-dim action/state, image + wrist_image (stored as image bytes in parquet).
datasets ¶
In this file, we define 3 types of datasets: 1. LeRobotSingleDataset: a single dataset for a given embodiment tag 2. LeRobotMixtureDataset: a mixture of datasets for a given list of embodiment tags 3. CachedLeRobotSingleDataset: a single dataset for a given embodiment tag, with caching for the video frames
See scripts/load_dataset.py for examples on how to use these datasets.
ModalityConfig ¶
Bases: BaseModel
Configuration for a modality.
LeRobotSingleDataset ¶
LeRobotSingleDataset(dataset_path: Path | str, modality_configs: dict[str, ModalityConfig], embodiment_tag: str | EmbodimentTag, video_backend: str = 'decord', video_backend_kwargs: dict | None = None, transforms: ComposedModalityTransform | None = None, delete_pause_frame: bool = False, data_cfg=None, **kwargs)
Bases: Dataset
Base dataset class for LeRobot that supports sharding.
Initialize the dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_path | Path | str | The path to the dataset. | required |
modality_configs | dict[str, ModalityConfig] | The configuration for each modality. The keys are the modality names, and the values are the modality configurations. See | required |
video_backend | str | Backend for video reading. | 'decord' |
video_backend_kwargs | dict | Keyword arguments for the video backend when initializing the video reader. | None |
transforms | ComposedModalityTransform | The transforms to apply to the dataset. | None |
embodiment_tag | EmbodimentTag | Overload the embodiment tag for the dataset. e.g. define it as "new_embodiment" | required |
Source code in AlphaBrain/dataloader/gr00t_lerobot/datasets.py
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 | |
dataset_path property ¶
The path to the dataset that contains the METADATA_FILENAME file.
metadata property ¶
The metadata for the dataset, loaded from metadata.json in the dataset directory
trajectory_ids property ¶
The trajectory IDs in the dataset, stored as a 1D numpy array of strings.
trajectory_lengths property ¶
The trajectory lengths in the dataset, stored as a 1D numpy array of integers. The order of the lengths is the same as the order of the trajectory IDs.
all_steps property ¶
The trajectory IDs and base indices for all steps in the dataset. Example: self.trajectory_ids: [0, 1, 2] self.trajectory_lengths: [3, 2, 4] return: [ ("traj_0", 0), ("traj_0", 1), ("traj_0", 2), ("traj_1", 0), ("traj_1", 1), ("traj_2", 0), ("traj_2", 1), ("traj_2", 2), ("traj_2", 3) ]
modality_keys property ¶
The modality keys for the dataset. The keys are the modality names, and the values are the keys for each modality.
{
"video": ["video.image_side_0", "video.image_side_1"], "state": ["state.eef_position", "state.eef_rotation"], "action": ["action.eef_position", "action.eef_rotation"], "language": ["language.human.task"], "timestamp": ["timestamp"], "reward": ["reward"],
}
delta_indices property ¶
The delta indices for the dataset. The keys are the modality.key, and the values are the delta indices for each modality.key.
lerobot_modality_meta property ¶
The metadata for the LeRobot dataset.
set_transforms_metadata ¶
Set the metadata for the transforms. This is useful for transforms that need to know the metadata, such as the normalization values.
Source code in AlphaBrain/dataloader/gr00t_lerobot/datasets.py
set_epoch ¶
Set the epoch for the dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
epoch | int | The epoch to set. | required |
get_step_data ¶
Get the RAW data for a single step in a trajectory. No transforms are applied.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trajectory_id | int | The name of the trajectory. | required |
base_index | int | The base step index in the trajectory. | required |
Returns:
| Name | Type | Description |
|---|---|---|
dict | dict | The RAW data for the step. |
Example return
{ "video": { "video.image_side_0": [B, T, H, W, C], "video.image_side_1": [B, T, H, W, C], }, "state": { "state.eef_position": [B, T, state_dim], "state.eef_rotation": [B, T, state_dim], }, "action": { "action.eef_position": [B, T, action_dim], "action.eef_rotation": [B, T, action_dim], }, }
Source code in AlphaBrain/dataloader/gr00t_lerobot/datasets.py
get_trajectory_data ¶
Get the data for a trajectory.
Source code in AlphaBrain/dataloader/gr00t_lerobot/datasets.py
get_trajectory_data_lerobot_v3 ¶
Get the data for a trajectory from lerobot v3.
Source code in AlphaBrain/dataloader/gr00t_lerobot/datasets.py
get_trajectory_index ¶
Get the index of the trajectory in the dataset by the trajectory ID. This is useful when you need to get the trajectory length or sampling weight corresponding to the trajectory ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trajectory_id | str | The ID of the trajectory. | required |
Returns:
| Name | Type | Description |
|---|---|---|
int | int | The index of the trajectory in the dataset. |
Source code in AlphaBrain/dataloader/gr00t_lerobot/datasets.py
get_episode_chunk ¶
get_episode_file_index ¶
Get the file index for an episode index.
get_episode_file_from_index ¶
Get the file from index for an episode index.
retrieve_data_and_pad ¶
retrieve_data_and_pad(array: ndarray, step_indices: ndarray, max_length: int, padding_strategy: str = 'first_last') -> np.ndarray
Retrieve the data from the dataset and pad it if necessary. Args: array (np.ndarray): The array to retrieve the data from. step_indices (np.ndarray): The step indices to retrieve the data for. max_length (int): The maximum length of the data. padding_strategy (str): The padding strategy, either "first" or "last".
Source code in AlphaBrain/dataloader/gr00t_lerobot/datasets.py
get_video ¶
Get the video frames for a trajectory by a base index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset | BaseSingleDataset | The dataset to retrieve the data from. | required |
trajectory_id | str | The ID of the trajectory. | required |
key | str | The key of the video. | required |
base_index | int | The base index of the trajectory. | required |
Returns:
| Type | Description |
|---|---|
ndarray | np.ndarray: The video frames for the trajectory and frame indices. Shape: (T, H, W, C) |
Source code in AlphaBrain/dataloader/gr00t_lerobot/datasets.py
1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 | |
get_state_or_action ¶
Get the state or action data for a trajectory by a base index. If the step indices are out of range, pad with the data: if the data is stored in absolute format, pad with the first or last step data; otherwise, pad with zero.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset | BaseSingleDataset | The dataset to retrieve the data from. | required |
trajectory_id | int | The ID of the trajectory. | required |
modality | str | The modality of the data. | required |
key | str | The key of the data. | required |
base_index | int | The base index of the trajectory. | required |
Returns:
| Type | Description |
|---|---|
ndarray | np.ndarray: The data for the trajectory and step indices. |
Source code in AlphaBrain/dataloader/gr00t_lerobot/datasets.py
get_language ¶
Get the language annotation data for a trajectory by step indices.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset | BaseSingleDataset | The dataset to retrieve the data from. | required |
trajectory_id | int | The ID of the trajectory. | required |
key | str | The key of the annotation. | required |
base_index | int | The base index of the trajectory. | required |
Returns:
| Type | Description |
|---|---|
list[str] | list[str]: The annotation data for the trajectory and step indices. If no matching data is found, return empty strings. |
Source code in AlphaBrain/dataloader/gr00t_lerobot/datasets.py
get_data_by_modality ¶
Get the data corresponding to the modality for a trajectory by a base index. This method will call the corresponding helper method based on the modality. See the helper methods for more details. NOTE: For the language modality, the data is padded with empty strings if no matching data is found.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset | BaseSingleDataset | The dataset to retrieve the data from. | required |
trajectory_id | int | The ID of the trajectory. | required |
modality | str | The modality of the data. | required |
key | str | The key of the data. | required |
base_index | int | The base index of the trajectory. | required |
Source code in AlphaBrain/dataloader/gr00t_lerobot/datasets.py
CachedLeRobotSingleDataset ¶
Bases: LeRobotSingleDataset
This class caches the video frames for each trajectory and key. It is recommended to use this class if the video frames need to be accessed multiple times.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resize_img | tuple[int, int] | The size to resize the video frames to reduce memory usage. | required |
Source code in AlphaBrain/dataloader/gr00t_lerobot/datasets.py
1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 | |
get_step_data ¶
Get the RAW data for a single step. No transforms are applied.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trajectory_id | str | The ID of the trajectory. | required |
base_index | int | The base index of the step. | required |
Returns:
| Name | Type | Description |
|---|---|---|
dict | dict | The data for the step. |
Source code in AlphaBrain/dataloader/gr00t_lerobot/datasets.py
set_transforms_metadata ¶
Set the metadata for the transforms. This is useful for transforms that need to know the metadata, such as the normalization values.
Source code in AlphaBrain/dataloader/gr00t_lerobot/datasets.py
LeRobotMixtureDataset ¶
LeRobotMixtureDataset(data_mixture: Sequence[tuple[LeRobotSingleDataset, float]], mode: str, balance_dataset_weights: bool = True, balance_trajectory_weights: bool = True, seed: int = 42, metadata_config: dict = {'percentile_mixing_method': 'min_max'}, **kwargs)
Bases: Dataset
A mixture of multiple datasets. This class samples a single dataset based on the dataset weights and then calls the __getitem__ method of the sampled dataset. It is recommended to modify the single dataset class instead of this class.
Initialize the mixture dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_mixture | list[tuple[LeRobotSingleDataset, float]] | Datasets and their corresponding weights. | required |
mode | str | If "train", getitem will return different samples every epoch; if "val" or "test", getitem will return the same sample every epoch. | required |
balance_dataset_weights | bool | If True, the weight of dataset will be multiplied by the total trajectory length of each dataset. | True |
balance_trajectory_weights | bool | If True, sample trajectories within a dataset weighted by their length; otherwise, use equal weighting. | True |
seed | int | Random seed for sampling. | 42 |
Source code in AlphaBrain/dataloader/gr00t_lerobot/datasets.py
2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 | |
dataset_sampling_weights property ¶
The sampling weights for each dataset.
trajectory_sampling_weights property ¶
The sampling weights for each trajectory in each dataset.
primary_dataset_indices property ¶
The indices of the primary datasets.
set_epoch ¶
Set the epoch for the dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
epoch | int | The epoch to set. | required |
sample_step ¶
Sample a single step from the dataset.
Source code in AlphaBrain/dataloader/gr00t_lerobot/datasets.py
compute_overall_statistics staticmethod ¶
compute_overall_statistics(per_task_stats: list[dict[str, dict[str, list[float] | ndarray]]], dataset_sampling_weights: list[float] | ndarray, percentile_mixing_method: str = 'weighted_average') -> dict[str, dict[str, list[float]]]
Computes overall statistics from per-task statistics using dataset sample weights.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
per_task_stats | list[dict[str, dict[str, list[float] | ndarray]]] | List of per-task statistics. | required |
Example format of one element in the per-task statistics list | { "state.gripper": { "min": [...], "max": [...], "mean": [...], "std": [...], "q01": [...], "q99": [...], }, ... } | required | |
dataset_sampling_weights | list[float] | ndarray | List of sample weights for each task. | required |
percentile_mixing_method | str | The method to mix the percentiles, either "weighted_average" or "weighted_std". | 'weighted_average' |
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, list[float]]] | A dict of overall statistics per modality. |
Source code in AlphaBrain/dataloader/gr00t_lerobot/datasets.py
2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 | |
merge_metadata staticmethod ¶
merge_metadata(metadatas: list[DatasetMetadata], dataset_sampling_weights: list[float], percentile_mixing_method: str) -> DatasetMetadata
Merge multiple metadata into one.
Source code in AlphaBrain/dataloader/gr00t_lerobot/datasets.py
update_metadata ¶
Merge multiple metadatas into one and set the transforms with the merged metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metadata_config | dict | Configuration for the metadata. "percentile_mixing_method": The method to mix the percentiles, either "weighted_average" or "min_max". weighted_average: Use the weighted average of the percentiles using the weight used in sampling the datasets. min_max: Use the min of the 1st percentile and max of the 99th percentile. | required |
Source code in AlphaBrain/dataloader/gr00t_lerobot/datasets.py
save_dataset_statistics ¶
Save merged dataset statistics to specified path in the required format. Only includes statistics for keys that are actually used in the datasets. Gripper-related keys will be placed at the end.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
save_path | Path | str | Path to save the statistics file | required |
format | str | Save format, currently only supports "json" | 'json' |
Source code in AlphaBrain/dataloader/gr00t_lerobot/datasets.py
2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 | |
load_merged_statistics classmethod ¶
Load merged dataset statistics from file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
load_path | Path | str | Path to the statistics file | required |
Returns:
| Name | Type | Description |
|---|---|---|
dict | dict | Dictionary containing merged statistics |
Source code in AlphaBrain/dataloader/gr00t_lerobot/datasets.py
apply_cached_statistics ¶
Apply cached statistics to avoid recomputation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cached_statistics | dict | Statistics loaded from file | required |
Source code in AlphaBrain/dataloader/gr00t_lerobot/datasets.py
calculate_dataset_statistics ¶
Calculate the dataset statistics of all columns for a list of parquet files.
Source code in AlphaBrain/dataloader/gr00t_lerobot/datasets.py
calculate_delta_action_statistics ¶
calculate_delta_action_statistics(parquet_paths: list[Path], lerobot_modality_meta: LeRobotModalityMetadata, action_keys_full: list[str], state_keys_full: list[str], action_indices: list[int], state_indices: list[int], action_mode_apply_keys: list[str] | None = None, action_mode_state_map: dict[str, str] | None = None, base_stats: dict | None = None) -> dict
Calculate action statistics using delta mode.
Rule
- For t>0: a_t - a_{t-1}
- For t=0: a_0 - s_0
Mapping rule (only two cases): 1) Use explicit action_mode_state_map if provided. 2) Otherwise, replace 'action.' with 'state.' directly.
Source code in AlphaBrain/dataloader/gr00t_lerobot/datasets.py
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 | |
calculate_rel_action_statistics ¶
calculate_rel_action_statistics(parquet_paths: list[Path], lerobot_modality_meta: LeRobotModalityMetadata, action_keys_full: list[str], state_keys_full: list[str], action_indices: list[int], state_indices: list[int], action_mode_apply_keys: list[str] | None = None, action_mode_state_map: dict[str, str] | None = None, base_stats: dict | None = None) -> dict
Calculate action statistics using rel mode.
Rule
- For all t: a_t - s_0
Mapping rule (only two cases): 1) Use explicit action_mode_state_map if provided. 2) Otherwise, replace 'action.' with 'state.' directly.
Source code in AlphaBrain/dataloader/gr00t_lerobot/datasets.py
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 | |
combine_modality_stats ¶
Combine statistics from all sub-keys under a modality.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
modality_stats | dict | Statistics for a modality, containing multiple sub-keys. Each sub-key contains DatasetStatisticalValues object. | required |
Returns:
| Name | Type | Description |
|---|---|---|
dict | dict | Combined statistics |
Source code in AlphaBrain/dataloader/gr00t_lerobot/datasets.py
generate_action_mask_for_used_keys ¶
Generate mask based on action modalities, but only for used keys. Gripper-related are False, others are True.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action_modalities | dict | Configuration information for action modalities. | required |
used_action_keys_ordered | Iterable of actually used action keys in the correct order. | required |
Returns:
| Type | Description |
|---|---|
list[bool] | list[bool]: List of mask values |
Source code in AlphaBrain/dataloader/gr00t_lerobot/datasets.py
get_used_modality_keys ¶
Extract used action and state keys from modality configuration.
Source code in AlphaBrain/dataloader/gr00t_lerobot/datasets.py
embodiment_tags ¶
mixtures ¶
mixtures.py
Defines a registry of dataset mixtures and weights for the Open-X Embodiment Datasets. Each dataset is associated with a float "sampling weight"
schema ¶
RotationType ¶
Bases: Enum
Type of rotation representation
LeRobotModalityField ¶
Bases: BaseModel
Metadata for a LeRobot modality field.
LeRobotStateActionMetadata ¶
LeRobotStateMetadata ¶
LeRobotActionMetadata ¶
LeRobotModalityMetadata ¶
Bases: BaseModel
Metadata for a LeRobot modality.
get_key_meta ¶
Get the metadata for a key in the LeRobot modality metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key | str | The key to get the metadata for. | required |
Returns:
| Name | Type | Description |
|---|---|---|
LeRobotModalityField | LeRobotModalityField | The metadata for the key. |
Example
lerobot_modality_meta = LeRobotModalityMetadata.model_validate(U.load_json(modality_meta_path)) lerobot_modality_meta.get_key_meta("state.joint_shoulder_y") lerobot_modality_meta.get_key_meta("video.main_camera") lerobot_modality_meta.get_key_meta("annotation.human.action.task_description")
Source code in AlphaBrain/dataloader/gr00t_lerobot/schema.py
VideoMetadata ¶
Bases: BaseModel
Metadata of the video modality
DatasetMetadata ¶
Bases: BaseModel
Metadata of the trainable dataset
Changes
- Update to use the new RawCommitHashMetadataMetadata_V1_2
transform ¶
base ¶
ModalityTransform ¶
Bases: BaseModel, ABC
Abstract class for transforming data modalities, e.g. video frame augmentation or action normalization.
Set the dataset metadata. This is useful for transforms that need to know the dataset metadata, e.g. to normalize actions. Subclasses can override this method if they need to do something more complex.
Source code in AlphaBrain/dataloader/gr00t_lerobot/transform/base.py
abstractmethod ¶Apply the transformation to the data corresponding to keys matching the apply_to regular expression and return the processed data.
InvertibleModalityTransform ¶
Bases: ModalityTransform
abstractmethod ¶Reverse the transformation to the data corresponding to keys matching the apply_to regular expression and return the processed data.
ComposedModalityTransform ¶
concat ¶
ConcatTransform ¶
Bases: InvertibleModalityTransform
Concatenate the keys according to specified order.
Get the dimension of a state or action key from the dataset metadata.
Source code in AlphaBrain/dataloader/gr00t_lerobot/transform/concat.py
Set the metadata and compute the dimensions of the state and action keys.
Source code in AlphaBrain/dataloader/gr00t_lerobot/transform/concat.py
state_action ¶
RotationTransform ¶
Adapted from https://github.com/real-stanford/diffusion_policy/blob/548a52bbb105518058e27bf34dcf90bf6f73681a/diffusion_policy/model/common/rotation_transformer.py
Valid representations
Always use matrix as intermediate representation.
Source code in AlphaBrain/dataloader/gr00t_lerobot/transform/state_action.py
StateActionToTensor ¶
StateActionTransform ¶
Bases: InvertibleModalityTransform
Class for state or action transform.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
apply_to | list[str] | The keys in the modality to load and transform. | required |
normalization_modes | dict[str, str] | The normalization modes for each state key. If a state key in apply_to is not present in the dictionary, it will not be normalized. | required |
target_rotations | dict[str, str] | The target representations for each state key. If a state key in apply_to is not present in the dictionary, it will not be rotated. | required |
StateActionPerturbation ¶
Bases: ModalityTransform
Class for state or action perturbation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
apply_to | list[str] | The keys in the modality to load and transform. | required |
std | float | Standard deviation of the noise to be added to the state or action. | required |
StateActionDropout ¶
Bases: ModalityTransform
Class for state or action dropout.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
apply_to | list[str] | The keys in the modality to load and transform. | required |
dropout_prob | float | Probability of dropping out a state or action. | required |
StateActionSinCosTransform ¶
Bases: ModalityTransform
Class for state or action sin-cos transform.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
apply_to | list[str] | The keys in the modality to load and transform. | required |
video ¶
VideoTransform ¶
Bases: ModalityTransform
VideoCrop ¶
Bases: VideoTransform
Get the transform for the given mode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode | Literal['train', 'eval'] | The mode to get the transform for. | 'train' |
Returns:
| Name | Type | Description |
|---|---|---|
Callable | Callable | If mode is "train", return a random crop transform. If mode is "eval", return a center crop transform. |
Source code in AlphaBrain/dataloader/gr00t_lerobot/transform/video.py
VideoResize ¶
Bases: VideoTransform
Get the resize transform. Same transform for both train and eval.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode | Literal['train', 'eval'] | The mode to get the transform for. | 'train' |
Returns:
| Name | Type | Description |
|---|---|---|
Callable | Callable | The resize transform. |
Source code in AlphaBrain/dataloader/gr00t_lerobot/transform/video.py
VideoRandomRotation ¶
Bases: VideoTransform
Get the random rotation transform, only used in train mode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode | Literal['train', 'eval'] | The mode to get the transform for. | 'train' |
Returns:
| Type | Description |
|---|---|
Callable | None | Callable | None: The random rotation transform. None for eval mode. |
Source code in AlphaBrain/dataloader/gr00t_lerobot/transform/video.py
VideoHorizontalFlip ¶
Bases: VideoTransform
Get the horizontal flip transform, only used in train mode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode | Literal['train', 'eval'] | The mode to get the transform for. | 'train' |
Returns:
| Type | Description |
|---|---|
Callable | None | Callable | None: If mode is "train", return a horizontal flip transform. If mode is "eval", return None. |
Source code in AlphaBrain/dataloader/gr00t_lerobot/transform/video.py
VideoGrayscale ¶
Bases: VideoTransform
Get the grayscale transform, only used in train mode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode | Literal['train', 'eval'] | The mode to get the transform for. | 'train' |
Returns:
| Type | Description |
|---|---|
Callable | None | Callable | None: If mode is "train", return a grayscale transform. If mode is "eval", return None. |
Source code in AlphaBrain/dataloader/gr00t_lerobot/transform/video.py
VideoColorJitter ¶
Bases: VideoTransform
Get the color jitter transform, only used in train mode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode | Literal['train', 'eval'] | The mode to get the transform for. | 'train' |
Returns:
| Type | Description |
|---|---|
Callable | None | Callable | None: If mode is "train", return a color jitter transform. If mode is "eval", return None. |
Source code in AlphaBrain/dataloader/gr00t_lerobot/transform/video.py
VideoRandomGrayscale ¶
Bases: VideoTransform
Get the grayscale transform, only used in train mode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode | Literal['train', 'eval'] | The mode to get the transform for. | 'train' |
Returns:
| Type | Description |
|---|---|
Callable | None | Callable | None: If mode is "train", return a grayscale transform. If mode is "eval", return None. |
Source code in AlphaBrain/dataloader/gr00t_lerobot/transform/video.py
VideoRandomPosterize ¶
Bases: VideoTransform
Get the posterize transform, only used in train mode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode | Literal['train', 'eval'] | The mode to get the transform for. | 'train' |
Returns:
| Type | Description |
|---|---|
Callable | None | Callable | None: If mode is "train", return a posterize transform. If mode is "eval", return None. |
Source code in AlphaBrain/dataloader/gr00t_lerobot/transform/video.py
VideoToTensor ¶
Bases: VideoTransform
Get the to tensor transform. Same transform for both train and eval.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode | Literal['train', 'eval'] | The mode to get the transform for. | 'train' |
Returns:
| Name | Type | Description |
|---|---|---|
Callable | Callable | The to tensor transform. |
Source code in AlphaBrain/dataloader/gr00t_lerobot/transform/video.py
Check if the input data has the correct shape. Expected video shape: [T, H, W, C], dtype np.uint8
Source code in AlphaBrain/dataloader/gr00t_lerobot/transform/video.py
staticmethod ¶Convert numpy array to tensor efficiently.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frames | ndarray | numpy array of shape [T, H, W, C] in uint8 format | required |
Returns: tensor of shape [T, C, H, W] in range [0, 1]
Source code in AlphaBrain/dataloader/gr00t_lerobot/transform/video.py
VideoToNumpy ¶
Bases: VideoTransform
Get the to numpy transform. Same transform for both train and eval.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode | Literal['train', 'eval'] | The mode to get the transform for. | 'train' |
Returns:
| Name | Type | Description |
|---|---|---|
Callable | Callable | The to numpy transform. |
Source code in AlphaBrain/dataloader/gr00t_lerobot/transform/video.py
staticmethod ¶Convert tensor back to numpy array efficiently.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frames | Tensor | tensor of shape [T, C, H, W] in range [0, 1] | required |
Returns: numpy array of shape [T, H, W, C] in uint8 format
Source code in AlphaBrain/dataloader/gr00t_lerobot/transform/video.py
VideoToPIL ¶
Bases: VideoTransform
Get the to PIL transform. Same transform for both train and eval.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode | Literal['train', 'eval'] | The mode to get the transform for. | 'train' |
Returns:
| Name | Type | Description |
|---|---|---|
Callable | Callable | The to PIL transform. |
Source code in AlphaBrain/dataloader/gr00t_lerobot/transform/video.py
staticmethod ¶Convert tensor back to PIL Image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frames | Tensor | tensor of shape [T, C, H, W] in range [0, 1] | required |
Returns: PIL Image of shape [T, H, W, C] in uint8 format
Source code in AlphaBrain/dataloader/gr00t_lerobot/transform/video.py
video ¶
get_frames_by_timestamps ¶
get_frames_by_timestamps(video_path: str, timestamps: list[float] | ndarray, video_backend: str = 'decord', video_backend_kwargs: dict = {}) -> np.ndarray
Get frames from a video at specified timestamps. Args: video_path (str): Path to the video file. timestamps (list[int] | np.ndarray): Timestamps to retrieve frames for, in seconds. video_backend (str, optional): Video backend to use. Defaults to "decord". Returns: np.ndarray: Frames at the specified timestamps.
Source code in AlphaBrain/dataloader/gr00t_lerobot/video.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 | |
get_all_frames ¶
get_all_frames(video_path: str, video_backend: str = 'decord', video_backend_kwargs: dict = {}, resize_size: tuple[int, int] | None = None) -> np.ndarray
Get all frames from a video. Args: video_path (str): Path to the video file. video_backend (str, optional): Video backend to use. Defaults to "decord". video_backend_kwargs (dict, optional): Keyword arguments for the video backend. resize_size (tuple[int, int], optional): Resize size for the frames. Defaults to None.
Source code in AlphaBrain/dataloader/gr00t_lerobot/video.py
Qwen-VL LLaVA-JSON subpackage¶
qwenvl_llavajson ¶
rope2d ¶
get_rope_index_25 ¶
get_rope_index_25(spatial_merge_size: Optional[int] = 2, input_ids: Optional[LongTensor] = None, image_grid_thw: Optional[LongTensor] = None, video_grid_thw: Optional[LongTensor] = None, second_per_grid_ts: Optional[Tensor] = None, attention_mask: Optional[Tensor] = None) -> Tuple[torch.Tensor, torch.Tensor]
Calculate the 3D rope index based on image and video's temporal, height and width in LLM.
Explanation
Each embedding sequence contains vision embedding and text embedding or just contains text embedding.
For pure text embedding sequence, the rotary position embedding has no difference with modern LLMs. Examples: input_ids: [T T T T T], here T is for text. temporal position_ids: [0, 1, 2, 3, 4] height position_ids: [0, 1, 2, 3, 4] width position_ids: [0, 1, 2, 3, 4]
For vision and text embedding sequence, we calculate 3D rotary position embedding for vision part and 1D rotary position embedding for text part. Examples: Temporal (Time): 3 patches, representing different segments of the video in time. Height: 2 patches, dividing each frame vertically. Width: 2 patches, dividing each frame horizontally. We also have some important parameters: fps (Frames Per Second): The video's frame rate, set to 1. This means one frame is processed each second. tokens_per_second: This is a crucial parameter. It dictates how many "time-steps" or "temporal tokens" are conceptually packed into a one-second interval of the video. In this case, we have 25 tokens per second. So each second of the video will be represented with 25 separate time points. It essentially defines the temporal granularity. temporal_patch_size: The number of frames that compose one temporal patch. Here, it's 2 frames. interval: The step size for the temporal position IDs, calculated as tokens_per_second * temporal_patch_size / fps. In this case, 25 * 2 / 1 = 50. This means that each temporal patch will be have a difference of 50 in the temporal position IDs. input_ids: [V V V V V V V V V V V V T T T T T], here V is for vision. vision temporal position_ids: [0, 0, 0, 0, 50, 50, 50, 50, 100, 100, 100, 100] vision height position_ids: [0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1] vision width position_ids: [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1] text temporal position_ids: [101, 102, 103, 104, 105] text height position_ids: [101, 102, 103, 104, 105] text width position_ids: [101, 102, 103, 104, 105] Here we calculate the text start position_ids as the max vision position_ids plus 1.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_ids | `torch.LongTensor` of shape `(batch_size, sequence_length)` | Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you provide it. | None |
image_grid_thw | `torch.LongTensor` of shape `(num_images, 3)`, *optional* | The temporal, height and width of feature shape of each image in LLM. | None |
video_grid_thw | `torch.LongTensor` of shape `(num_videos, 3)`, *optional* | The temporal, height and width of feature shape of each video in LLM. | None |
second_per_grid_ts | `torch.Tensor` of shape `(num_videos)`, *optional* | The time interval (in seconds) for each grid along the temporal dimension in the 3D position IDs. | None |
attention_mask | `torch.Tensor` of shape `(batch_size, sequence_length)`, *optional* | Mask to avoid performing attention on padding token indices. Mask values selected in
| None |
Returns:
| Type | Description |
|---|---|
Tensor | position_ids ( |
Tensor | mrope_position_deltas ( |
Source code in AlphaBrain/dataloader/qwenvl_llavajson/rope2d.py
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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | |
get_rope_index_2 ¶
get_rope_index_2(spatial_merge_size: Optional[int] = 2, input_ids: Optional[LongTensor] = None, image_grid_thw: Optional[LongTensor] = None, video_grid_thw: Optional[LongTensor] = None, second_per_grid_ts: Optional[Tensor] = None, attention_mask: Optional[Tensor] = None) -> Tuple[torch.Tensor, torch.Tensor]
Calculate the 3D rope index based on image and video's temporal, height and width in LLM.
Explanation
Each embedding sequence contains vision embedding and text embedding or just contains text embedding.
For pure text embedding sequence, the rotary position embedding has no difference with mordern LLMs. Examples: input_ids: [T T T T T], here T is for text. temporal position_ids: [0, 1, 2, 3, 4] height position_ids: [0, 1, 2, 3, 4] width position_ids: [0, 1, 2, 3, 4]
For vision and text embedding sequence, we calculate 3D rotary position embedding for vision part and 1D rotary position embeddin for text part. Examples: Assume we have a video input with 3 temporal patches, 2 height patches and 2 width patches. input_ids: [V V V V V V V V V V V V T T T T T], here V is for vision. vision temporal position_ids: [0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2] vision height position_ids: [0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1] vision width position_ids: [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1] text temporal position_ids: [3, 4, 5, 6, 7] text height position_ids: [3, 4, 5, 6, 7] text width position_ids: [3, 4, 5, 6, 7] Here we calculate the text start position_ids as the max vision position_ids plus 1.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_ids | `torch.LongTensor` of shape `(batch_size, sequence_length)` | Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you provide it. | None |
image_grid_thw | `torch.LongTensor` of shape `(num_images, 3)`, *optional* | The temporal, height and width of feature shape of each image in LLM. | None |
video_grid_thw | `torch.LongTensor` of shape `(num_videos, 3)`, *optional* | The temporal, height and width of feature shape of each video in LLM. | None |
attention_mask | `torch.Tensor` of shape `(batch_size, sequence_length)`, *optional* | Mask to avoid performing attention on padding token indices. Mask values selected in
| None |
Returns:
| Type | Description |
|---|---|
Tensor | position_ids ( |
Tensor | mrope_position_deltas ( |
Source code in AlphaBrain/dataloader/qwenvl_llavajson/rope2d.py
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 | |