Skip to content

Commit

Permalink
text updated and plot torus
Browse files Browse the repository at this point in the history
  • Loading branch information
Victorletzelter authored and cedricrommel committed Nov 27, 2024
1 parent f3150f8 commit fb504d7
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 5 deletions.
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div align="center">
<h1> ManiPose: Manifold-Constrained Multi-Hypothesis 3D Human Pose Estimation </h1>
<h1> ManiPose: Manifold-Constrained Multi-Hypothesis 3D Human Pose Estimation (NeurIPS 2024) </h1>
<h3> Cédric Rommel, Victor Letzelter, Nermin Samet, Renaud Marlet, Matthieu Cord, Patrick Pérez, Eduardo Valle
</h3>
<!-- <h4> <i> International Conference on Computer Vision (ICCV), <br> Workshop Analysis and Modeling of Faces and Gestures, 2023 </i></h4> -->
Expand Down Expand Up @@ -177,7 +177,7 @@ python main_3dhp.py \
train.batch_size_test=30
``` -->

# 1D-to-2D toy experiment
# toy experiments

Figure 4 can be reproduced in ~2 minutes using a ~10GB GPU. Just run the following command:
```bash
Expand All @@ -187,11 +187,21 @@ cd toy_experiment ; python plotting_script.py
You should find the corresponding figures in the `./figures` folder:
<p align="center"> <img src="./assets/single_toy_picture_column_v2.png" width="80%"> </p>

Table 1 can also be reproduced in ~2 minutes using the following command:
Table 1 can be reproduced using the following command:
```bash
bash toy_experiment/quantitative_comparison_toy2d.sh
```

The Figure 8 from 2D-to-3D toy experiment can be reprocuced and saved in `toy_experiment/images` by running
```python toy_experiment/toy-plot.py
python
```

Table 6 can also be reproced using the command:
```bash
bash toy_experiment/quantitative_comparison_toy3d.sh
```

# Acknowledgments

The basis of the human pose lifting code was borrowed from [DiffHPE](https://github.com/valeoai/diffhpe), which builds on top of several other repositories, including:
Expand Down
9 changes: 7 additions & 2 deletions toy_experiment/data/distributions.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,14 @@ def __init__(
for c, mu, kappa in zip(self.components, self.modes, self.dispersions):
self.dist_list.append(BivariateVonMises(phi_loc=mu[0], psi_loc=mu[1],phi_concentration=kappa[0],psi_concentration=kappa[1],correlation=0.))

def sample(self, size: int) -> Tuple[np.array, np.array]:
def sample(self, size: int, output_components=False) -> Tuple[np.array, np.array]:
angles = super().sample(size)
cartesian_points = self.torusanglestocartesian(major_radius=self.major_radius,minor_radius=self.minor_radius,angles=angles)
assert np.shape(np.stack((cartesian_points[:,0],cartesian_points[:,2]),axis=-1)) == (size,2)
assert np.shape(cartesian_points) == (size,3)
return np.stack((cartesian_points[:,0],cartesian_points[:,2]),axis=-1), cartesian_points

if output_components is True:
return np.stack((cartesian_points[:,0],cartesian_points[:,2]),axis=-1), cartesian_points, self.picked_components

else :
return np.stack((cartesian_points[:,0],cartesian_points[:,2]),axis=-1), cartesian_points
Binary file added toy_experiment/images/torus.pdf
Binary file not shown.
101 changes: 101 additions & 0 deletions toy_experiment/tor-plot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#%%

import os

os.system('pip install pyro-ppl')
os.system('pip install ipympl')
os.system('pip install entrypoints')

#%%

import numpy as np
from data import (
LiftingDist2Dto3D)
import rootutils
rootutils.setup_root(__file__, indicator=".project-root", project_root_env_var=True, pythonpath=True)

major_radius = 2
minor_radius = 1
R = major_radius
r = minor_radius
N = 10
x = np.linspace(-(R+2*r), (R+2*r), N)
y = np.linspace(-(R+2*r), (R+2*r), N)
z = np.linspace(-r, r, N)
X_test = np.stack([x,z], axis=1) #(N,2)
Y_test = np.stack([x,y,z], axis=1) #(N,3)

distribution = LiftingDist2Dto3D(
major_radius=2,
minor_radius=1,
weights= [0.3, 0.4,0.2,0.1],
modes = [(-3.1415, 0), (0,3.1415/4),(0.5, -3.1415/4), (2*3.1415/3,3.1415/2)],
dispersions=[(2,2), (4,4),(3,3),(10,10)],
random_state=123)

_, points, components = distribution.sample(size=1000, output_components=True)
angles = distribution.torus_cartesian_to_angles_batch(major_radius=2,minor_radius=1,points = points)

#%%

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib.lines import Line2D

def plot_torus(angles, point_colors, R=2, r=1):
"""
Visualize points on a torus given their angular coordinates.
:param angles: A (N, 2) shaped array of angular coordinates (u, v).
:param R: Major radius of the torus.
:param r: Minor radius of the torus.
"""
# Convert angular coordinates to Cartesian coordinates
u, v = angles[:, 0], angles[:, 1]
x = (R + r * np.cos(v)) * np.cos(u)
y = (R + r * np.cos(v)) * np.sin(u)
z = r * np.sin(v)

# Create a 3D plot
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

# Labeling the axes
ax.set_xlabel('X axis')
ax.set_ylabel('Y axis')
ax.set_zlabel('Z axis')

# Creating a mesh for the torus
u = np.linspace(0, 2 * np.pi, 50)
v = np.linspace(0, 2 * np.pi, 50)
u, v = np.meshgrid(u, v)
x_tor = (R + r * np.cos(v)) * np.cos(u)
y_tor = (R + r * np.cos(v)) * np.sin(u)
z_tor = r * np.sin(v)

# Plotting the torus mesh
ax.plot_wireframe(x_tor, y_tor, z_tor, color='gray', alpha=0.3,zorder=1)

ax.scatter(x, y, z, c=point_colors,zorder=2)

elevation = 60
azimuth = -45
ax.view_init(azim=azimuth, elev=elevation)

# plt.title('Distribution of Points on the Torus')

plt.show()

colors = ['blue', 'green', 'red', 'purple']
point_colors = [colors[comp] for comp in components]
# Example usage
plot_torus(angles, point_colors= point_colors) # Visualize the distribution on a torus

if not os.path.exists(os.path.join(os.environ['PROJECT_ROOT'],'toy_experiment/images')):
os.makedirs(os.path.join(os.environ['PROJECT_ROOT'],'toy_experiment/images'))

filepath = os.path.join(os.environ['PROJECT_ROOT'],'toy_experiment/images/torus.pdf')

plt.savefig(filepath)
# %%

0 comments on commit fb504d7

Please sign in to comment.