File size: 4,311 Bytes
52ada33 eb0ddd1 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | # OneHundredStyle-G1 visualizer
`visualize.py` replays the clips on the G1 in the MuJoCo viewer, or renders them to a video
file without a display. `style100.py` is the loader it uses; it needs only numpy and is the
place to look for the clip layout and the mirror function.
## Install
```bash
pip install -r scripts/requirements.txt # numpy, mujoco, imageio[ffmpeg]
```
Python 3.9 or newer. `imageio[ffmpeg]` is only needed for `--record`.
## Quick start
Run from the dataset folder:
```bash
python scripts/visualize.py # browse all 810 clips
python scripts/visualize.py --style Zombie # all takes of one style
python scripts/visualize.py --take FW FR # forward walks and runs of every style
python scripts/visualize.py --clip Zombie_FW Chicken_FR # only these clips
python scripts/visualize.py --clip Zombie_FW --mirror # the left-right mirror image
python scripts/visualize.py --clip Zombie_FW --speed 0.5 # half speed
```
On macOS the interactive viewer has to be started with `mjpython` instead of `python`
(a MuJoCo requirement).
The camera follows the pelvis and is placed relative to the robot's heading in the first
frame of each clip; the mouse still orbits and zooms. The top-left label shows the clip id,
the motion and the current frame. The terminal prints the description of the style.
## Keyboard
| Key | Action |
|---|---|
| `SPACE` | Pause / resume |
| `RIGHT` or `N` | Next clip |
| `LEFT` or `B` | Previous clip |
| `R` | Restart the clip |
| `UP` / `DOWN` | Faster / slower playback |
Each clip loops until you move on. Close the window to quit.
## Record a video
```bash
python scripts/visualize.py --clip Zombie_FW --seconds 6 --record zombie.mp4
python scripts/visualize.py --clip Zombie_FW Chicken_FW --start 10 --seconds 4 --record two.mp4
python scripts/visualize.py --clip Zombie_FW --seconds 3 --record small.gif --every 2 --width 480 --height 360
```
`--record` needs `--clip` or `--style` and renders the selected clips one after another with
the camera of the viewer. Clips are long (79 s on median), so `--start` and `--seconds` pick
the part to render. Every rendered frame is a frame of the dataset: `--speed` only changes
the frame rate written to the file, and `--every N` keeps every N-th frame.
On a machine without a display, select an offscreen backend first:
```bash
MUJOCO_GL=egl python scripts/visualize.py --clip Zombie_FW --seconds 6 --record out.mp4
```
## Options
| Option | Default | Meaning |
|---|---|---|
| `--clip ID [ID ...]` | all | Play only these clips |
| `--style STYLE [STYLE ...]` | all | Play only these styles |
| `--take TAKE [TAKE ...]` | all | Play only these takes (`ID FW FR BW BR SW SR TR1 TR2 TR3`) |
| `--mirror` | off | Play the left-right mirror image of every clip |
| `--speed X` | `1.0` | Playback speed factor |
| `--azimuth DEG` | `135` | Camera yaw relative to the initial heading |
| `--elevation DEG` | `-15` | Camera elevation |
| `--distance M` | `3.2` | Camera distance to the pelvis |
| `--record FILE` | off | Render to `.mp4` or `.gif` instead of opening a window |
| `--start S`, `--seconds S` | `0`, all | When recording, the part of each clip to render |
| `--every N` | `1` | When recording, keep every N-th frame |
| `--width`, `--height` | `1280`, `720` | Recording size in pixels |
| `--scene XML` | `robot/scene.xml` | Another MuJoCo model with the same 29 joint names |
| `--root DIR` | this dataset | Dataset folder |
## Use the loader in your own code
```python
import sys
sys.path.insert(0, "scripts")
from style100 import JOINT_NAMES, load_clip, load_metadata, mirror
clips = load_metadata() # list of dicts, one per clip
clip = load_clip(clips[0]["file"]) # named (T, ...) arrays
print(clip.joint_pos.shape, JOINT_NAMES[0]) # (4775, 29) left_hip_pitch_joint
```
`mirror(raw)` takes the `(T, 281)` array of a clip and returns its left-right mirror image in
the same layout; `load_clip(path, mirrored=True)` applies it on loading.
MuJoCo orders the joints differently from the dataset, so place them by name:
```python
qadr = [model.joint(name).qposadr[0] for name in JOINT_NAMES]
data.qpos[:3], data.qpos[3:7], data.qpos[qadr] = clip.root_pos[t], clip.root_quat[t], clip.joint_pos[t]
```
|