catachiii's picture
Rename to OneHundredStyle-G1
52ada33 verified
|
Raw History Blame Contribute Delete
4.31 kB

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

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:

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

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:

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

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:

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]