Skip to content

Commit 4041f57

Browse files
feat(visualization): replace cv2 GUI with Rerun (and solves ffmpeg versioning issues) (#903)
1 parent 2c86fea commit 4041f57

15 files changed

+175
-65
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,14 @@ conda create -y -n lerobot python=3.10
9898
conda activate lerobot
9999
```
100100

101-
When using `miniconda`, if you don't have `ffmpeg` in your environment:
101+
When using `miniconda`, install `ffmpeg` in your environment:
102102
```bash
103-
conda install ffmpeg
103+
conda install ffmpeg -c conda-forge
104104
```
105105

106106
Install 🤗 LeRobot:
107107
```bash
108-
pip install --no-binary=av -e .
108+
pip install -e .
109109
```
110110

111111
> **NOTE:** If you encounter build errors, you may need to install additional dependencies (`cmake`, `build-essential`, and `ffmpeg libs`). On Linux, run:
@@ -118,7 +118,7 @@ For simulations, 🤗 LeRobot comes with gymnasium environments that can be inst
118118

119119
For instance, to install 🤗 LeRobot with aloha and pusht, use:
120120
```bash
121-
pip install --no-binary=av -e ".[aloha, pusht]"
121+
pip install -e ".[aloha, pusht]"
122122
```
123123

124124
To use [Weights and Biases](https://docs.wandb.ai/quickstart) for experiment tracking, log in with

benchmarks/video/capture_camera_feed.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,21 @@
1717

1818
import argparse
1919
import datetime as dt
20+
import os
21+
import time
2022
from pathlib import Path
2123

2224
import cv2
25+
import rerun as rr
2326

27+
# see https://rerun.io/docs/howto/visualization/limit-ram
28+
RERUN_MEMORY_LIMIT = os.getenv("LEROBOT_RERUN_MEMORY_LIMIT", "5%")
29+
30+
31+
def display_and_save_video_stream(output_dir: Path, fps: int, width: int, height: int, duration: int):
32+
rr.init("lerobot_capture_camera_feed")
33+
rr.spawn(memory_limit=RERUN_MEMORY_LIMIT)
2434

25-
def display_and_save_video_stream(output_dir: Path, fps: int, width: int, height: int):
2635
now = dt.datetime.now()
2736
capture_dir = output_dir / f"{now:%Y-%m-%d}" / f"{now:%H-%M-%S}"
2837
if not capture_dir.exists():
@@ -39,24 +48,21 @@ def display_and_save_video_stream(output_dir: Path, fps: int, width: int, height
3948
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, height)
4049

4150
frame_index = 0
42-
while True:
51+
start_time = time.time()
52+
while time.time() - start_time < duration:
4353
ret, frame = cap.read()
4454

4555
if not ret:
4656
print("Error: Could not read frame.")
4757
break
48-
49-
cv2.imshow("Video Stream", frame)
58+
rr.log("video/stream", rr.Image(frame.numpy()), static=True)
5059
cv2.imwrite(str(capture_dir / f"frame_{frame_index:06d}.png"), frame)
5160
frame_index += 1
5261

53-
# Break the loop on 'q' key press
54-
if cv2.waitKey(1) & 0xFF == ord("q"):
55-
break
56-
57-
# Release the capture and destroy all windows
62+
# Release the capture
5863
cap.release()
59-
cv2.destroyAllWindows()
64+
65+
# TODO(Steven): Add a graceful shutdown via a close() method for the Viewer context, though not currently supported in the Rerun API.
6066

6167

6268
if __name__ == "__main__":
@@ -86,5 +92,11 @@ def display_and_save_video_stream(output_dir: Path, fps: int, width: int, height
8692
default=720,
8793
help="Height of the captured images.",
8894
)
95+
parser.add_argument(
96+
"--duration",
97+
type=int,
98+
default=20,
99+
help="Duration in seconds for which the video stream should be captured.",
100+
)
89101
args = parser.parse_args()
90102
display_and_save_video_stream(**vars(args))

examples/10_use_so100.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,15 @@ conda activate lerobot
5757
git clone https://github.com/huggingface/lerobot.git ~/lerobot
5858
```
5959

60-
#### 5. Install LeRobot with dependencies for the feetech motors:
60+
#### 5. Install ffmpeg in your environment:
61+
When using `miniconda`, install `ffmpeg` in your environment:
6162
```bash
62-
cd ~/lerobot && pip install --no-binary=av -e ".[feetech]"
63+
conda install ffmpeg -c conda-forge
64+
```
65+
66+
#### 6. Install LeRobot with dependencies for the feetech motors:
67+
```bash
68+
cd ~/lerobot && pip install -e ".[feetech]"
6369
```
6470

6571
Great :hugs:! You are now done installing LeRobot and we can begin assembling the SO100 arms :robot:.
@@ -491,6 +497,9 @@ python lerobot/scripts/control_robot.py \
491497

492498
#### a. Teleop with displaying cameras
493499
Follow [this guide to setup your cameras](https://github.com/huggingface/lerobot/blob/main/examples/7_get_started_with_real_robot.md#c-add-your-cameras-with-opencvcamera). Then you will be able to display the cameras on your computer while you are teleoperating by running the following code. This is useful to prepare your setup before recording your first dataset.
500+
501+
> **NOTE:** To visualize the data, enable `--control.display_data=true`. This streams the data using `rerun`.
502+
494503
```bash
495504
python lerobot/scripts/control_robot.py \
496505
--robot.type=so100 \

examples/11_use_lekiwi.md

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,15 @@ conda activate lerobot
6767
git clone https://github.com/huggingface/lerobot.git ~/lerobot
6868
```
6969

70-
#### 5. Install LeRobot with dependencies for the feetech motors:
70+
#### 5. Install ffmpeg in your environment:
71+
When using `miniconda`, install `ffmpeg` in your environment:
7172
```bash
72-
cd ~/lerobot && pip install --no-binary=av -e ".[feetech]"
73+
conda install ffmpeg -c conda-forge
74+
```
75+
76+
#### 6. Install LeRobot with dependencies for the feetech motors:
77+
```bash
78+
cd ~/lerobot && pip install -e ".[feetech]"
7379
```
7480

7581
## C. Install LeRobot on laptop
@@ -108,9 +114,15 @@ conda activate lerobot
108114
git clone https://github.com/huggingface/lerobot.git ~/lerobot
109115
```
110116

111-
#### 5. Install LeRobot with dependencies for the feetech motors:
117+
#### 5. Install ffmpeg in your environment:
118+
When using `miniconda`, install `ffmpeg` in your environment:
112119
```bash
113-
cd ~/lerobot && pip install --no-binary=av -e ".[feetech]"
120+
conda install ffmpeg -c conda-forge
121+
```
122+
123+
#### 6. Install LeRobot with dependencies for the feetech motors:
124+
```bash
125+
cd ~/lerobot && pip install -e ".[feetech]"
114126
```
115127

116128
Great :hugs:! You are now done installing LeRobot and we can begin assembling the SO100 arms and Mobile base :robot:.
@@ -412,6 +424,8 @@ python lerobot/scripts/control_robot.py \
412424
--control.fps=30
413425
```
414426

427+
> **NOTE:** To visualize the data, enable `--control.display_data=true`. This streams the data using `rerun`. For the `--control.type=remote_robot` you will also need to set `--control.viewer_ip` and `--control.viewer_port`
428+
415429
You should see on your laptop something like this: ```[INFO] Connected to remote robot at tcp://172.17.133.91:5555 and video stream at tcp://172.17.133.91:5556.``` Now you can move the leader arm and use the keyboard (w,a,s,d) to drive forward, left, backwards, right. And use (z,x) to turn left or turn right. You can use (r,f) to increase and decrease the speed of the mobile robot. There are three speed modes, see the table below:
416430
| Speed Mode | Linear Speed (m/s) | Rotation Speed (deg/s) |
417431
| ---------- | ------------------ | ---------------------- |

examples/11_use_moss.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,15 @@ conda create -y -n lerobot python=3.10 && conda activate lerobot
3131
git clone https://github.com/huggingface/lerobot.git ~/lerobot
3232
```
3333

34-
5. Install LeRobot with dependencies for the feetech motors:
34+
5. Install ffmpeg in your environment:
35+
When using `miniconda`, install `ffmpeg` in your environment:
3536
```bash
36-
cd ~/lerobot && pip install --no-binary=av -e ".[feetech]"
37+
conda install ffmpeg -c conda-forge
38+
```
39+
40+
6. Install LeRobot with dependencies for the feetech motors:
41+
```bash
42+
cd ~/lerobot && pip install -e ".[feetech]"
3743
```
3844

3945
## Configure the motors
@@ -212,6 +218,9 @@ python lerobot/scripts/control_robot.py \
212218

213219
**Teleop with displaying cameras**
214220
Follow [this guide to setup your cameras](https://github.com/huggingface/lerobot/blob/main/examples/7_get_started_with_real_robot.md#c-add-your-cameras-with-opencvcamera). Then you will be able to display the cameras on your computer while you are teleoperating by running the following code. This is useful to prepare your setup before recording your first dataset.
221+
222+
> **NOTE:** To visualize the data, enable `--control.display_data=true`. This streams the data using `rerun`.
223+
215224
```bash
216225
python lerobot/scripts/control_robot.py \
217226
--robot.type=moss \

examples/2_evaluate_pretrained_policy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
1919
It requires the installation of the 'gym_pusht' simulation environment. Install it by running:
2020
```bash
21-
pip install --no-binary=av -e ".[pusht]"`
21+
pip install -e ".[pusht]"`
2222
```
2323
"""
2424

examples/7_get_started_with_real_robot.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ First, install the additional dependencies required for robots built with dynami
3333

3434
Using `pip`:
3535
```bash
36-
pip install --no-binary=av -e ".[dynamixel]"
36+
pip install -e ".[dynamixel]"
3737
```
3838

3939
Using `poetry`:
@@ -55,6 +55,9 @@ Finally, connect both arms to your computer via USB. Note that the USB doesn't p
5555
Now you are ready to configure your motors for the first time, as detailed in the sections below. In the upcoming sections, you'll learn about our classes and functions by running some python code in an interactive session, or by copy-pasting it in a python file.
5656

5757
If you have already configured your motors the first time, you can streamline the process by directly running the teleoperate script (which is detailed further in the tutorial):
58+
59+
> **NOTE:** To visualize the data, enable `--control.display_data=true`. This streams the data using `rerun`.
60+
5861
```bash
5962
python lerobot/scripts/control_robot.py \
6063
--robot.type=koch \
@@ -828,10 +831,10 @@ It contains:
828831

829832
Troubleshooting:
830833
- On Linux, if you encounter any issue during video encoding with `ffmpeg: unknown encoder libsvtav1`, you can:
831-
- install with conda-forge by running `conda install -c conda-forge ffmpeg` (it should be compiled with `libsvtav1`),
832-
- or, install [Homebrew](https://brew.sh) and run `brew install ffmpeg` (it should be compiled with `libsvtav1`),
833-
- or, install [ffmpeg build dependencies](https://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu#GettheDependencies) and [compile ffmpeg from source with libsvtav1](https://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu#libsvtav1),
834-
- and, make sure you use the corresponding ffmpeg binary to your install with `which ffmpeg`.
834+
- install with conda-forge by running `conda install -c conda-forge ffmpeg` (it should be compiled with `libsvtav1`),
835+
> **NOTE:** This usually installs `ffmpeg 7.X` for your platform (check the version installed with `ffmpeg -encoders | grep libsvtav1`). If it isn't `ffmpeg 7.X` or lacks `libsvtav1` support, you can explicitly install `ffmpeg 7.X` using: `conda install ffmpeg=7.1.1 -c conda-forge`
836+
- or, install [ffmpeg build dependencies](https://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu#GettheDependencies) and [compile ffmpeg from source with libsvtav1](https://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu#libsvtav1),
837+
- and, make sure you use the corresponding ffmpeg binary to your install with `which ffmpeg`.
835838
- On Linux, if the left and right arrow keys and escape key don't have any effect during data recording, make sure you've set the `$DISPLAY` environment variable. See [pynput limitations](https://pynput.readthedocs.io/en/latest/limitations.html#linux).
836839

837840
At the end of data recording, your dataset will be uploaded on your Hugging Face page (e.g. https://huggingface.co/datasets/cadene/koch_test) that you can obtain by running:

examples/8_use_stretch.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,19 @@ conda create -y -n lerobot python=3.10 && conda activate lerobot
4343
git clone https://github.com/huggingface/lerobot.git ~/lerobot
4444
```
4545

46-
6. Install LeRobot with stretch dependencies:
46+
6. When using `miniconda`, install `ffmpeg` in your environment:
4747
```bash
48-
cd ~/lerobot && pip install --no-binary=av -e ".[stretch]"
48+
conda install ffmpeg -c conda-forge
49+
```
50+
51+
7. Install LeRobot with stretch dependencies:
52+
```bash
53+
cd ~/lerobot && pip install -e ".[stretch]"
4954
```
5055

5156
> **Note:** If you get this message, you can ignore it: `ERROR: pip's dependency resolver does not currently take into account all the packages that are installed.`
5257
53-
7. Run a [system check](https://docs.hello-robot.com/0.3/getting_started/stretch_hardware_overview/#system-check) to make sure your robot is ready:
58+
8. Run a [system check](https://docs.hello-robot.com/0.3/getting_started/stretch_hardware_overview/#system-check) to make sure your robot is ready:
5459
```bash
5560
stretch_system_check.py
5661
```
@@ -97,6 +102,8 @@ This is equivalent to running `stretch_robot_home.py`
97102
Before trying teleoperation, you need activate the gamepad controller by pressing the middle button. For more info, see Stretch's [doc](https://docs.hello-robot.com/0.3/getting_started/hello_robot/#gamepad-teleoperation).
98103

99104
Now try out teleoperation (see above documentation to learn about the gamepad controls):
105+
106+
> **NOTE:** To visualize the data, enable `--control.display_data=true`. This streams the data using `rerun`.
100107
```bash
101108
python lerobot/scripts/control_robot.py \
102109
--robot.type=stretch \

examples/9_use_aloha.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,14 @@ conda create -y -n lerobot python=3.10 && conda activate lerobot
3030
git clone https://github.com/huggingface/lerobot.git ~/lerobot
3131
```
3232

33-
5. Install LeRobot with dependencies for the Aloha motors (dynamixel) and cameras (intelrealsense):
33+
5. When using `miniconda`, install `ffmpeg` in your environment:
3434
```bash
35-
cd ~/lerobot && pip install --no-binary=av -e ".[dynamixel, intelrealsense]"
35+
conda install ffmpeg -c conda-forge
36+
```
37+
38+
6. Install LeRobot with dependencies for the Aloha motors (dynamixel) and cameras (intelrealsense):
39+
```bash
40+
cd ~/lerobot && pip install -e ".[dynamixel, intelrealsense]"
3641
```
3742

3843
## Teleoperate
@@ -43,6 +48,9 @@ Teleoperation consists in manually operating the leader arms to move the followe
4348
2. Our code assumes that your robot has been assembled following Trossen Robotics instructions. This allows us to skip calibration, as we use the pre-defined calibration files in `.cache/calibration/aloha_default`. If you replace a motor, make sure you follow the exact instructions from Trossen Robotics.
4449

4550
By running the following code, you can start your first **SAFE** teleoperation:
51+
52+
> **NOTE:** To visualize the data, enable `--control.display_data=true`. This streams the data using `rerun`.
53+
4654
```bash
4755
python lerobot/scripts/control_robot.py \
4856
--robot.type=aloha \

lerobot/common/policies/pi0/modeling_pi0.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
2525
Install pi0 extra dependencies:
2626
```bash
27-
pip install --no-binary=av -e ".[pi0]"
27+
pip install -e ".[pi0]"
2828
```
2929
3030
Example of finetuning the pi0 pretrained model (`pi0_base` in `openpi`):

lerobot/common/robot_devices/control_configs.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class TeleoperateControlConfig(ControlConfig):
4141
fps: int | None = None
4242
teleop_time_s: float | None = None
4343
# Display all cameras on screen
44-
display_cameras: bool = True
44+
display_data: bool = False
4545

4646

4747
@ControlConfig.register_subclass("record")
@@ -82,7 +82,7 @@ class RecordControlConfig(ControlConfig):
8282
# Not enough threads might cause low camera fps.
8383
num_image_writer_threads_per_camera: int = 4
8484
# Display all cameras on screen
85-
display_cameras: bool = True
85+
display_data: bool = False
8686
# Use vocal synthesis to read events.
8787
play_sounds: bool = True
8888
# Resume recording on an existing dataset.
@@ -116,6 +116,11 @@ class ReplayControlConfig(ControlConfig):
116116
@dataclass
117117
class RemoteRobotConfig(ControlConfig):
118118
log_interval: int = 100
119+
# Display all cameras on screen
120+
display_data: bool = False
121+
# Rerun configuration for remote robot (https://ref.rerun.io/docs/python/0.22.1/common/initialization_functions/#rerun.connect_tcp)
122+
viewer_ip: str | None = None
123+
viewer_port: str | None = None
119124

120125

121126
@dataclass

0 commit comments

Comments
 (0)