huggingface / lerobot

🤗 LeRobot: Making AI for Robotics more accessible with end-to-end learning
Apache License 2.0
6.88k stars 629 forks source link

lerobot/common/policies/normalize.py divide by zero #211

Closed ruijie-he closed 4 months ago

ruijie-he commented 4 months ago

System Info

Normalize class could have a divide by 0 problem, e.g. when some of the states or actions have a fixed value. 

This can be fixed if https://github.com/huggingface/lerobot/blob/main/lerobot/common/policies/normalize.py#L150 is changed to 

batch[key] = (batch[key] - min) / (max - min + 1e-8)

Information

Reproduction

This occurs when I extend push T / Diffusion policy to a real robot, and start by fixing the non-XY states / actions.

Expected behavior

Should be able to compute loss even when there are states and actions that have a single fixed value in the entire dataset

alexander-soare commented 4 months ago

@ruijie-he thanks a lot for reporting. We'll add this to the TODO list, but one question: have you considered contributing a PR? ;)