Skip to content

Commit e758d95

Browse files
authored
Merge pull request #61 from rfahrn/docs6
add .rst files and utils
2 parents 2d36dcd + e46ecc1 commit e758d95

File tree

85 files changed

+1268
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+1268
-0
lines changed

Diff for: docs/examples.rst

+134
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
Examples
2+
========
3+
4+
Pose Format Conversion with Sirens
5+
-----------------------------------
6+
7+
The ``pose_to_siren_to_pose.py`` script shows us how to change a 3D pose using something called a Siren neural network.
8+
9+
.. note::
10+
11+
The function follows these steps:
12+
13+
1. Fills missing data in the body with zeros.
14+
2. Normalizes the pose distribution.
15+
3. Converts the pose using the Siren neural network.
16+
4. Constructs the new Pose with the predicted data.
17+
5. Unnormalizes the pose distribution.
18+
19+
Also: Before you start, ensure you have a `.pose` file/ path. This is the standardized format that stores the 3D pose information. If you don't have one, you might either need to obtain it from a relevant dataset or convert your existing pose data into this format.
20+
21+
Step-by-step Guide:
22+
~~~~~~~~~~~~~~~~~~~
23+
24+
1. **Preparation**
25+
26+
Begin by importing the necessary modules:
27+
28+
.. code-block:: python
29+
30+
import numpy as np
31+
from numpy import ma
32+
import pose_format.utils.siren as siren
33+
from pose_format import Pose
34+
from pose_format.numpy import NumPyPoseBody
35+
from pose_format.pose_visualizer import PoseVisualizer
36+
37+
38+
2. **Define the Conversion Function**
39+
40+
The function `pose_to_siren_to_pose` is used to perform the conversion. An you find the overview of the whole function :ref:`overview`
41+
42+
43+
.. code-block:: python
44+
45+
def pose_to_siren_to_pose(p: Pose, fps=None) -> Pose:
46+
"""Converts a given Pose object to its Siren representation and back to Pose."""
47+
48+
# Fills missing values with 0's
49+
p.body.zero_filled()
50+
51+
# Noralizes
52+
mu, std = p.normalize_distribution()
53+
54+
# Use siren net
55+
net = siren.get_pose_siren(p, total_steps=3000, steps_til_summary=100, learning_rate=1e-4, cuda=True)
56+
57+
new_fps = fps if fps is not None else p.body.fps
58+
coords = siren.PoseDataset.get_coords(time=len(p.body.data) / p.body.fps, fps=new_fps)
59+
60+
# Get predicitons of new Pose data
61+
pred = net(coords).cpu().numpy()
62+
63+
# Construct new Body out of predcitions
64+
pose_body = NumPyPoseBody(fps=new_fps, data=ma.array(pred), confidence=np.ones(shape=tuple(pred.shape[:3])))
65+
p = Pose(header=p.header, body=pose_body)
66+
67+
# Revert normalization and give back the pose instance
68+
p.unnormalize_distribution(mu, std)
69+
return p
70+
71+
72+
The function does the following operations:
73+
74+
- Fills missing data in the pose body with zeros.
75+
- Normalizes the pose distribution.
76+
- Uses the Siren neural network to transform the pose.
77+
- Constructs a new Pose with the predicted data.
78+
- Reverts the normalization on the pose distribution.
79+
80+
3. **Usage**
81+
82+
After defining the function, you can use it in your main script:
83+
84+
.. code-block:: python
85+
86+
if __name__ == "__main__":
87+
pose_path = "/home/nlp/amit/PhD/PoseFormat/sample-data/1.pose" # your own file path to a `.pose` file
88+
89+
buffer = open(pose_path, "rb").read()
90+
p = Pose.read(buffer)
91+
print("Poses loaded")
92+
93+
p = pose_to_siren_to_pose(p)
94+
95+
info = p.header.normalization_info(
96+
p1=("pose_keypoints_2d", "RShoulder"),
97+
p2=("pose_keypoints_2d", "LShoulder")
98+
)
99+
p.normalize(info, scale_factor=300)
100+
p.focus()
101+
102+
v = PoseVisualizer(p)
103+
v.save_video("reconstructed.mp4", v.draw(max_frames=3000))
104+
105+
106+
The main script performs these tasks:
107+
108+
- Reads the pose data from a file.
109+
- Applies the ``pose_to_siren_to_pose`` function to the read pose.
110+
- Normalizes and focuses the pose.
111+
- Visualizes the converted pose using the ``PoseVisualizer``.
112+
113+
4. **Execution**
114+
115+
To run the script:
116+
117+
.. code-block:: bash
118+
119+
$ python pose_format_converter.py
120+
121+
122+
123+
The ``pose_format`` combined with Siren neural networks is great to transform and work with 3D pose data.
124+
By understanding and using the functions and methods provided in this script, you will be able to understand better how to manipulate and visualize 3D poses to suit your own requirements.
125+
126+
127+
.. _overview:
128+
129+
Overview of ``pose_to_siren_to_pose.py``
130+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
131+
132+
.. literalinclude:: ../examples/pose_to_siren_to_pose.py
133+
:language: python
134+
:linenos:

Diff for: docs/index.rst

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
.. Pose documentation master file, created by
2+
sphinx-quickstart on Tue Aug 15 14:09:31 2023.
3+
You can adapt this file completely to your liking, but it should at least
4+
contain the root `toctree` directive.
5+
6+
7+
8+
========================================
9+
Welcome to Pose-Format's documentation!
10+
========================================
11+
12+
Pose is an innovative toolkit created by :cite:`moryossef2021pose-format` dedicated to the handling, manipulation, and visualization of poses. With support for various file formats and the ability to operate
13+
with Python especially the :ref:`pose_format` package and JavaScript, Pose provides a comprehensive solution for pose-related tasks.
14+
15+
16+
17+
18+
.. toctree::
19+
:maxdepth: 3
20+
:caption: Introduction
21+
22+
readme
23+
24+
.. toctree::
25+
:maxdepth: 7
26+
:caption: Python Code Documentation
27+
28+
modules
29+
pose_format
30+
31+
.. toctree::
32+
:maxdepth: 2
33+
:caption: Additional Material
34+
35+
js_docs
36+
examples
37+
specs_v01
38+
39+
40+
41+
References
42+
----------
43+
44+
.. bibliography:: references.bib
45+
46+
Indices and tables
47+
==================
48+
49+
* :ref:`genindex`
50+
* :ref:`modindex`
51+
* :ref:`search`

Diff for: docs/js_docs.rst

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
JavaScript
2+
------------------------
3+
4+
.. toctree::
5+
:maxdepth: 2
6+
7+
pose_format_js
8+
pose_viewer_js

Diff for: docs/json.rst

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
JSON Files
2+
==========
3+
4+
package.JSON
5+
-------------
6+
7+
.. literalinclude:: ../src/js/pose_format/package.json
8+
:language: json
9+
:linenos:
10+
:caption: Description or Title for the JSON file
11+
12+
package-lock.JSON
13+
-----------------
14+
.. literalinclude:: ../src/js/pose_format/package-lock.json
15+
:language: json
16+
:linenos:
17+
:caption: Description or Title for the JSON file
18+
19+
tsconfig.JSON
20+
-------------
21+
22+
.. literalinclude:: ../src/js/pose_format/tsconfig.json
23+
:language: json
24+
:linenos:
25+
:caption: Description or Title for the JSON file
26+
27+
tslint.JSON
28+
-------------
29+
30+
31+
.. literalinclude:: ../src/js/pose_format/tslint.json
32+
:language: json
33+
:linenos:
34+
:caption: Description or Title for the JSON file

Diff for: docs/modules.rst

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
Structure
2+
=============
3+
4+
The :ref:`pose_format` aims to help users with the pose data management and pose analysis.
5+
The toolkit offers many functionalities, from reading and editing to visualizing and testing pose data. It provides a wide range of features for these tasks.
6+
7+
This section gives an brief overview of the main feature structure of the package and its functionalities.
8+
9+
Main Features
10+
-------------
11+
12+
1. **Reading and Manipulating Pose Data**:
13+
14+
* `.pose` files ensuring cross-compatibility between popular libraries such as NumPy, PyTorch, and TensorFlow.
15+
* The loaded data presents multiple manipulation options including:
16+
17+
- Normalizing pose data.
18+
- Agumentation of data.
19+
- Interpolation of data.
20+
21+
22+
2. **Visualization Capabilities**:
23+
24+
- Methods to visualize raw and processed pose data using `pose_format.pose_visualizer.PoseVisualizer` module.
25+
- Includes overlay functions for videos.
26+
27+
28+
3. **Package Organization and Components**:
29+
30+
* Structured with submodules and subpackages serving the purposes:
31+
32+
- :ref:`pose_format_numpy` for NumPy interactions.
33+
34+
- :ref:`pose_format_tensorflow` for TensorFlow functionalities.
35+
36+
- :ref:`pose_format_torch` for PyTorch-related tools.
37+
38+
- :ref:`pose_format_third_party` for externals.
39+
40+
- :ref:`pose_format_utils` for utility tools.
41+
42+
4. **Testing Suite**:
43+
44+
- Tests for the reliability of the package and its setups/data can be found in :ref:`tests`.
45+
46+
Tests
47+
------
48+
49+
This section illustrates the content of the testing suite and the used data.
50+
51+
.. toctree::
52+
:maxdepth: 4
53+
54+
tests

Diff for: docs/pose_format.numpy.pose_body.rst

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
pose\_format.numpy.pose\_body module
2+
====================================
3+
4+
.. automodule:: pose_format.numpy.pose_body
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:

Diff for: docs/pose_format.numpy.representation.distance.rst

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
pose\_format.numpy.representation.distance module
2+
=================================================
3+
4+
.. automodule:: pose_format.numpy.representation.distance
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
pose\_format.numpy.representation.distance\_test module
2+
=======================================================
3+
4+
.. automodule:: pose_format.numpy.representation.distance_test
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:

Diff for: docs/pose_format.numpy.representation.rst

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
pose\_format.numpy.representation package
2+
=========================================
3+
4+
.. toctree::
5+
:maxdepth: 2
6+
7+
pose_format.numpy.representation.distance
8+
pose_format.numpy.representation.distance_test
9+
10+

Diff for: docs/pose_format.numpy.rst

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.. _pose_format_numpy:
2+
3+
pose_format.numpy package
4+
==========================
5+
6+
Integration with the NumPy library.
7+
8+
.. automodule:: pose_format.numpy
9+
:members:
10+
:undoc-members:
11+
:show-inheritance:
12+
13+
.. toctree::
14+
:maxdepth: 4
15+
16+
pose_format.numpy.representation
17+
pose_format.numpy.pose_body

Diff for: docs/pose_format.pose.rst

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
pose\_format.pose module
2+
========================
3+
4+
.. automodule:: pose_format.pose
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:

Diff for: docs/pose_format.pose_body.rst

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
pose\_format.pose\_body module
2+
==============================
3+
4+
.. automodule:: pose_format.pose_body
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:

Diff for: docs/pose_format.pose_header.rst

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
pose\_format.pose\_header module
2+
================================
3+
4+
.. automodule:: pose_format.pose_header
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:

Diff for: docs/pose_format.pose_representation.rst

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
pose\_format.pose\_representation module
2+
========================================
3+
4+
.. automodule:: pose_format.pose_representation
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:

Diff for: docs/pose_format.pose_test.rst

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
pose\_format.pose\_test module
2+
==============================
3+
4+
.. automodule:: pose_format.pose_test
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:

Diff for: docs/pose_format.pose_visualizer.rst

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
pose\_format.pose\_visualizer module
2+
====================================
3+
4+
.. automodule:: pose_format.pose_visualizer
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:

0 commit comments

Comments
 (0)