From fb504d79d221f4861eff6c4fce68803b77989f80 Mon Sep 17 00:00:00 2001 From: Victorletzelter Date: Fri, 18 Oct 2024 18:39:37 +0200 Subject: [PATCH] text updated and plot torus --- README.md | 16 ++++- toy_experiment/data/distributions.py | 9 ++- toy_experiment/images/torus.pdf | Bin 0 -> 1205 bytes toy_experiment/tor-plot.py | 101 +++++++++++++++++++++++++++ 4 files changed, 121 insertions(+), 5 deletions(-) create mode 100644 toy_experiment/images/torus.pdf create mode 100644 toy_experiment/tor-plot.py diff --git a/README.md b/README.md index d2b822c..13e9d12 100755 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@
-

ManiPose: Manifold-Constrained Multi-Hypothesis 3D Human Pose Estimation

+

ManiPose: Manifold-Constrained Multi-Hypothesis 3D Human Pose Estimation (NeurIPS 2024)

Cédric Rommel, Victor Letzelter, Nermin Samet, Renaud Marlet, Matthieu Cord, Patrick Pérez, Eduardo Valle

@@ -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 @@ -187,11 +187,21 @@ cd toy_experiment ; python plotting_script.py You should find the corresponding figures in the `./figures` folder:

-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: diff --git a/toy_experiment/data/distributions.py b/toy_experiment/data/distributions.py index 89bc31d..d846e20 100755 --- a/toy_experiment/data/distributions.py +++ b/toy_experiment/data/distributions.py @@ -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 \ No newline at end of file + + 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 \ No newline at end of file diff --git a/toy_experiment/images/torus.pdf b/toy_experiment/images/torus.pdf new file mode 100644 index 0000000000000000000000000000000000000000..4a821edb78dc130ac492092eb7fcd4bfdc57a762 GIT binary patch literal 1205 zcmZWpzi-n(6pk28VL{m+L)2EZx%1DsRjHs!Qw3TYB@9Sa2gkmoZc|@$xwe4`HY7G? zkl0}=5)y1|h)957?SP74=1<_A?FK7857vG6?%wyl@7}xA4K<+;rFd$V=dVSsl()4<42nGhUV0BevQJ@0d%!WFTB$#mkd9dBtXTF3=GF>0Z zjkfe811kZVo|H^PV5_M{+IwCQMm=!SRl)r>ldywnYjvc;MiNNl5Gkys|7!Ygz;1?) zo-aW0R_p~sb_spbVnco;e5^{LpS_a7ueEQQ@U`&e z^Uw1;zs@fe-W?aulr`zOsYx*jMXXY}@Ga)9pdHw~z?5|<{r?6lzjB~*Ee9&^a-i}* z2P#ccFzvFWxyaox7@`HSi>*ZYBXmvAI-Fris;Hji0_L_nIp}lQ4?A#dmY2%L0_;gS z7%mfXI9V!l(VN#uQ}E!(M>Dd!20<4(o_~Ofr6*uye0<2Gnrhs++Ok0nOQ*W4yQXPd zH>fd7>Fj)l+(@vlMnShUIvL>DwrN8bCYX*&sR7Xhb4=`|DaU3ys*zi{J^xsM+~(B(&Aj1tS%F2 aL|qPg@`}V4#1k@>)wL>GskFXb*Zu)>gGJ~7 literal 0 HcmV?d00001 diff --git a/toy_experiment/tor-plot.py b/toy_experiment/tor-plot.py new file mode 100644 index 0000000..1961f0f --- /dev/null +++ b/toy_experiment/tor-plot.py @@ -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) +# %%