Edit on GitHub

Imitation Learning

Overview

Overview

This document provides an overview of the complete ROS 2-based imitation learning pipeline built on the OMY platform and Hugging Face Hub, including a user-friendly web GUI designed to streamline interaction and improve accessibility.

1. Data Collection

Human operators use a leader device to demonstrate motions, collecting image and joint position data. The web-based GUI plays a key role in streamlining this process by providing real-time visualization and control. Collected data can be uploaded to (or downloaded from) the Hugging Face Hub.

2. Data Visualization

Collected data is visualized to inspect motion trajectories and images, helping identify potential errors before training.

3. Model Training

The verified dataset is then used to train an action policy model. Training can be performed on local GPUs. The resulting models can be uploaded to and downloaded from the Hugging Face Hub.

4. Model Inference

Once trained, the models are deployed on the OMY to execute real-time inference for tasks such as pick and place, and obstacle avoidance.

End-to-End Imitation Learning Workflow

Dataset Schema

The dataset follows the standard 🤗 Hugging Face dataset format and contains imitation learning demonstrations collected from the AI Worker via ROS 2 teleoperation using the lerobot framework.

Field Type Description
action List[float32] Leader state vector
observation.state List[float32] Follower state vector
observation.images.cam_head Image RGB image from the head-mounted camera
timestamp float32 Time (in seconds) when the step was recorded
frame_index int64 Index of the frame within an episode
episode_index int64 Index of the episode
index int64 Global index across the dataset
task_index int64 Task identifier

Camera Connection

Hardware Setup

1. Connect the Camera

Warning: The RealSense camera mounted on the OMY uses a USB 2.0 cable and must be connected directly to the user PC. Due to variations in USB configurations across different PCs, the camera image may not appear immediately. In such cases, connecting the camera through a USB hub has been observed to resolve the issue in some environments.

Software Installation [USER PC]

1. Start the Docker Containers

Launch the containers using your preferred method or registered aliases:

open_manipulator docker start
physical_ai_server docker start

2. Run AI Server via Alias

Inside the open_manipulator container, run the AI Server using the registered alias:

ros2 launch realsense2_camera rs_camera.launch.py

Make sure the camera is properly connected and recognized inside the container.

Troubleshooting

Problem Solution
Camera not recognized Check USB cable, use lsusb, reboot
No image stream Check topics, verify node is running
Permission denied Add user to video group:
sudo usermod -aG video $USER

Dataset Preparation

Prerequisites

To begin, access the Robot PC via SSH.(Refer to the Quick Start Guide for instructions on how to connect via SSH.)

1. Launch the ROS 2 teleoperation node

Open a new terminal in Robot PC and enter the Docker container:

docker exec -it open_manipulator /bin/bash

Launch the ROS 2 teleoperation node:

ros2 launch open_manipulator_bringup ai_teleoperation.launch.py

2. Launch Physical AI Server

NOTE: The Physical AI Server is the backend that connects with the Web UI. It should be running to use the interface for data recording.

Open a new terminal in User PC and start the Docker container.:

cd physical_ai_tools/docker
.container.sh start

Enter the Docker container

cd physical_ai_tools/docker
.container.sh enter

Launch Physical AI Server with the following command:

ros2 launch physical_ai_server physical_ai_server_bringup.launch.py

Or, use shortcut command:

ai_server

3. Open the Web UI

Access the Web UI in Your Browser

Open a web browser User PC and go to http://127.0.0.1.

Alternatively, from another device connected to the same network, go to http://{IP address of the User PC}.

Once connected, you should see the web UI as shown below.

Record your dataset

1. Select the Robot Type

On the Home page, select the type of robot you are using.

2. Go to Record page

NOTE: You cannot access Record page unless a robot type has been selected on the Home page.
Please ensure that the robot type is selected before proceeding.

The Record page is divided into three main sections:

The selected robot type is also displayed in the top left corner.

3. Visualize RGB images from the cameras:

The image stream is displayed automatically upon entering the Record page.
You can remove the current stream and select a different one as needed.

To change the image topic:

  1. Click the + button in the Image Streaming Area.
  2. Choose a topic from the popup window.

4. Enter Task Information:

Fill out the task-related fields in the Task Info Panel, located on the right side of the Record page.

For detailed information on each field, expand the section below:

Item Description
Task Name It is used for the folder name of the dataset.
Task Instruction A sentence that instructs the robot what action to perform, such as “pick and place object”.
Push to hub Check this box to push the dataset to the Hugging Face Hub for sharing and training.
Requirements:
1. Hugging Face account
2. Permissions to push to the repository
Private Mode Available only when “Push to hub” is enabled. Keeps the dataset private on Hugging Face.
User ID Your Hugging Face username, used as the dataset folder name.
- Not using Hugging Face? Any name is fine.
- Using Hugging Face? Click “Load” to select a User ID.
- No registered ID? Click “Change” to enter your token manually.
- If account exists but “Push to hub” is unchecked, you can:
1. Load a registered ID
2. Enter a custom ID
FPS Frame rate for recording. Recommended value: 15
Tags Keywords for organizing and categorizing datasets on the hub. Useful for filtering/searching.
Warmup Time Time (in seconds) to warm up the robot before recording starts.
Episode Time Duration (in seconds) to record each episode.
Reset Time Duration (in seconds) for resetting between episodes.
Num Episodes Total number of episodes to record.
Optimized Save If enabled, uses RAM for faster data encoding.

Start Recording:

To begin recording, use the Control Panel located at the bottom of the Record page:

Step 1: Click the Start Button

Click the Start button to begin the recording session. The system will automatically:

Step 2: Monitor and Control During Recording

While recording is in progress, the following controls are available:

NOTE:
The current recording stage is displayed in the control panel:

  • 📍 Ready to start — Standby mode before recording begins
  • 🔥 Warm-up in progress — Robot is warming up
  • 🔴 Recording in progress — Capturing data
  • 🏠 Reset in progress — Reset time between episodes
  • 💾 Saving… — Encoding and saving the episode

TIP:

  • Before you start, keep the robot in a safe and ready position during warm-up
  • Make sure all required fields in the Task Info Panel are filled in
  • Keep the robot in a safe and ready position during warm-up
  • Monitor progress and status updates through the Web UI
  • System resources (CPU, RAM, Storage) are displayed during recording

Step 3. After recording:

NOTE: This path refers to your host system, not inside the Docker container.

~/ai_worker/docker/huggingface/lerobot

Dataset Visualization

Once data collection is complete, you can preview and inspect your recorded dataset using the following command:

cd /root/ros2_ws/src/physical_ai_tools/lerobot
python lerobot/scripts/visualize_dataset_html.py \
  --host 0.0.0.0 \
  --port 9091 \
  --repo-id ${HF_USER}/omy_test

You should see an output similar to the following:

Fetching 4 files: 100%|██████████| 4/4 [00:00<00:00, 3457.79it/s]
.gitattributes: 100%|██████████| 2.46k/2.46k [00:00<00:00, 45.9MB/s]
Fetching 126 files: 100%|██████████| 126/126 [00:00<00:00, 266.66it/s]
Resolving data files: 100%|██████████| 30/30 [00:00<00:00, 662258.53it/s]
INFO 2025-05-15 16:18:07 set_html.py:364 Output directory already exists. Loading from it: '/tmp/lerobot_visualize_dataset_uo6ddbb1'
 * Serving Flask app 'visualize_dataset_html'
 * Debug mode: off
INFO 2025-05-15 16:18:07 _internal.py:97 WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
 * Running on http://127.0.0.1:9091
INFO 2025-05-15 16:18:07 _internal.py:97 Press CTRL+C to quit

Once the server is running, access http://127.0.0.1:9091 in your browser on the User PC to preview the dataset.

Or, on another device connected to the same network as the User PC, access http://{IP address of the host machine}:9091 to preview the dataset.

You should see a web interface similar to the one below:

Model Workflow

This guide explains the process of training and deploying imitation learning models for the OMY using your prepared datasets.

Model Training

After preparing your dataset, you can proceed to train the policy model.

1. [User PC] Enter the Docker Container

Open a terminal on the Jetson device and enter the Docker container:

cd open_manipulator
./docker/container.sh enter

2. Navigate to the LeRobot Directory

cd /root/ros2_ws/src/physical_ai_tools/lerobot

3. Train the Policy

Execute the following command to start training:

python lerobot/scripts/train.py \
  --dataset.repo_id=${HF_USER}/omy_test \
  --policy.type=act \
  --output_dir=outputs/train/act_omy_test \
  --job_name=act_omy_test \
  --policy.device=cuda \
  --log_freq=100 \
  --save_freq=1000

Key Training Parameters:

Parameter Description
--dataset.repo_id The Hugging Face dataset ID you created in the data collection step
--policy.type Model architecture to use (e.g., 'act' for Action Chunking Transformer)
--output_dir Directory path to save model checkpoints and logs
--job_name Name of the training run (useful for tracking multiple experiments)
--policy.device Device to use for training ('cuda' for GPU, 'cpu' for CPU)
--log_freq How often to log training statistics (number of iterations)
--save_freq How often to save model checkpoints (number of iterations)

Expected Training Output:
During training, you will see output like this,

INFO 2025-05-28 12:12:40 ts/train.py:232 step:200 smpl:2K ep:3 epch:0.16 loss:7.490 grdn:154.502 lr:1.0e-05 updt_s:0.047 data_s:0.002
INFO 2025-05-28 12:12:48 ts/train.py:232 step:400 smpl:3K ep:7 epch:0.33 loss:3.128 grdn:85.109 lr:1.0e-05 updt_s:0.041 data_s:0.000
INFO 2025-05-28 12:12:57 ts/train.py:232 step:600 smpl:5K ep:10 epch:0.49 loss:2.615 grdn:74.954 lr:1.0e-05 updt_s:0.041 data_s:0.000
INFO 2025-05-28 12:13:05 ts/train.py:232 step:800 smpl:6K ep:13 epch:0.65 loss:2.331 grdn:68.764 lr:1.0e-05 updt_s:0.042 data_s:0.000
INFO 2025-05-28 12:13:14 ts/train.py:232 step:1K smpl:8K ep:16 epch:0.81 loss:2.075 grdn:64.323 lr:1.0e-05 updt_s:0.042 data_s:0.000
INFO 2025-05-28 12:13:22 ts/train.py:232 step:1K smpl:10K ep:20 epch:0.98 loss:1.903 grdn:61.364 lr:1.0e-05 updt_s:0.042 data_s:0.000
INFO 2025-05-28 12:13:31 ts/train.py:232 step:1K smpl:11K ep:23 epch:1.14 loss:1.716 grdn:57.887 lr:1.0e-05 updt_s:0.042 data_s:0.001
INFO 2025-05-28 12:13:40 ts/train.py:232 step:2K smpl:13K ep:26 epch:1.30 loss:1.558 grdn:54.819 lr:1.0e-05 updt_s:0.041 data_s:0.000
INFO 2025-05-28 12:13:48 ts/train.py:232 step:2K smpl:14K ep:29 epch:1.47 loss:1.454 grdn:53.859 lr:1.0e-05 updt_s:0.042 data_s:0.000
...

Training time depends on your hardware and dataset size, but typically ranges from several hours to a full day.

(Optional) Uploading Checkpoints to Hugging Face

To upload the latest trained checkpoint to the Hugging Face Hub:

huggingface-cli upload ${HF_USER}/act_omy_test \
  outputs/train/act_omy_test/checkpoints/last/pretrained_model

This makes your model accessible from anywhere and simplifies deployment.

Model Inference

Once your model is trained, you can deploy it on the OMY for inference.

1. Open a Terminal and Enter Docker Container

cd 
./docker/container.sh enter

2. Launch the ROS 2 Follower Node

ros2 launch open_manipulator_bringup omy_follower_ai.launch.py

3. Open a New Terminal and Run Docker Container

cd 
./docker/container.sh enter

4. Launch the Camera Node

ros2 launch realsense2_camera rs_camera.launch.py

5. Open a New Terminal and Run Docker Container

cd 
./docker/container.sh enter

6. Set the Robot Type to ‘omy’

ros2 service call /set_robot_type physical_ai_interfaces/srv/SetRobotType "
{
  robot_type: 'omy'
}"

7. Send Service Call for Evaluation
You can now observe the robot performing motions driven by real-time inference from a trained model!

ros2 service call /task/command physical_ai_interfaces/srv/SendCommand "
{
  command: 2,
  task_info: {
    task_name: 'pick_and_place',
    task_type: 'inference',
    user_id: '[USER_ID]',
    task_instruction: 'Pick up the object and place it in the box',
    fps: 30
  },
  model_path: '[REPO_ID]'
}"

Key Inference Parameters

Parameter Description
task_name The name used to identify the task
task_type The mode of execution
user_id The Hugging Face dataset repository ID
task_instruction The name of the task you are performing
fps Frame rate for dataset recording
model_path Where to save model checkpoints and logs

Visualizing Inference Results

After running inference, you can visualize the results using the same visualization tool used for datasets.

First, navigate to the LeRobot Directory:

cd /root/ros2_ws/src/physical_ai_tools/lerobot

Then, launch the visualization server with the following command:

python lerobot/scripts/visualize_dataset_html.py \
  --host 0.0.0.0 \
  --port 9091 \
  --repo-id ${HF_USER}/eval_omy_test

Finally, open http://127.0.0.1:9091 in your browser to see how your model performed.

TIP: If you have a another device connected to the same network as the host machine, open http://omy-{serial number}.local:9091 in your browser to see how your model performed.

For example, http://omy-SNPR48A0000.local:9091.

Troubleshooting