Skip to main content

A gymnasium environment for Human-in-the-Loop Reinforcement Learning

Project description

gym-hil

A collection of gymnasium environments for Human-In-the-Loop (HIL) reinforcement learning, compatible with Hugging Face's LeRobot codebase.

Overview

The gym-hil package provides environments designed for human-in-the-loop reinforcement learning. The list of environments are integrated with external devices like gamepads and keyboards, making it easy to collect demonstrations and perform interventions during learning.

Currently available environments:

  • Franka Panda Robot: A robotic manipulation environment for Franka Panda robot based on MuJoCo

What is Human-In-the-Loop (HIL) RL?

Human-in-the-Loop (HIL) Reinforcement Learning keeps a human inside the control loop while the agent is training. During every rollout, the policy proposes an action, but the human may instantly override it for as many consecutive steps as needed; the robot then executes the human's command instead of the policy's choice. This approach improves sample efficiency and promotes safer exploration, as corrective actions pull the system out of unrecoverable or dangerous states and guide it toward high-value behaviors.

Human-in-the-Loop RL Schema

Demo Video

Watch the gym-hil demo video
Click the image to watch a demo of gym-hil in action!

We use HIL-SERL from LeRobot to train this policy.
The policy was trained for 10 minutes with human in the loop.
After only 10 minutes of training, the policy successfully performs the task.

Installation

Create a virtual environment with Python 3.10 and activate it, e.g. with miniconda:

conda create -y -n gym_hil python=3.10 && conda activate gym_hil

Install gym-hil from PyPI:

pip install gym-hil

or from source:

git clone https://github.com/HuggingFace/gym-hil.git && cd gym-hil
pip install -e .

Franka Environment Quick Start

import time
import imageio
import gymnasium as gym
import numpy as np

import gym_hil

# Use the Franka environment
env = gym.make("gym_hil/PandaPickCubeBase-v0", render_mode="human", image_obs=True)
action_spec = env.action_space

obs, info = env.reset()
frames = []

for i in range(200):
    obs, rew, done, truncated, info = env.step(env.action_space.sample())
    # info contains the key "is_intervention" (boolean) indicating if a human intervention occurred
    # If info["is_intervention"] is True, then info["action_intervention"] contains the action that was executed
    images = obs["pixels"]
    frames.append(np.concatenate((images["front"], images["wrist"]), axis=0))

    if done:
        obs, info = env.reset()

env.close()
imageio.mimsave("franka_render_test.mp4", frames, fps=20)

Available Environments

Franka Panda Robot Environments

  • PandaPickCubeBase-v0: The core environment with the Franka arm and a cube to pick up.
  • PandaPickCubeGamepad-v0: Includes gamepad control for teleoperation.
  • PandaPickCubeKeyboard-v0: Includes keyboard control for teleoperation.

Teleoperation

For Franka environments, you can use the gamepad or keyboard to control the robot:

python gym_hil/examples/test_teleoperation.py

To run the teleoperation with keyboard you can use the option --use-keyboard.

Human-in-the-Loop Wrappers

The hil_wrappers.py module provides wrappers for human-in-the-loop interaction:

  • EEActionWrapper: Transforms actions to end-effector space for intuitive control
  • InputsControlWrapper: Adds gamepad or keyboard control for teleoperation
  • GripperPenaltyWrapper: Optional wrapper to add penalties for excessive gripper actions

These wrappers make it easy to build environments for human demonstrations and interactive learning.

LeRobot Compatibility

All environments in gym-hil are designed to work seamlessly with Hugging Face's LeRobot codebase for human-in-the-loop reinforcement learning. This makes it easy to:

  • Collect human demonstrations
  • Train agents with human feedback
  • Perform interactive learning with human intervention

Contribute

# install pre-commit hooks
pre-commit install

# apply style and linter checks on staged files
pre-commit

Acknowledgment

The Franka environment in gym-hil is adapted from franka-sim initially built by Kevin Zakka.

Version History

  • v0: Original version

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gym_hil-0.1.2.tar.gz (5.7 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gym_hil-0.1.2-py3-none-any.whl (5.7 MB view details)

Uploaded Python 3

File details

Details for the file gym_hil-0.1.2.tar.gz.

File metadata

  • Download URL: gym_hil-0.1.2.tar.gz
  • Upload date:
  • Size: 5.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.10.16 Darwin/24.3.0

File hashes

Hashes for gym_hil-0.1.2.tar.gz
Algorithm Hash digest
SHA256 a3692a3b75ef64bab102784cca749b613a04ef8ccdbb6eabe6ac713216fb5a2c
MD5 09b46ef7007c60e7d27649e60f921f93
BLAKE2b-256 394f924eeed4cf7bd4519a5b60b74e37b61ad5c5c97cf901c96bc164fe8f01db

See more details on using hashes here.

File details

Details for the file gym_hil-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: gym_hil-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 5.7 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.10.16 Darwin/24.3.0

File hashes

Hashes for gym_hil-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 36da97cc8f7cbd325d0d1461c63d928780a573da0678e679ed40fb3983b77b53
MD5 57cff778918d85691763f2030854a225
BLAKE2b-256 a4d0c7df4fa0c0f179a44561e10b3861186f0a8c53601b35634f9794d9753408

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page