|
Download scripts/README.md from catachiii/FiveHundredShots: direct link, hf CLI and curl.
- Browser
- Download file 4.24 kB
-
https://huggingface.co/datasets/catachiii/FiveHundredShots/resolve/main/scripts/README.md
- Command line
-
hf download hf://datasets/catachiii/FiveHundredShots/scripts/README.md
-
curl -L -o README.md https://huggingface.co/datasets/catachiii/FiveHundredShots/resolve/main/scripts/README.md
4.24 kB
| # FiveHundredShots visualizer | |
| `visualize.py` replays the clips on the G1 + racket model in the MuJoCo viewer, or renders them | |
| to a video file without a display. `fivehundredshots.py` is the loader it uses; it needs only | |
| numpy and is the place to look for the clip layout. | |
| ## 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 500 shots | |
| python scripts/visualize.py --stroke backhand # only backhands | |
| python scripts/visualize.py --shot shot_0458 shot_0122 # only these shots | |
| python scripts/visualize.py --shot shot_0458 --speed 0.25 # quarter speed | |
| ``` | |
| On macOS the interactive viewer has to be started with `mjpython` instead of `python` | |
| (a MuJoCo requirement). | |
| ## What you see | |
|  | |
| | Marker | Meaning | | |
| |---|---| | |
| | Yellow sphere | Centre of the racket string bed in the current frame | | |
| | Red sphere | Where that centre is at ball contact (`sweetspot_hit_world`) | | |
| | Green arrow | Direction the racket face points at contact (`hit_direction_world`) | | |
| The yellow sphere reaches the red one exactly at the contact frame. The camera follows the | |
| pelvis and is placed relative to each shot's hit direction, so every stroke is seen from the | |
| same side; the mouse still orbits and zooms. The top-left label shows the shot id, stroke, | |
| current frame and contact frame. | |
| ## Keyboard | |
| | Key | Action | | |
| |---|---| | |
| | `SPACE` | Pause / resume | | |
| | `RIGHT` or `N` | Next shot | | |
| | `LEFT` or `B` | Previous shot | | |
| | `R` | Restart the shot | | |
| | `H` | Jump to the contact frame and pause | | |
| | `V` | Show / hide the markers | | |
| | `UP` / `DOWN` | Faster / slower playback | | |
| Each shot loops until you move on. Close the window to quit. | |
| ## Record a video | |
| ```bash | |
| python scripts/visualize.py --shot shot_0458 shot_0122 --record strokes.mp4 | |
| python scripts/visualize.py --shot shot_0458 --record slow.mp4 --speed 0.25 | |
| python scripts/visualize.py --shot shot_0458 --record small.gif --every 2 --width 480 --height 360 | |
| ``` | |
| `--record` needs `--shot` and renders the listed shots one after another, with the same | |
| camera and markers as the viewer. 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 --shot shot_0458 --record out.mp4 | |
| ``` | |
| ## Options | |
| | Option | Default | Meaning | | |
| |---|---|---| | |
| | `--shot ID [ID ...]` | all | Play only these shots | | |
| | `--stroke forehand\|backhand` | both | Play only this stroke type | | |
| | `--speed X` | `1.0` | Playback speed factor | | |
| | `--azimuth DEG` | `135` | Camera yaw relative to the hit direction | | |
| | `--elevation DEG` | `-15` | Camera elevation | | |
| | `--distance M` | `3.2` | Camera distance to the pelvis | | |
| | `--no-markers` | off | Hide the spheres and the arrow | | |
| | `--record FILE` | off | Render to `.mp4` or `.gif` instead of opening a window | | |
| | `--every N` | `1` | When recording, keep every N-th frame | | |
| | `--width`, `--height` | `1280`, `720` | Recording size in pixels | | |
| | `--scene XML` | `robot/scene_tennis.xml` | Another MuJoCo model with the same 29 joint names | | |
| | `--root DIR` | this dataset | Dataset folder | | |
| With `--scene` pointing at a stock G1 model the motion still plays; the yellow marker needs | |
| the `racket_sweetspot` site and is skipped when the model has none. | |
| ## Use the loader in your own code | |
| ```python | |
| import sys | |
| sys.path.insert(0, "scripts") | |
| from fivehundredshots import JOINT_NAMES, load_clip, load_metadata | |
| shots = load_metadata() # list of dicts, one per shot | |
| clip = load_clip(shots[0]["file"]) # named (T, ...) arrays | |
| print(clip.joint_pos.shape, JOINT_NAMES[0]) # (176, 29) left_hip_pitch_joint | |
| ``` | |
| 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] | |
| ``` | |