# LeRobot离线ReplayBuffer图像未归一化致训练异常与Checkpoint保存失败

> 原文链接：https://robotics.hellobike.com/pitfalls/2026-11-19-lerobot-5411
> 频道：pitfalls | 更新日期：2026-11-19 | 标签：auto, github-issue, lerobot
> 核心摘要：ReplayBuffer加载视频帧为float32[0-255]导致训练数据尺度错误及存盘崩溃，需在转换函数中显式归一化至[0,1]。

# LeRobot离线ReplayBuffer图像未归一化致训练异常与Checkpoint保存失败

::: v-pre
> 本文由 AI 根据公开内容整理，可能有误，请以原文为准：[[Bug][RL] Offline replay buffer stores uint8 camera frames as float 0-255, corrupting offline training and checkpoint dumps](https://github.com/huggingface/lerobot/issues/5411)（GitHub huggingface/lerobot #5411）

**状态**：已解决

## 问题

LeRobot 0.7.1中`ReplayBuffer.from_lerobot_dataset()`将视频相机帧存为float32 [0,255]而非[0,1]。使用`OnlineOfflineMixer`时离线批次图像值比在线大255倍破坏训练；同时因数值超范围导致PNG写入被拒，`save_episode()`抛出`FileNotFoundError`中断学习。PR #4558仅修复写入路径，内存中离线缓冲仍为0-255。

## 环境

LeRobot 0.7.1 (commit b0057180), Ubuntu 22.04, Python 3.12.12, PyTorch 2.11.0+cu130, RTX 5090, FFmpeg 4.4.2, torchcodec 0.11.

## 解决办法

1. 在`_lerobotdataset_to_transitions`函数中将uint8 RGB相机帧转换为float32并除以255.0归一化至[0,1]区间，对`state`和`next_state`键均执行此操作。
2. 排除depth键的归一化处理，保持其原始数据类型与范围不变。
3. 更新或合入PR #5413，该修复已在`tests/utils/test_replay_buffer.py`中添加回归测试，验证`return_uint8=True`加载视频数据集并经`to_lerobot_dataset()`往返后数值正确。
4. 验证修复效果：确认buffer内图像值域变为[0,1]，图像写入错误降为0，且`to_lerobot_dataset()`能成功写入全部帧。

讨论原作者：@18853477039 等，版权归原作者所有。
:::

## 原始参考来源 (Sources)

- [GitHub huggingface/lerobot #5411：[Bug][RL] Offline replay buffer stores uint8 camera frames as float 0-255, corrupting offline training and checkpoint dumps](https://github.com/huggingface/lerobot/issues/5411)