Skip to content

Commit

Permalink
Add demo collection doc
Browse files Browse the repository at this point in the history
  • Loading branch information
hang-yin committed Sep 30, 2024
1 parent 0c42217 commit e3ddecd
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions docs/tutorials/demo_collection.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,75 @@ action = teleop_sys.get_action(teleop_sys.get_obs())
```

to get the action based on the user teleoperation input, and pass the action to the `env.step` function.

## Data Collection and Playback

OmniGibson provides tools for collecting demonstration data and playing it back for further analysis, training, or evaluation. This is implemented via two environment wrapper classes: `DataCollectionWrapper` and `DataPlaybackWrapper`.

### DataCollectionWrapper

The `DataCollectionWrapper` is used to collect data during environment interactions. It wraps around an existing OmniGibson environment and records relevant information at each step.

Key features:

- Records actions, states, rewards, and termination conditions
- Optimizes the simulator for data collection
- Tracks object and system transitions within the environment

Example usage:

```python
import omnigibson as og
from omnigibson.envs import DataCollectionWrapper

# Create your OmniGibson environment
env = og.Environment(configs=your_config)

# Wrap it with DataCollectionWrapper
wrapped_env = DataCollectionWrapper(
env=env,
output_path="path/to/save/data.hdf5",
only_successes=False, # Set to True to only save successful episodes
)

# Use the wrapped environment as you would normally
obs, info = wrapped_env.reset()
for _ in range(num_steps):
action = your_policy(obs)
obs, reward, terminated, truncated, info = wrapped_env.step(action)

# Save the collected data
wrapped_env.save_data()
```

### DataPlaybackWrapper

The `DataPlaybackWrapper` is used to replay collected data and optionally record additional observations. This is particularly useful for gathering visual data or other sensor information that wasn't collected during the initial demonstration.

Key features:
- Replays episodes from collected data
- Can record additional observation modalities during playback
- Supports custom robot sensor configurations and external sensors

Example usage:

```python
from omnigibson.envs import DataPlaybackWrapper

# Create a playback environment
playback_env = DataPlaybackWrapper.create_from_hdf5(
input_path="path/to/collected/data.hdf5",
output_path="path/to/save/playback/data.hdf5",
robot_obs_modalities=["proprio", "rgb", "depth_linear"],
robot_sensor_config=your_robot_sensor_config,
external_sensors_config=your_external_sensors_config,
n_render_iterations=5,
only_successes=False,
)

# Playback the entire dataset and record observations
playback_env.playback_dataset(record=True)

# Save the recorded playback data
playback_env.save_data()
```

0 comments on commit e3ddecd

Please sign in to comment.