Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

60x Speedup on IUV2FBC Function. Greatly speeds up converting a 2D person image to a 3D model. #99

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

davidleejy
Copy link

@davidleejy davidleejy commented Aug 21, 2018

Referenced in #98
Hello,

This PR gives a 60x speed up to IUV2FBC (in DensePose/detectron/utils/densepose_methods.py). IUV2FBC function converts an IUV point to an XYZ point on a SMPL model. This will convenience users who would like to make a 3D person out of a 2D person image (e.g. in virtual reality).

Timings

Run IUV2FBC on 125 IUV points in 'DensePoseData/demo_data/demo_dp_single_ann.pkl' ...

Original:

8629403 function calls in 5.227 seconds
Ordered by: cumulative time
   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.000    0.000    5.227    5.227 <string>:1(<module>)
        1    0.001    0.001    5.227    5.227 <ipython-input-40-02014517a6cb>:32(f)
      125    0.088    0.001    5.219    0.042 densepose_methods.py:270(IUV2FBC)
    35578    0.430    0.000    5.064    0.000 densepose_methods.py:62(barycentric_coordinates_exists)
   108588    1.486    0.000    4.536    0.000 numeric.py:1591(cross)

Sped up:

39129 function calls in 0.081 seconds
Ordered by: cumulative time
   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.000    0.000    0.081    0.081 <string>:1(<module>)
        1    0.001    0.001    0.081    0.081 <ipython-input-39-6b6ed951a68c>:32(f)
      125    0.014    0.000    0.079    0.001 densepose_methods.py:174(IUV2FBC_fast)
      125    0.035    0.000    0.059    0.000 densepose_methods.py:135(barycentric_coordinates_fast)
      375    0.008    0.000    0.020    0.000 numeric.py:1591(cross)

Run IUV2FBC on 80000 IUV points ...

summary

Original: Estimated ~53 minutes (80000 points / 125 points * 5 secs ~= 53 mins)

Sped up: 1 minute (timing obtained from a profiled run)

PR Contribution

notebooks/DensePose-Fast-IUV-2-XYZ.ipynb : Is a demo. Also addresses issue #87 .

detectron/utils/densepose_methods.py : Contains sped-up codes. Backward-compatible since original functions not modified. New functions: IUV2FBC_fast and barycentric_coordinates_fast.

DensePoseData/demo_data_2/* : Data given for the convenience of running DensePose-Fast-IUV-2-XYZ.ipynb .

@facebook-github-bot facebook-github-bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Aug 21, 2018
@nvrv nvrv requested a review from ralpguler August 21, 2018 14:29
@davidleejy
Copy link
Author

@nvrv @ralpguler
Loved using Densepose and would be grateful for the opportunity to contribute to this repository. The following sheds more light on how the speed-up came about:

  • Main source of speed-up is batching numpy cross product computations (https://stackoverflow.com/questions/1988091/poor-numpy-cross-performance) executed frequented in barycentric_coordinates_exists() and barycentric_coordinates(). Instead of calling numpy.cross() on 2 vectors at a time, I called it on a bunch of vectors in a single call.

  • Secondary source of speed-up is removing duplicate computations in barycentric_coordinates_exists() and barycentric_coordinates().

  • The result is a single function barycentric_coordinates_fast().

  • New code is functionally identical to original code in that it produces the same results.

  • End-users call a new function IUV2FBC_fast() that takes in the same parameters as the original function IUV2FBC().
    IUV2FBC_fast( self, I_point , U_point, V_point)
    IUV2FBC( self, I_point , U_point, V_point)

  • I admit the demo notebook I gave is kind of messy in hindsight. I could have removed a lot of cells to help better convey this improvement. I could clean it up if it'd help the reviewers & maintainers. :)

Feel free to comment with questions and/or suggestions :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
CLA Signed Do not delete this pull request or issue due to inactivity.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants