fix(dataset): cleanup_interrupted_episode wipes image temp dirs (#3405)

This commit is contained in:
whats2000
2026-04-19 18:04:24 +08:00
committed by GitHub
parent a8b72d9615
commit 52f508c51c
2 changed files with 30 additions and 1 deletions
+1 -1
View File
@@ -597,7 +597,7 @@ class DatasetWriter:
def cleanup_interrupted_episode(self, episode_index: int) -> None: def cleanup_interrupted_episode(self, episode_index: int) -> None:
"""Remove temporary image directories for an interrupted episode.""" """Remove temporary image directories for an interrupted episode."""
for key in self._meta.video_keys: for key in self._meta.camera_keys:
img_dir = self._get_image_file_path( img_dir = self._get_image_file_path(
episode_index=episode_index, image_key=key, frame_index=0 episode_index=episode_index, image_key=key, frame_index=0
).parent ).parent
+29
View File
@@ -454,6 +454,35 @@ def test_tmp_video_deletion(tmp_path, empty_lerobot_dataset_factory):
) )
def test_cleanup_interrupted_episode_removes_image_temp_dirs(tmp_path, empty_lerobot_dataset_factory):
"""Verify interrupted episode cleanup removes temporary image directories for both image and video features."""
features = {
"image": {"dtype": "image", "shape": DUMMY_CHW, "names": ["channels", "height", "width"]},
"video": {"dtype": "video", "shape": DUMMY_HWC, "names": ["height", "width", "channels"]},
}
ds = empty_lerobot_dataset_factory(
root=tmp_path / "interrupted", features=features, streaming_encoding=False
)
# Add one frame without saving episode simulating an interruption
ds.add_frame(
{
"image": np.random.rand(*DUMMY_CHW),
"video": np.random.rand(*DUMMY_HWC),
"task": "Dummy task",
}
)
img_dir = ds.writer._get_image_file_dir(0, "image")
vid_img_dir = ds.writer._get_image_file_dir(0, "video")
# Precondition: both temp dirs exist after add_frame.
assert img_dir.exists()
assert vid_img_dir.exists()
ds.writer.cleanup_interrupted_episode(episode_index=0)
assert not img_dir.exists(), "image temp dir leaked after cleanup_interrupted_episode"
assert not vid_img_dir.exists(), "video temp dir leaked after cleanup_interrupted_episode"
def test_tmp_mixed_deletion(tmp_path, empty_lerobot_dataset_factory): def test_tmp_mixed_deletion(tmp_path, empty_lerobot_dataset_factory):
"""Verify temporary image directories are removed appropriately when both image and video features are present.""" """Verify temporary image directories are removed appropriately when both image and video features are present."""
image_key = "image" image_key = "image"