mirror of
https://github.com/huggingface/lerobot.git
synced 2026-07-23 17:56:07 +00:00
feat(raw frame unit): adapting dataset reader so that raw depth frames are scaled according to the requested unit
This commit is contained in:
@@ -22,10 +22,14 @@ from pathlib import Path
|
|||||||
import datasets
|
import datasets
|
||||||
import torch
|
import torch
|
||||||
|
|
||||||
from lerobot.configs import DEFAULT_DEPTH_UNIT, DepthEncoderConfig
|
from lerobot.configs import (
|
||||||
|
DEFAULT_DEPTH_UNIT,
|
||||||
|
DEPTH_METER_UNIT,
|
||||||
|
DepthEncoderConfig,
|
||||||
|
)
|
||||||
|
|
||||||
from .dataset_metadata import LeRobotDatasetMetadata
|
from .dataset_metadata import LeRobotDatasetMetadata
|
||||||
from .depth_utils import dequantize_depth
|
from .depth_utils import MM_PER_METRE, dequantize_depth
|
||||||
from .feature_utils import (
|
from .feature_utils import (
|
||||||
check_delta_timestamps,
|
check_delta_timestamps,
|
||||||
get_delta_indices,
|
get_delta_indices,
|
||||||
@@ -102,6 +106,13 @@ class DatasetReader:
|
|||||||
for vid_key in self._meta.depth_keys
|
for vid_key in self._meta.depth_keys
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Get the input unit of each depth feature stored as raw images.
|
||||||
|
self._image_depth_units: dict[str, str | None] = {
|
||||||
|
key: (self._meta.features[key].get("info") or {}).get("depth_unit")
|
||||||
|
for key in self._meta.depth_keys
|
||||||
|
if key in self._meta.image_keys
|
||||||
|
}
|
||||||
|
|
||||||
def set_image_transforms(self, image_transforms: Callable | None) -> None:
|
def set_image_transforms(self, image_transforms: Callable | None) -> None:
|
||||||
"""Replace the transform applied to visual observations."""
|
"""Replace the transform applied to visual observations."""
|
||||||
if image_transforms is not None and not callable(image_transforms):
|
if image_transforms is not None and not callable(image_transforms):
|
||||||
@@ -329,6 +340,13 @@ class DatasetReader:
|
|||||||
continue
|
continue
|
||||||
item[cam] = self._image_transforms(item[cam])
|
item[cam] = self._image_transforms(item[cam])
|
||||||
|
|
||||||
|
# Convert depth features to the output unit.
|
||||||
|
for key, stored_unit in self._image_depth_units.items():
|
||||||
|
if key in item and stored_unit is not None and stored_unit != self._depth_output_unit:
|
||||||
|
item[key] = (
|
||||||
|
item[key] * MM_PER_METRE if stored_unit == DEPTH_METER_UNIT else item[key] / MM_PER_METRE
|
||||||
|
)
|
||||||
|
|
||||||
# Add task as a string
|
# Add task as a string
|
||||||
task_idx = item["task_index"].item()
|
task_idx = item["task_index"].item()
|
||||||
item["task"] = self._meta.tasks.iloc[task_idx].name
|
item["task"] = self._meta.tasks.iloc[task_idx].name
|
||||||
|
|||||||
Reference in New Issue
Block a user