Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Google deepmind Dm control Trajectory Loader

From Leeroopedia
Knowledge Sources
Domains Robotics, Motion Capture
Last Updated 2026-02-15 04:00 GMT

Overview

The TrajectoryLoader module provides infrastructure for loading, decoding, and modifying motion capture trajectory data from HDF5 files into protobuf representations consumed by the locomotion system.

Description

This module defines an abstract base class TrajectoryLoader and its concrete implementation HDF5TrajectoryLoader for reading motion capture trajectories stored in HDF5 format. The base class establishes a common interface where trajectories are identified by keys and loaded via the get_trajectory method, which supports optional proto modifiers -- callables that transform trajectory protobufs in-place after deserialization.

HDF5TrajectoryLoader reads HDF5 files using h5py (an optional dependency), reconstructing FittedTrajectory protobuf messages by filling primitive fields from HDF5 attributes and walker/prop pose data from HDF5 datasets into per-timestep WalkerPose and PropPose proto messages. The loader supports start/end time or step slicing and velocity zeroing for the final timestep.

The module also provides four proto modifier classes for data augmentation during training: PropMassLimiter (caps prop mass at a maximum), PropResizer (scales prop sizes and mass using multiplicative or additive factors), ZOffsetter (shifts the z-position of all walker and prop poses throughout a trajectory), and AppendageFixer (transforms appendage positions from global coordinates to walker-local frame using quaternion rotation).

Usage

Use HDF5TrajectoryLoader when you need to load motion capture trajectories from HDF5 files for reference pose tracking tasks. Use the proto modifier classes when you need to augment trajectory data -- for example, varying prop sizes during training to improve robustness, or adjusting vertical offsets for terrain adaptation.

Code Reference

Source Location

Signature

class TrajectoryLoader(metaclass=abc.ABCMeta):
    def __init__(self, trajectory_class=trajectory.Trajectory, proto_modifier=()):
    def keys(self):  # abstract
    def _get_proto_for_key(self, key):  # abstract
    def get_trajectory(self, key, start_time=None, end_time=None,
                       start_step=None, end_step=None,
                       zero_out_velocities=True):

class HDF5TrajectoryLoader(TrajectoryLoader):
    def __init__(self, path, trajectory_class=trajectory.Trajectory,
                 proto_modifier=()):
    def keys(self):
    def _get_proto_for_key(self, key):

class PropMassLimiter:
    def __init__(self, max_mass):
    def __call__(self, proto, random_state=None):

class PropResizer:
    def __init__(self, size_factor=None, size_delta=None, mass=None):
    def __call__(self, proto, random_state=None):

class ZOffsetter:
    def __init__(self, z_offset=0.0):
    def __call__(self, proto, random_state=None):

class AppendageFixer:
    def __call__(self, proto, random_state=None):

Import

from dm_control.locomotion.mocap.loader import TrajectoryLoader
from dm_control.locomotion.mocap.loader import HDF5TrajectoryLoader
from dm_control.locomotion.mocap.loader import PropMassLimiter
from dm_control.locomotion.mocap.loader import PropResizer
from dm_control.locomotion.mocap.loader import ZOffsetter
from dm_control.locomotion.mocap.loader import AppendageFixer

I/O Contract

Inputs (HDF5TrajectoryLoader.__init__)

Name Type Required Description
path str Yes Path to the HDF5 file containing trajectory data
trajectory_class class No Python class to wrap loaded trajectory protos (default: trajectory.Trajectory)
proto_modifier callable or iterable of callables No Callables that modify each trajectory proto in-place after deserialization

Inputs (get_trajectory)

Name Type Required Description
key str Yes Identifier for the trajectory to retrieve
start_time float No Start time for trajectory slicing
end_time float No End time for trajectory slicing
start_step int No Start step index (alternative to start_time)
end_step int No End step index (alternative to end_time)
zero_out_velocities bool No Whether to zero velocities in the last timestep (default: True)

Outputs

Name Type Description
keys() tuple of str Sorted sequence of trajectory identifiers in the HDF5 file
get_trajectory() Trajectory A Trajectory object wrapping the loaded protobuf data

Usage Examples

from dm_control.locomotion.mocap import loader

# Load trajectories from an HDF5 file
trajectory_loader = loader.HDF5TrajectoryLoader('/path/to/mocap_data.h5')

# List available trajectory keys
keys = trajectory_loader.keys()

# Load a specific trajectory with time slicing
traj = trajectory_loader.get_trajectory(
    keys[0], start_time=0.0, end_time=5.0)

# Load with proto modifiers for data augmentation
mass_limiter = loader.PropMassLimiter(max_mass=5.0)
resizer = loader.PropResizer(size_factor=1.2, mass=3.0)
z_shift = loader.ZOffsetter(z_offset=0.05)

augmented_loader = loader.HDF5TrajectoryLoader(
    '/path/to/mocap_data.h5',
    proto_modifier=(mass_limiter, resizer, z_shift))

augmented_traj = augmented_loader.get_trajectory(keys[0])

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment