File size: 1,872 Bytes
0a3f650
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Future-timestep keypose supervision from the existing annotated trajectories.

Query i receives the primitive target attached to demonstration time t + i,
rather than another copy of time t's primitive target. Observations and optional
phase supervision still describe only time t. Wrap KeyposeDataset before action
normalization so its original per-timestep population continues to define stats.
"""

import torch
from pydantic import BaseModel, ConfigDict
from torch.utils.data import Dataset

from lim.keypose_policy import KeyposeDataset


class KeyposeSequenceDatasetConfig(BaseModel, frozen=True):
    model_config = ConfigDict(
        arbitrary_types_allowed=True, extra="forbid", use_attribute_docstrings=True
    )
    dataset: KeyposeDataset
    """Unnormalized keypose dataset owning observations, slices, and full targets."""


class KeyposeSequenceDataset(Dataset):
    def __init__(self, config: KeyposeSequenceDatasetConfig):
        self.config = config
        self.dataset = config.dataset

    def __getattr__(self, name):
        return getattr(self.dataset, name)

    def __len__(self):
        return len(self.dataset)

    def __getitem__(self, index):
        sample = self.dataset[index]
        trajectory, step = self.dataset.slices[index]
        targets = self.dataset.trajectories["actions"][trajectory]
        times = torch.arange(
            step, step + self.dataset.num_queries, device=targets.device
        ).clamp_max(len(targets) - 1)
        # Padding holds the final world keypose and its gripper command. It is
        # deliberately not the zero-increment stop padding used by dense actions.
        # Use original physical timesteps, including filtered-out observations;
        # the selected slice list controls obs_t sampling, not future label time.
        return {**sample, "actions": targets.index_select(0, times)}