ホーム バラエティ SO-101 Introduction (10) - HIL-SERL - A Sample-Efficient Reinforcement Learning Algorithm Combining Human Demonstrations, Online Learning, and Human Intervention

SO-101 Introduction (10) - HIL-SERL - A Sample-Efficient Reinforcement Learning Algorithm Combining Human Demonstrations, Online Learning, and Human Intervention

真鍋 千夏 真鍋 千夏 • 更新: • 公開: • 読了約 41 分
目次

An overview of "HIL-SERL" is summarized below.

Previous

nc4f938608137

1. HIL-SERL

"HIL-SERL" (Human-in-the-Loop Sample-Efficient Reinforcement Learning) is a sample-efficient reinforcement learning algorithm that combines human demonstrations, online learning, and human intervention.

First, a small number of human demonstrations are prepared and used to train a reward classifier. Then, an actor-learner architecture is adopted that allows humans to intervene during policy execution to guide exploration and correct dangerous actions. In this tutorial, a gamepad is used to intervene and control the robot during the learning process.

"HIL-SERL" combines the following three main elements:

By combining these elements, "HIL-SERL" can achieve near-perfect task success and reduce cycle times compared to imitation-only baselines.

2. Requirements

3. What tasks can be learned?

"HIL-SERL" can be used to learn various manipulation tasks.
The recommendations are as follows:

4. Installing LeRobot with HIL-SERL

The commands to install "LeRobot with HIL-SERL" are as follows:

pip install -e ".[hilserl]"

5. Real Robot Learning Workflow

5-1. Understanding the configuration

The learning process begins with the proper setup of the HILSerl environment. The configuration class to focus on here is lerobot/common/envs/configs.py, specifically HILSerlRobotEnvConfig.

class HILSerlRobotEnvConfig(EnvConfig):
    robot: RobotConfig | None = None    # メインロボットエージェント (lerobot/common/robots で定義)
    teleop: TeleoperatorConfig | None = None    # テレオペレーターエージェント (例: ゲームパッド、リーダーアーム) (lerobot/common/teleoperators で定義)
    wrapper: EnvTransformConfig | None = None    # 環境ラッパー設定。lerobot/scripts/server/gym_manipulator.py を確認
    fps: int = 10    # 操作FPS
    name: str = "real_robot"    # 環境名
    mode: str = None    # "record", "replay", または None (学習用)
    repo_id: str | None = None    # LeRobotデータセットリポジトリID
    dataset_root: str | None = None    # ローカルデータセットのルート (オプション)
    task: str = ""    # タスクID
    num_episodes: int = 10    # 録画するエピソード数
    episode: int = 0    # 再生するエピソードのインデックス
    device: str = "cuda"    # 計算デバイス
    push_to_hub: bool = True    # 録画したデータセットをHubにプッシュするか
    pretrained_policy_name_or_path: str | None = None    # ポリシーの読み込み用
    reward_classifier_pretrained_path: str | None = None    # 報酬モデル用
    number_of_steps_after_success: int = 0    # 報酬分類器の場合、成功後にさらに肯定的なサンプルを収集して分類器を学習
5-2. Identifying robot workspace boundaries

Before collecting demonstrations, you need to determine the appropriate operating range for the robot.

This simplifies the learning problem on the real robot in two ways:

Empirically, learning in joint space for reinforcement learning in manipulation is often a more difficult problem. Some tasks are nearly impossible to learn in joint space, but become learnable when the action space is transformed into end-effector coordinates.

・Using find_joint_limits.py
This script helps you find the safe operating range for the robot's end-effector. If you have a follower arm and a leader arm, you can use this script to find the boundaries for the follower arm that will be applied during learning. By bounding the action space, you reduce redundant exploration by the agent and ensure safety.

python -m lerobot.scripts.find_joint_limits \
    --robot.type=so100_follower \
    --robot.port=/dev/tty.usbmodem58760431541 \
    --robot.id=black \
    --teleop.type=so100_leader \
    --teleop.port=/dev/tty.usbmodem58760431551 \
    --teleop.id=blue

・Workflow
(1) Run the script and move the robot within the space that solves the task.

(2) The script records the minimum and maximum positions of the end-effector, as well as the joint angles, and outputs them to the console.

Max ee position [0.2417 0.2012 0.1027]
Min ee position [0.1663 -0.0823 0.0336]
Max joint positions [-20.0, -20.0, -20.0, -20.0, -20.0, -20.0]
Min joint positions [50.0, 50.0, 50.0, 50.0, 50.0, 50.0]

(3) Use these values in the configuration of the end_effector_bounds field for the TeleoperatorConfig.

・Configuration Example

"end_effector_bounds": 
    "max": [0.24, 0.20, 0.10],
    "min": [0.16, -0.08, 0.03]
5-3. Collecting Demonstrations

By defining boundaries, you can safely collect demonstrations for learning. In reinforcement learning using off-policy algorithms, you can use the collected offline dataset to improve the efficiency of the learning process.

・Setting up Recording Mode
Create a configuration file to record demos (or edit an existing configuration file such as env_config_so100.json).

・Configuration Section Example

"mode": "record",
"repo_id": "username/pick_lift_cube",
"dataset_root": null,
"task": "pick_and_lift",
"num_episodes": 15,
"episode": 0,
"push_to_hub": true
5-4. Using a Teleoperation Device

In addition to the robot, you need a teleoperation device to collect task datasets and perform interventions during online learning. We support the use of gamepads, keyboards, or the robot's leader arm.

'HIL-Serl' learns the robot's movement in end-effector space. Therefore, teleoperation controls the displacement of the end-effector in the x, y, and z directions.

To do this, you need to define a version of the robot that performs actions in end-effector space. For default parameters related to end-effector space, check the robot class 'SO100FollowerEndEffector' and its configuration 'SO100FollowerEndEffectorConfig'.

class SO100FollowerEndEffectorConfig(SO100FollowerConfig):
    """SO100FollowerEndEffector ロボットのコンフィグ"""

    # エンドエフェクタ位置のデフォルトの境界 (メートル単位)
    end_effector_bounds: dict[str, list[float]] = field( # bounds for the end-effector in x,y,z direction
        default_factory=lambda: 
            "min": [-1.0, -1.0, -1.0],  # min x, y, z
            "max": [1.0, 1.0, 1.0],  # max x, y, z
        
    )

    max_gripper_pos: float = 50 # maximum gripper position that the gripper will be open at

    end_effector_step_sizes: dict[str, float] = field( # maximum step size for the end-effector in x,y,z direction
        default_factory=lambda: 
            "x": 0.02,
            "y": 0.02,
            "z": 0.02,
        
    )

Teleoperator defines the teleoperation device. A list of available Teleoperators can be found in lerobot/common/teleoperators.

・Gamepad Settings
Gamepads are very useful for controlling the robot and the state of the episode.

To set up the gamepad, you must set control_mode to "gamepad" in the configuration file and define the teleop section.

    "teleop": 
        "type": "gamepad",
        "use_gripper": true
    ,

・SO101 Leader Arm Setup
The SO101 leader arm has reduced gearing to allow the follower arm to follow and move during exploration. Therefore, the following motion is much smoother compared to the gearless SO100.

To set up the SO101 leader arm, you must set control_mode to "leader" and define the teleop section in the configuration file.

    "teleop": 
        "type": "so101_leader",
        "port": "/dev/tty.usbmodem585A0077921", # check your port number
        "use_degrees": true
    ,

To annotate episode success/failure, press the S key for success and the Esc key for failure on the keyboard. During online learning, press the space key to take over control from the policy, and press the space key again to return control to the policy.

・Recording Demos
Start the recording process. See below for an example configuration file.

python lerobot/scripts/rl/gym_manipulator.py --config_path lerobot/configs/env_config_so100.json

The recording procedure is as follows:

5-5. Dataset Processing

Once demonstrations are collected, process them to determine the optimal camera crop. Reinforcement learning is sensitive to background clutter, so it is important to crop images to the appropriate workspace area.

Visual RL algorithms learn directly from pixel inputs, making them susceptible to irrelevant visual information. Background elements such as changing lighting, shadows, moving people, and objects outside the workspace can disrupt the learning process. Keep the following points in mind for proper ROI selection:

・Determining Crop Parameters
Use the crop_dataset_roi.py script to interactively select the region of interest in the camera images.

python lerobot/scripts/rl/crop_dataset_roi.py --repo-id username/pick_lift_cube

The endpoint output is as follows:

Selected Rectangular Regions of Interest (top, left, height, width):
observation.images.side: [180, 207, 180, 200]
observation.images.front: [180, 250, 120, 150]

・Updating Config
Add the following crop parameters to your training configuration.

"crop_params_dict": 
    "observation.images.side": [180, 207, 180, 200],
    "observation.images.front": [180, 250, 120, 150]
,
"resize_size": [128, 128]

・Recommended Image Resolution
Most vision-based policies have been validated with 128x128 (default) or 64x64 pixel square inputs. Therefore, we recommend setting the resize_size parameter to [128, 128]. If you want to save GPU memory and bandwidth, set it to [64, 64]. Other resolutions are possible but have not been thoroughly tested.

5-6. Training the Reward Classifier

The reward classifier plays a crucial role in the HIL-SERL workflow by automating reward assignment and detecting episode success. Instead of manually defining reward functions or relying on human feedback at every time step, the reward classifier learns to predict success/failure from visual observations. This allows the reinforcement learning algorithm to learn efficiently by providing consistent, automated reward signals based on the robot's camera input.

This guide explains how to train a reward classifier in LeRobot's human-in-the-loop reinforcement learning implementation. The reward classifier learns to predict reward values from a given state, which can then be used to train a policy in a reinforcement learning environment.

The reward classifier implementation in modeling_classifier.py uses a pre-trained visual model to process images. It outputs a single value for binary rewards to predict success/failure cases, or multiple values for multi-class settings.

• Collecting a dataset for the reward classifier
Before training, you need to collect a dataset containing labeled examples. The record_dataset function in gym_manipulator.py enables the process of collecting datasets that include observations, actions, and rewards.

To collect a dataset, you need to modify several parameters in the environment configuration based on HILSerlRobotEnvConfig.

python lerobot/scripts/rl/gym_manipulator.py --config_path lerobot/configs/reward_classifier_train_config.json

• Key parameters for data collection

The number_of_steps_after_success parameter is critical for collecting more positive examples. Once success is detected, the system continues recording for the specified number of steps while maintaining the reward=1 label. Otherwise, there will not be enough states labeled as 1 in the dataset to train a proper classifier.

An example of the data collection configuration section is as follows:

    "mode": "record",
    "repo_id": "hf_username/dataset_name",
    "dataset_root": "data/your_dataset",
    "num_episodes": 20,
    "push_to_hub": true,
    "fps": 10,
    "number_of_steps_after_success": 15

• Reward classifier config
The reward classifier is configured using configuration_classifier.py. The main parameters are as follows:

An example configuration for training the reward classifier is as follows:

  "policy": 
    "type": "reward_classifier",
    "model_name": "helper2424/resnet10",
    "model_type": "cnn",
    "num_cameras": 2,
    "num_classes": 2,
    "hidden_dim": 256,
    "dropout_rate": 0.1,
    "learning_rate": 1e-4,
    "device": "cuda",
    "use_amp": true,
    "input_features": 
      "observation.images.front": 
        "type": "VISUAL",
        "shape": [3, 128, 128]
      ,
      "observation.images.side": 
        "type": "VISUAL",
        "shape": [3, 128, 128]
      
    
  

• Classifier training
To train the classifier, use the train.py script with the following settings.

python lerobot/scripts/train.py --config_path path/to/reward_classifier_train_config.json

• Model deployment and testing
To use the trained reward classifier, configure HILSerlRobotEnvConfig to use the model.

env_config = HILSerlRobotEnvConfig(
    reward_classifier_pretrained_path="path_to_your_pretrained_trained_model",
    # その他の環境パラメータ
)

Alternatively, set the arguments in the JSON configuration file.

    "reward_classifier_pretrained_path": "path_to_your_pretrained_model"

Run gym_manipulator.py to test the model.

python lerobot/scripts/rl/gym_manipulator.py --config_path path/to/env_config.json

The reward classifier automatically provides rewards based on visual input from the robot's camera.

• Example workflow for training a reward classifier

(1) Creating configuration files
Create the necessary JSON configuration files for the reward classifier and the environment. You can check an example here.

(2) Dataset Collection

python lerobot/scripts/rl/gym_manipulator.py --config_path lerobot/configs/env_config.json

(3) Classifier Training

python lerobot/scripts/train.py --config_path lerobot/configs/reward_classifier_train_config.json

(4) Classifier Testing

python lerobot/scripts/rl/gym_manipulator.py --config_path lerobot/configs/env_config.json
5-7. Training with Actor Learner

The LeRobot system employs a distributed actor-learner architecture for training. This architecture decouples robot interaction from the learning process, allowing them to run in parallel without interfering with each other. The actor server processes robot observations and actions, sending interaction data to the learner server. The learner server performs gradient descent and periodically updates the actor's policy weights. Two processes must be started: the learner and the actor.

・Config
Create a training configuration file (see sample here). The training configuration is based on the main TrainRLServerPipelineConfig class located in lerobot/configs/train.py.

・Starting the Learner
First, start the learner server process.

python lerobot/scripts/rl/learner.py --config_path lerobot/configs/train_config_hilserl_so100.json

・Starting the Actor
In a separate terminal, start the actor process with the same configuration.

python lerobot/scripts/rl/actor.py --config_path lerobot/configs/train_config_hilserl_so100.json

・Learning Flow
Learning proceeds automatically.

・Human in the Loop
The key to efficient learning is providing corrective feedback through human intervention, assisting in policy learning and exploration by completing the task.
To perform human intervention, press the top-right trigger button on the gamepad (or the space key on the keyboard). This pauses the policy's actions, allowing the human to take over control.
A successful experiment is one where, even if human intervention is required at the start, the number of interventions decreases as the policy improves. The intervention rate can be monitored on the wandb dashboard.

・Monitoring and Debugging
If wandb.enable is set to true, you can monitor training progress in real-time from the Weights & Biases dashboard.

5-8. Human Intervention Guide

The learning process is highly sensitive to intervention strategies. It takes a few runs to understand effective intervention methods. Here are some tips and tricks.

The ideal behavior is for the intervention rate to gradually decrease during training, as shown in the figure below.

5-9. Key Hyperparameters to Tune

Some configuration values have a disproportionate impact on learning stability and speed.

Next time



同じカテゴリの記事

真鍋 千夏
デジタルマーケター 真鍋 千夏
プロフィールを見る →

美容と暮らしの話題を担当。メーカーの公式発表、商品成分の公表資料、専門家の監修記事をもとに事実を整理します。

おすすめの関連記事