Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

musclemap-data

musclemap-data is the data-generation stage of the MuscleMap thesis pipeline:

  1. Load Motion-X++ SMPL-X motion ([T, 322])
  2. Convert to OpenSim coordinates and run static optimization
  3. Save muscle activations and aligned text metadata for model training

Project pipeline context

This repo is Project 1 of 3:

  • musclemap-data (this project): motion -> muscle activation dataset
  • musclemap-model (future): text -> muscle activations (fine-tuned MotionGPT)
  • musclemap-eval (future): benchmarking and comparisons

Project 2 is expected to train from this project's output_dataset/ artifact layout (described below).

Requirements

  • Miniforge / Anaconda / Micromamba (conda on PATH)
  • Python 3.11 from conda (environment.yml)
  • Platform support:
    • macOS arm64 / x86_64
    • Linux x86_64
    • Windows x86_64

Installation

1) Clone and enter the repository

cd /path/to/musclemap-data

2) Create the conda environment (OpenSim + all Python dependencies)

From the repo root:

conda env create -f environment.yml
conda activate musclemap-data
python -m pip install -e .

The env name is musclemap-data (see name: in environment.yml). If it already exists:

conda env update -f environment.yml --prune
conda activate musclemap-data
python -m pip install -e .

pip install -e . installs the src package in editable mode (minimal pyproject.toml + setuptools). Pure conda cannot replace this one line without vendoring the package layout.

OpenSim comes from the opensim-org channel; numerical stacks come from conda-forge; pyrender, torch, smplx, and rerun-sdk are installed via the pip: subsection (still inside the same conda env).

3) Download required model files

Place OpenSim model files under models/ (default points to models/Rajagopal2016.osim).

For optional notebook mesh preview, download official SMPL-X model files and set:

  • paths.smplx_model_folder to the parent directory containing smplx/
    • expected layout example: <folder>/smplx/SMPLX_NEUTRAL.npz

4) Download Motion-X++ subsets

python scripts/download_dataset.py --config config.yaml

Useful options:

  • --subset IDEA400 (repeatable)
  • --modality motion --modality text_seq --modality text_frame (repeatable)
  • --yes (non-interactive where applicable)

5) Run environment check and auto-detect OpenSim interpreter

python scripts/setup_check.py --config config.yaml

This script validates imports and writes:

  • paths.opensim_python_exe
  • paths.opensim_conda_env

Use --dry-run to inspect without writing.

Quick usage

Notebook workflow (exploration/tuning)

Use notebooks/01_explore_and_tune.ipynb to:

  • inspect motion/text samples
  • preview original and reconstructed motion with multiple backends:
    • Rerun (build_rerun_smplx_animation, animate_motion_interactive)
    • Dash/Plotly (show_dash_smplx_motion, show_dash_app)
  • run one-sequence OpenSim pipeline with progress bars
  • inspect solver metrics and activation plots

Use the musclemap-data conda kernel for Jupyter (same env as OpenSim and all deps). After conda activate musclemap-data and pip install -e ., register once:

conda activate musclemap-data
cd /path/to/musclemap-data
python -m pip install -e .
python -m ipykernel install --user --name musclemap-data --display-name "musclemap-data"

Select that kernel in the notebook UI. If import opensim still fails, run python scripts/setup_check.py --config config.yaml so paths.opensim_python_exe matches this interpreter, or set DRY_RUN=True in the pipeline cell to skip OpenSim.

Recommended comparison workflow in notebook:

# 1) Original source motion (raw SMPL-X)
from src.visualization import show_dash_smplx_motion, show_dash_app

show_dash_smplx_motion(
    smplx_motion=motion,  # from load_sample(sample)["motion"]
    config=cfg,
    inline=True,
)

# 2) Reconstructed motion from OpenSim coordinates + activations
mot_path = (tmp_root / sample.id / "viz_coords.mot").resolve()
show_dash_app(
    mot_path=mot_path,
    activations=acts,
    muscle_names=muscle_names,
    config=cfg,
    smplx_motion=motion,  # optional overlay of raw SMPL-X joints
    inline=True,
)

Batch processing

Run full (or limited) dataset processing:

python scripts/run_batch.py --config config.yaml

Common flags:

  • --workers N override batch.num_workers
  • --limit N process first N remaining samples
  • --dry-run skip OpenSim and generate synthetic activations
  • --reset-checkpoint clear progress checkpoint before run

Batch artifacts:

  • output_root/batch.log
  • output_root/batch_summary.json
  • output_root/failed_files.log (on failures)

Output dataset contract

Generated dataset layout:

output_dataset/
  <sequence_id>/
    activations.npy          # float32, [T, N_muscles]
    smplx_322.npy            # float32, [T, 322] passthrough
    semantic_label.txt       # sequence-level text description
    pose_descriptions/
      <frame_idx>.txt        # per-frame text
  muscle_names.json          # list[str], len == N_muscles
  metadata.json              # dict[id -> {T, fps, source, n_muscles, status}]

Important invariants:

  • activations.npy is always float32
  • output FPS comes from config (output.output_fps)
  • muscle count is inferred from names (muscle_names.json)

Configuration reference (config.yaml)

Main sections:

  • paths:
    • dataset root (motionx_root)
    • output root (output_root)
    • OpenSim model path (opensim_model)
    • OpenSim python executable (opensim_python_exe)
    • temporary dir (temp_dir)
    • optional regressor path (smplx_to_opensim_regressor)
    • optional SMPL-X mesh model folder (smplx_model_folder)
  • dataset:
    • subdirectories for motion / sequence text / frame text
    • source fps
  • download:
    • Google Drive folder id, subset/modality toggles, cache controls
  • conversion:
    • target/output FPS, filtering, velocity clamp, ROM limits
  • ik, rra, static_optimization:
    • OpenSim stage settings and solver controls
    • optional solver log/metric persistence
  • visualization:
    • Rerun settings (rerun_app_id, rerun_recording_id, rerun_spawn)
    • Dash settings (dash_port, dash_inline, dash_scene_bg, etc.)
    • stick figure camera and 3D settings (for helper transforms/bounds)
    • mesh preview parameters
  • output:
    • output fps and output file toggles
  • batch:
    • retries, worker count, checkpoint filename

Why rra.enabled: false by default

This project can optionally run OpenSim RRA (Residual Reduction Algorithm), but it is disabled by default (rra.enabled: false) because it is typically impractical for large-scale Motion-X++ processing:

  • Runtime cost: RRA adds a full forward dynamics pass (often multiple iterations), which dominates wall-clock time when processing thousands of clips.
  • Missing experimental signals: robust RRA normally relies on external loads / GRFs (force plates) and better-tuned model conditions; Motion-X++ provides kinematics only, so RRA can be fragile or require heavy assumptions.

With RRA disabled, the effective pipeline used for dataset generation is:

SMPL-X motion → coordinates .mot → IK → Static Optimization → activations.npy

Testing

Run full test suite:

conda activate musclemap-data
pytest tests/ -q

Troubleshooting

ModuleNotFoundError: opensim

  • Ensure OpenSim is installed in a conda env
  • Run python scripts/setup_check.py --config config.yaml
  • Confirm notebook/CLI is using the intended Python executable

Download failures from Drive

  • Re-run scripts/download_dataset.py
  • Use cached zips under .download_cache/
  • Follow manual fallback instructions printed by the script

Batch run interrupted

  • Re-run scripts/run_batch.py (checkpoint resumes automatically)
  • Use --reset-checkpoint only if you want to restart from scratch

Rerun opens separate window instead of notebook

  • Set cfg["visualization"]["rerun_spawn"] = False to render in-cell via rr.notebook_show().
  • Ensure the active notebook kernel has rerun-sdk installed.

Dash opens in browser instead of inline

  • Pass inline=True to show_dash_app(...) / show_dash_smplx_motion(...).
  • For robust inline support, install jupyter-dash; otherwise the code falls back to a browser tab.

Mesh preview errors

  • Mesh deps are included in environment.yml (torch, smplx); run conda env update -f environment.yml --prune
  • Set paths.smplx_model_folder correctly (parent of smplx/)

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages