Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
BSD 3-Clause License

Copyright (c) 2024, Zhengyi Luo

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5 changes: 5 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include LICENSE
include README.md
recursive-include smpl_sim *.py
recursive-include smpl_sim/utils *.py
recursive-include smpl_sim/data *.yaml *.urdf *.xml
6 changes: 6 additions & 0 deletions MUJOCO_LOG.TXT
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Sun Jan 28 12:48:00 2024
ERROR: could not initialize GLFW

Mon Feb 19 20:01:16 2024
WARNING: mju_openResource: unknown file 'tmp/smpl_humanoid.xml'

Sat Mar 2 18:16:01 2024
ERROR: could not initialize GLFW

46 changes: 35 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,58 @@
[Repo still under construction]
# Porting of UHC and PHC to MUJOCO>=3
# SMPLSim: Simulating SMPL/SMPLX Humanoids in MUJOCO and Isaac Gym

`smpl_sim` is a pip-installable library containing a modelization of the SMPL humanoid in different simulators (MUJOCO and Isaac Gym). It is a minimal library to support simple humanoid tasks, and is the basis library for doing more complicated tasks such as motion imitation.

<div float="center">
<img src="assets/smplsim_teaser.gif" />
</div>



## Core Features
This repo supports creating the xml files for SMPL/SMPLH/SMPLX compatible humanoid models in MUJOCO>=3. It also supports creating the humanoid models in Isaac Gym. It also provides a simple PPO implementation for training the humanoid models in MUJOCO.

### Commands:

```
python examples/env_humanoid_test.py headless=False
python smpl_sim/run.py env=speed exp_name=speed env.self_obs_v=2
python smpl_sim/run.py env=getup exp_name=speed env.self_obs_v=2
python smpl_sim/run.py env=reach exp_name=speed env.self_obs_v=2
python smpl_sim/run.py env=speed exp_name=speed env.self_obs_v=2 robot.create_vel_sensors=True
python smpl_sim/run.py env=getup exp_name=speed env.self_obs_v=2 robot.create_vel_sensors=True
python smpl_sim/run.py env=reach exp_name=speed env.self_obs_v=2 robot.create_vel_sensors=True
```


## Citation
If you find this work useful for your research, please cite our paper:
```
PULSE:
@inproceedings{
luo2024universal,
title={Universal Humanoid Motion Representations for Physics-Based Control},
author={Zhengyi Luo and Jinkun Cao and Josh Merel and Alexander Winkler and Jing Huang and Kris M. Kitani and Weipeng Xu},
booktitle={The Twelfth International Conference on Learning Representations},
year={2024},
url={https://openreview.net/forum?id=OrOd8PxOO2}
}

PHC:
@inproceedings{Luo2023PerpetualHC,
author={Zhengyi Luo and Jinkun Cao and Alexander W. Winkler and Kris Kitani and Weipeng Xu},
title={Perpetual Humanoid Control for Real-time Simulated Avatars},
booktitle={International Conference on Computer Vision (ICCV)},
year={2023}
}
}

UHC:
@inproceedings{Luo2021DynamicsRegulatedKP,
title={Dynamics-Regulated Kinematic Policy for Egocentric Pose Estimation},
author={Zhengyi Luo and Ryo Hachiuma and Ye Yuan and Kris Kitani},
booktitle={Advances in Neural Information Processing Systems},
year={2021}
}
```


Also consider citing these prior works that are used in this project:

```
Expand All @@ -42,9 +71,4 @@ Also consider citing these prior works that are used in this project:
year={2023}
}

@inproceedings{Luo2021DynamicsRegulatedKP,
title={Dynamics-Regulated Kinematic Policy for Egocentric Pose Estimation},
author={Zhengyi Luo and Ryo Hachiuma and Ye Yuan and Kris Kitani},
booktitle={Advances in Neural Information Processing Systems},
year={2021}
}
```
Binary file added assets/smplsim_teaser.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions examples/motion_lib_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@
def main(cfg : DictConfig) -> None:
# motions = joblib.load("sample_data/amass_isaac_standing_upright_slim.pkl")
device = torch.device("cpu")
# motion_file = "/hdd/zen/data/ActBound/AMASS/amass_copycat_take6_test.pkl"
# motion_file = "data/amass/singles/0-KIT_3_walking_slow08_poses.pkl"
motion_file = "data/amass/singles/0-SSM_synced_20160930_50032_punch_kick_sync_poses.pkl"
motion_file = "data/amass/singles/0-KIT_3_walking_slow08_poses.pkl"
# motion_file = "data/amass/singles/0-SSM_synced_20160930_50032_punch_kick_sync_poses.pkl"
motion_lib_cfg = EasyDict({
"motion_file": motion_file,
"device": device,
Expand All @@ -50,7 +49,8 @@ def main(cfg : DictConfig) -> None:
"randomrize_heading": True,
})
motion_lib = MotionLibSMPL(motion_lib_cfg)
motion_lib.load_motions(shape_params = [np.zeros(17)] )
shape_params = np.zeros(17)
motion_lib.load_motions(m_cfg = motion_lib_cfg, shape_params = [shape_params] )

env = HumanoidEnv(cfg)
env.reset()
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ dependencies = [
'gymnasium>=0.29.1',
'hydra-core>=1.3',
'tqdm',
'easydict',
"importlib-resources==3.0.0;python_version<'3.9'"
]

Expand Down
20 changes: 10 additions & 10 deletions smpl_sim/agents/agent_humanoid.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,22 +180,23 @@ def log_train(self, info):


if not self.cfg.no_log:
wandb.log(
data={
log_data = {
"avg_episode_reward": loggers.avg_episode_reward,
"eps_len": loggers.avg_episode_len,
"avg_rwd": loggers.avg_reward,
"reward_raw": loggers.info_dict,
},
step=self.epoch,
)

}

if "log_eval" in info:
wandb.log(data=info["log_eval"], step=self.epoch)
log_data.update(info["log_eval"])

wandb.log(data=log_data, step=self.epoch)


def optimize_policy(self,save_model=True):
starting_epoch = self.epoch
for _ in range(starting_epoch, self.cfg.learning.max_epoch):
info = {}
t0 = time.time()
self.pre_epoch()
batch, loggers = self.sample(self.cfg.learning.min_batch_size)
Expand All @@ -213,13 +214,12 @@ def optimize_policy(self,save_model=True):
elif save_model and (self.epoch) % self.cfg.learning.save_curr_frequency == 0:
self.save_curr()
t2 = time.time()

info = {
info.update({
"loggers": loggers,
"T_sample": t1 - t0,
"T_update": t2 - t1,
"T_total": t2 - t0,
}
})

self.log_train(info)
self.after_epoch()
Expand Down
1 change: 1 addition & 0 deletions smpl_sim/envs/humanoid_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from scipy.spatial.transform import Rotation as sRot
from enum import Enum
from collections import defaultdict
import torch

from smpl_sim.envs.base_env import BaseEnv
import smpl_sim.envs.controllers as ctrls
Expand Down
2 changes: 1 addition & 1 deletion smpl_sim/smpllib/motion_lib_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def update_soft_sampling_weight(self, failed_keys):

def update_sampling_prob(self, termination_history):
print("------------------------------------------------------ Restoring Termination History ------------------------------------------------------")
if len(termination_history) == len(self._termination_history):
if len(self._sampling_prob) == len(self._termination_history):
self._sampling_prob[:] = termination_history/termination_history.sum()
self._termination_history = termination_history
print("Successfully restored termination history")
Expand Down
2 changes: 1 addition & 1 deletion smpl_sim/smpllib/motion_lib_smpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def load_motion_with_skeleton(ids, motion_data_list, shape_params, mesh_parsers,
start = random.randint(0, seq_len - max_len)
end = start + max_len

trans = to_torch(curr_file['trans']).float().clone()[start:end]
trans = to_torch(curr_file['trans'] if "trans" in curr_file else curr_file['trans_orig']).float().clone()[start:end]

pose_aa = to_torch(curr_file['pose_aa'][start:end]).float().clone()
if pose_aa.shape[1] == 156:
Expand Down
26 changes: 13 additions & 13 deletions smpl_sim/smpllib/np_smpl_humanoid_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
import sys
import pdb
import os.path as osp
from copycat.utils.torch_ext import dict_to_torch
from smpl_sim.utils.torch_ext import dict_to_torch

sys.path.append(os.getcwd())

from copycat.utils.torch_utils import *
from copycat.utils.transform_utils import *
from smpl_sim.utils.torch_utils import *
from smpl_sim.utils.np_transform_utils import *
from scipy.spatial.transform import Rotation as sRot
import joblib
from mujoco_py import load_model_from_path
from copycat.smpllib.smpl_mujoco import SMPLConverter, smpl_to_qpose, smpl_to_qpose_torch, SMPL_BONE_ORDER_NAMES
from copycat.smpllib.smpl_parser import SMPL_EE_NAMES
from copycat.utils.tools import get_expert, get_expert_master
from smpl_sim.smpllib.smpl_joint_names import SMPLConverter, smpl_to_qpose, smpl_to_qpose_torch, SMPL_BONE_ORDER_NAMES
from smpl_sim.smpllib.smpl_parser import SMPL_EE_NAMES
from smpl_sim.utils.tools import get_expert, get_expert_master
import pytorch3d.transforms as tR
from copycat.smpllib.smpl_parser import (
from smpl_sim.smpllib.smpl_parser import (
SMPL_Parser,
SMPLH_Parser,
SMPLX_Parser,
Expand Down Expand Up @@ -406,12 +406,12 @@ def forward_kinematics_batch(self, rotations, root_rotations,

if __name__ == "__main__":
import mujoco_py
from copycat.smpllib.smpl_robot import Robot
from copycat.smpllib.torch_smpl_humanoid import Humanoid
from copycat.utils.config_utils.copycat_config import Config
from copycat.data_loaders.dataset_amass_single import DatasetAMASSSingle
from copycat.utils.torch_ext import dict_to_torch
from copycat.smpllib.smpl_mujoco import smpl_to_qpose_torch, smplh_to_smpl
from smpl_sim.smpllib.smpl_robot import Robot
from smpl_sim.smpllib.torch_smpl_humanoid import Humanoid
from smpl_sim.utils.config_utils.copycat_config import Config
from smpl_sim.data_loaders.dataset_amass_single import DatasetAMASSSingle
from smpl_sim.utils.torch_ext import dict_to_torch
from smpl_sim.smpllib.smpl_mujoco import smpl_to_qpose_torch, smplh_to_smpl
torch.manual_seed(0)

cfg = Config(
Expand Down
Loading