-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit cc37e92
Showing
100 changed files
with
17,367 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
out | ||
datasets | ||
results |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
EGOPOSE | ||
SOFTWARE LICENSE AGREEMENT | ||
ACADEMIC OR NON-PROFIT ORGANIZATION NONCOMMERCIAL RESEARCH USE ONLY | ||
|
||
BY USING OR DOWNLOADING THE SOFTWARE, YOU ARE AGREEING TO THE TERMS OF THIS LICENSE AGREEMENT. IF YOU DO NOT AGREE WITH THESE TERMS, YOU MAY NOT USE OR DOWNLOAD THE SOFTWARE. | ||
|
||
This is a license agreement ("Agreement") between your academic institution or non profit organization or self (called "Licensee" or "You" in this Agreement) and Carnegie Mellon University (called "Licensor" in this Agreement). All rights not specifically granted to you in this Agreement are reserved for Licensor. | ||
|
||
RESERVATION OF OWNERSHIP AND GRANT OF LICENSE: | ||
Licensor retains exclusive ownership of any copy of the Software (as defined below) licensed under this Agreement and hereby grants to Licensee a personal, non-exclusive, | ||
non-transferable license to use the Software for noncommercial research purposes, without the right to sublicense, pursuant to the terms and conditions of this Agreement. As used in this Agreement, the term "Software" means (i) the actual copy of all or any portion of code for program routines made accessible to Licensee by Licensor pursuant to this Agreement, inclusive of backups, updates, and/or merged copies permitted hereunder or subsequently supplied by Licensor, including all or any file structures, programming instructions, user interfaces and screen formats and sequences as well as any and all documentation and instructions related to it, and (ii) all or any derivatives and/or modifications created or made by You to any of the items specified in (i). | ||
|
||
CONFIDENTIALITY: Licensee acknowledges that the Software is proprietary to Licensor, and as such, Licensee agrees to receive all such materials in confidence and use the Software only in accordance with the terms of this Agreement. Licensee agrees to use reasonable effort to protect the Software from unauthorized use, reproduction, distribution, or publication. | ||
|
||
COPYRIGHT: The Software is owned by Licensor and is protected by United States copyright laws and applicable international treaties and/or conventions. | ||
|
||
PERMITTED USES: The Software may be used for your own noncommercial internal research purposes. You understand and agree that Licensor is not obligated to implement any suggestions and/or feedback you might provide regarding the Software, but to the extent Licensor does so, you are not entitled to any compensation related thereto. | ||
|
||
DERIVATIVES: You may create derivatives of or make modifications to the Software, however, You agree that all and any such derivatives and modifications will be owned by Licensor and become a part of the Software licensed to You under this Agreement. You may only use such derivatives and modifications for your own noncommercial internal research purposes, and you may not otherwise use, distribute or copy such derivatives and modifications in violation of this Agreement. | ||
|
||
BACKUPS: If Licensee is an organization, it may make that number of copies of the Software necessary for internal noncommercial use at a single site within its organization provided that all information appearing in or on the original labels, including the copyright and trademark notices are copied onto the labels of the copies. | ||
|
||
USES NOT PERMITTED: You may not distribute, copy or use the Software except as explicitly permitted herein. Licensee has not been granted any trademark license as part of this Agreement and may not use the name or mark "AB3DMOT", "Carnegie Mellon", or any renditions thereof without the prior written permission of Licensor. | ||
|
||
You may not sell, rent, lease, sublicense, lend, time-share or transfer, in whole or in part, or provide third parties access to prior or present versions (or any parts thereof) of the Software. | ||
|
||
ASSIGNMENT: You may not assign this Agreement or your rights hereunder without the prior written consent of Licensor. Any attempted assignment without such consent shall be null and void. | ||
|
||
TERM: The term of the license granted by this Agreement is from Licensee's acceptance of this Agreement by clicking "I Agree" below or by using the Software until terminated as provided below. | ||
|
||
The Agreement automatically terminates without notice if you fail to comply with any provision of this Agreement. Licensee may terminate this Agreement by ceasing using the Software. Upon any termination of this Agreement, Licensee will delete any and all copies of the Software. You agree that all provisions which operate to protect the proprietary rights of Licensor shall remain in force should breach occur and that the obligation of confidentiality described in this Agreement is binding in perpetuity and, as such, survives the term of the Agreement. | ||
|
||
FEE: Provided Licensee abides completely by the terms and conditions of this Agreement, there is no fee due to Licensor for Licensee's use of the Software in accordance with this Agreement. | ||
|
||
DISCLAIMER OF WARRANTIES: THE SOFTWARE IS PROVIDED "AS-IS" WITHOUT WARRANTY OF ANY KIND INCLUDING ANY WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE OR PURPOSE OR OF NON-INFRINGEMENT. LICENSEE BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF THE SOFTWARE AND RELATED MATERIALS. | ||
|
||
SUPPORT AND MAINTENANCE: No Software support or training by the Licensor is provided as part of this Agreement. | ||
|
||
EXCLUSIVE REMEDY AND LIMITATION OF LIABILITY: To the maximum extent permitted under applicable law, Licensor shall not be liable for direct, indirect, special, incidental, or consequential damages or lost profits related to Licensee's use of and/or inability to use the Software, even if Licensor is advised of the possibility of such damage. | ||
|
||
EXPORT REGULATION: Licensee agrees to comply with any and all applicable | ||
U.S. export control laws, regulations, and/or other laws related to embargoes and sanction programs administered by the Office of Foreign Assets Control. | ||
|
||
SEVERABILITY: If any provision(s) of this Agreement shall be held to be invalid, illegal, or unenforceable by a court or other tribunal of competent jurisdiction, the validity, legality and enforceability of the remaining provisions shall not in any way be affected or impaired thereby. | ||
|
||
NO IMPLIED WAIVERS: No failure or delay by Licensor in enforcing any right or remedy under this Agreement shall be construed as a waiver of any future or other exercise of such right or remedy by Licensor. | ||
|
||
GOVERNING LAW: This Agreement shall be construed and enforced in accordance with the laws of the Commonwealth of Pennsylvania without reference to conflict of laws principles. You consent to the personal jurisdiction of the courts of this County and waive their rights to venue outside of Allegheny County, Pennsylvania. | ||
|
||
ENTIRE AGREEMENT AND AMENDMENTS: This Agreement constitutes the sole and entire agreement between Licensee and Licensor as to the matter set forth herein and supersedes any previous agreements, understandings, and arrangements between the parties relating hereto. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# EgoPose | ||
 | ||
 | ||
--- | ||
This repo contains the official implementation of our paper: | ||
|
||
Ego-Pose Estimation and Forecasting as Real-Time PD Control | ||
Ye Yuan, Kris Kitani. ICCV 2019. | ||
[[project page](https://www.ye-yuan.com/ego-pose)] [[paper](https://arxiv.org/pdf/1906.03173.pdf)] [[video](https://youtu.be/968IIDZeWE0)] | ||
|
||
# Installation | ||
### Dataset | ||
* Download the dataset from this [link](https://drive.google.com/file/d/1vzxVHAtfvfIEDreqYvHulhtNwHcomotV/view?usp=sharing) and place the unzipped dataset folder inside the repo as "EgoPose/datasets". Please see the README.txt inside the folder for details about the dataset. | ||
### Environment | ||
* **Supported OS:** MacOS, Linux | ||
* **Packages:** | ||
* Python >= 3.6 | ||
* PyTorch >= 0.4 ([https://pytorch.org/](https://pytorch.org/)) | ||
* gym ([https://github.com/openai/gym](https://github.com/openai/gym)) | ||
* mujoco-py ([https://github.com/openai/mujoco-py](https://github.com/openai/mujoco-py)) | ||
* OpenCV: ```conda install -c menpo opencv``` | ||
* Tensorflow, OpenGL, yaml: | ||
```conda install tensorflow pyopengl pyyaml``` | ||
* **Additional setup:** | ||
* For linux, set the following environment variable to greatly improve multi-threaded sampling performance: | ||
```export OMP_NUM_THREADS=1``` | ||
* **Note**: All scripts should be run from the root of this repo. | ||
# Quick Demo | ||
### Pretrained Models | ||
* Please first download our pretrained models from this [link](https://drive.google.com/file/d/1DE-uSUk4JMDtL9aQY2R5rAd3_yPRUIIH/view?usp=sharing) and place the unzipped results folder inside the repo as "EgoPose/results". | ||
|
||
### Ego-Pose Estimation | ||
* To visualize the results for MoCap data: | ||
```python ego_pose/eval_pose.py --egomimic-cfg subject_03 --statereg-cfg subject_03 --mode vis``` | ||
Here we use the config file for subject_03. Note that in the visualization, the red humanoid represents the GT. | ||
|
||
* To visualize the results for in-the-wild data: | ||
```python ego_pose/eval_pose_wild.py --egomimic-cfg cross_01 --statereg-cfg cross_01 --data wild_01 --mode vis``` | ||
Here we use the config file for cross-subject model (cross_01) and test it on in-the-wild data (wild_01). | ||
|
||
* Keyboard shortcuts for the visualizer: [keymap.md](https://github.com/Khrylx/EgoPose/blob/master/docs/keymap.md) | ||
### Ego-Pose Forecasting | ||
* To visualize the results for MoCap data: | ||
```python ego_pose/eval_forecast.py --egoforecast-cfg subject_03 --mode vis``` | ||
|
||
* To visualize the results for in-the-wild data: | ||
```python ego_pose/eval_forecast_wild.py --egoforecast-cfg cross_01 --data wild_01 --mode vis``` | ||
|
||
|
||
# Training and Testing | ||
* If you are interested in training and testing with our code, please see [train_and_test.md](https://github.com/Khrylx/EgoPose/blob/master/docs/train_and_test.md). | ||
|
||
# Citation | ||
If you find our work useful in your research, please consider citing our paper [Ego-Pose Estimation and Forecasting as Real-Time PD Control](https://www.ye-yuan.com/ego-pose): | ||
``` | ||
@inproceedings{yuan2019ego, | ||
title={Ego-Pose Estimation and Forecasting as Real-Time PD Control}, | ||
author={Yuan, Ye and Kitani, Kris}, | ||
booktitle={Proceedings of the IEEE International Conference on Computer Vision}, | ||
year={2019} | ||
} | ||
``` | ||
|
||
# License | ||
|
||
The software in this repo is freely available for free non-commercial use. Please see the [license](https://github.com/Khrylx/EgoPose/blob/master/LICENSE) for further details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from agents.agent_pg import AgentPG | ||
from agents.agent_ppo import AgentPPO | ||
from agents.agent_trpo import AgentTRPO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import multiprocessing | ||
from core import LoggerRL, TrajBatch | ||
from utils.memory import Memory | ||
from utils.torch import * | ||
import math | ||
import time | ||
|
||
|
||
class Agent: | ||
|
||
def __init__(self, env, policy_net, value_net, dtype, device, custom_reward=None, | ||
mean_action=False, render=False, running_state=None, num_threads=1): | ||
self.env = env | ||
self.policy_net = policy_net | ||
self.value_net = value_net | ||
self.dtype = dtype | ||
self.device = device | ||
self.custom_reward = custom_reward | ||
self.mean_action = mean_action | ||
self.running_state = running_state | ||
self.render = render | ||
self.num_threads = num_threads | ||
self.noise_rate = 1.0 | ||
self.traj_cls = TrajBatch | ||
self.logger_cls = LoggerRL | ||
self.sample_modules = [policy_net] | ||
self.update_modules = [policy_net, value_net] | ||
|
||
def sample_worker(self, pid, queue, min_batch_size): | ||
torch.randn(pid) | ||
if hasattr(self.env, 'np_random'): | ||
self.env.np_random.rand(pid) | ||
memory = Memory() | ||
logger = LoggerRL() | ||
|
||
while logger.num_steps < min_batch_size: | ||
state = self.env.reset() | ||
if self.running_state is not None: | ||
state = self.running_state(state) | ||
logger.start_episode(self.env) | ||
self.pre_episode() | ||
|
||
for t in range(10000): | ||
state_var = tensor(state).unsqueeze(0) | ||
vs_out = self.trans_policy(state_var) | ||
mean_action = self.mean_action or np.random.binomial(1, 1 - self.noise_rate) | ||
action = self.policy_net.select_action(vs_out, mean_action)[0].numpy() | ||
action = int(action) if self.policy_net.type == 'discrete' else action.astype(np.float64) | ||
next_state, env_reward, done, info = self.env.step(action) | ||
if self.running_state is not None: | ||
next_state = self.running_state(next_state) | ||
if self.custom_reward is not None: | ||
c_reward, c_info = self.custom_reward(self.env, state, action, info) | ||
reward = c_reward | ||
else: | ||
c_reward, c_info = 0.0, np.array([0.0]) | ||
reward = env_reward | ||
logger.step(self.env, env_reward, c_reward, c_info) | ||
|
||
mask = 0 if done else 1 | ||
exp = 1 - mean_action | ||
self.push_memory(memory, state, action, mask, next_state, reward, exp) | ||
|
||
if pid == 0 and self.render: | ||
self.env.render() | ||
if done: | ||
break | ||
state = next_state | ||
|
||
logger.end_episode(self.env) | ||
logger.end_sampling() | ||
|
||
if queue is not None: | ||
queue.put([pid, memory, logger]) | ||
else: | ||
return memory, logger | ||
|
||
def pre_episode(self): | ||
return | ||
|
||
def push_memory(self, memory, state, action, mask, next_state, reward, exp): | ||
memory.push(state, action, mask, next_state, reward, exp) | ||
|
||
def pre_sample(self): | ||
return | ||
|
||
def sample(self, min_batch_size): | ||
t_start = time.time() | ||
self.pre_sample() | ||
to_test(*self.sample_modules) | ||
with to_cpu(*self.sample_modules): | ||
with torch.no_grad(): | ||
thread_batch_size = int(math.floor(min_batch_size / self.num_threads)) | ||
queue = multiprocessing.Queue() | ||
memories = [None] * self.num_threads | ||
loggers = [None] * self.num_threads | ||
for i in range(self.num_threads-1): | ||
worker_args = (i+1, queue, thread_batch_size) | ||
worker = multiprocessing.Process(target=self.sample_worker, args=worker_args) | ||
worker.start() | ||
memories[0], loggers[0] = self.sample_worker(0, None, thread_batch_size) | ||
|
||
for i in range(self.num_threads - 1): | ||
pid, worker_memory, worker_logger = queue.get() | ||
memories[pid] = worker_memory | ||
loggers[pid] = worker_logger | ||
traj_batch = self.traj_cls(memories) | ||
logger = self.logger_cls.merge(loggers) | ||
|
||
logger.sample_time = time.time() - t_start | ||
return traj_batch, logger | ||
|
||
def trans_policy(self, states): | ||
"""transform states before going into policy net""" | ||
return states | ||
|
||
def trans_value(self, states): | ||
"""transform states before going into value net""" | ||
return states | ||
|
||
def set_noise_rate(self, noise_rate): | ||
self.noise_rate = noise_rate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
from core import estimate_advantages | ||
from agents.agent import Agent | ||
from utils.torch import * | ||
import time | ||
|
||
|
||
class AgentPG(Agent): | ||
|
||
def __init__(self, gamma=0.99, tau=0.95, optimizer_policy=None, optimizer_value=None, | ||
opt_num_epochs=1, value_opt_niter=1, **kwargs): | ||
super().__init__(**kwargs) | ||
self.gamma = gamma | ||
self.tau = tau | ||
self.optimizer_policy = optimizer_policy | ||
self.optimizer_value = optimizer_value | ||
self.opt_num_epochs = opt_num_epochs | ||
self.value_opt_niter = value_opt_niter | ||
|
||
def update_value(self, states, returns): | ||
"""update critic""" | ||
for _ in range(self.value_opt_niter): | ||
values_pred = self.value_net(self.trans_value(states)) | ||
value_loss = (values_pred - returns).pow(2).mean() | ||
self.optimizer_value.zero_grad() | ||
value_loss.backward() | ||
self.optimizer_value.step() | ||
|
||
def update_policy(self, states, actions, returns, advantages, exps): | ||
"""update policy""" | ||
# use a2c by default | ||
ind = exps.nonzero().squeeze(1) | ||
for _ in range(self.opt_num_epochs): | ||
self.update_value(states, returns) | ||
log_probs = self.policy_net.get_log_prob(self.trans_policy(states)[ind], actions[ind]) | ||
policy_loss = -(log_probs * advantages[ind]).mean() | ||
self.optimizer_policy.zero_grad() | ||
policy_loss.backward() | ||
self.optimizer_policy.step() | ||
|
||
def update_params(self, batch): | ||
t0 = time.time() | ||
to_train(*self.update_modules) | ||
states = torch.from_numpy(batch.states).to(self.dtype).to(self.device) | ||
actions = torch.from_numpy(batch.actions).to(self.dtype).to(self.device) | ||
rewards = torch.from_numpy(batch.rewards).to(self.dtype).to(self.device) | ||
masks = torch.from_numpy(batch.masks).to(self.dtype).to(self.device) | ||
exps = torch.from_numpy(batch.exps).to(self.dtype).to(self.device) | ||
with to_test(*self.update_modules): | ||
with torch.no_grad(): | ||
values = self.value_net(self.trans_value(states)) | ||
|
||
"""get advantage estimation from the trajectories""" | ||
advantages, returns = estimate_advantages(rewards, masks, values, self.gamma, self.tau) | ||
|
||
self.update_policy(states, actions, returns, advantages, exps) | ||
|
||
return time.time() - t0 |
Oops, something went wrong.