-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathviz.py
66 lines (57 loc) · 1.9 KB
/
viz.py
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
"""A collection mujoco-mjx vizualization utilities."""
import pickle
import numpy as np
from pathlib import Path
from stac_mjx.stac import Stac
from stac_mjx import io
from omegaconf import DictConfig
from typing import Union, Dict
def viz_stac(
data_path: Union[Path, str],
# cfg: DictConfig,
n_frames: int,
save_path: Union[Path, str],
start_frame: int = 0,
camera: Union[int, str] = 0,
height: int = 1200,
width: int = 1920,
base_path=None,
show_marker_error=False,
):
"""Render forward kinematics from keypoint positions.
Args:
data_path (Union[Path, str]): Path to stac output pickle file
cfg (DictConfig): configs
n_frames (int): number of frames to render
save_path (Union[Path, str]): Path to save rendered video (.mp4)
start_frame (int, optional): Starting rendering frame. Defaults to 0.
camera (Union[int, str], optional): Camera name (or number), defined in MJCF. Defaults to 0.
height (int, optional): Rendering pixel height. Defaults to 1200.
width (int, optional): Rendering pixel width. Defaults to 1920.
base_path (Path, optional): Base path for path strings in configs. Defaults to Path.cwd().
Returns:
(List): List of frames
"""
cfg, d = io.load_stac_data(data_path)
qposes = d.qpos
kp_data = d.kp_data
kp_names = d.kp_names
offsets = d.offsets
if base_path is None:
base_path = Path.cwd()
xml_path = base_path / cfg.model.MJCF_PATH
# initialize stac to create mj_model with scaling and marker body sites according to config
# Set the learned offsets for body sites manually
stac = Stac(xml_path, cfg, kp_names)
return cfg, stac.render(
qposes,
kp_data,
offsets,
n_frames,
save_path,
start_frame,
camera,
height,
width,
show_marker_error,
)