Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Python API including enabled AsynchronousOut mode #1593

Merged

Conversation

frankier
Copy link
Contributor

Currently AsynchronousOut mode won't work with the Python API since it is not possible to get ahold of a Datum created inside OpenPose from the Python side. The reason for this is at the moment, lists are copied when going over the Python => C++ boundary. See https://pybind11.readthedocs.io/en/stable/advanced/cast/stl.html#making-opaque-types . To get the semantics of passing a mutable reference, we can wrap an STL type.

Unfortunately this is not quite sufficient. We need to pass a shared_pointer<vector<shared_pointer>> to openpose::Wrapper. The outer shared pointer is eventually pointed somewhere else in queue.hpp:

tDatums = {std::move(this->mTQueue.front())};

So we just swap that vector with ours, which should avoid copying the datum I think. I'm a bit confused about why there are so many levels of nesting though. A more idiomatic approach would be to just return a value in Python, but since the Python/C++ APIs are currently very similar, I thought I'd keep it this way and just adjust it to work in this case also.

This PR also contains the following related changes:

  • Update Python tutorial for adjusted API and port C++ AsynchronousOut example to Python
  • Add ThreadManagerMode enum to Python interface

And a couple of unrelated bug fixes to the Python API:

  • Add type_caster<op::Array<long long>> so datum.poseIds can be accessed from Python
  • Cast empty Arrays on Datum to None in Python rather than numpy scalars of trash data.

@frankier
Copy link
Contributor Author

Updated to only set up producer when we need synchronous input

@stale
Copy link

stale bot commented Aug 16, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale/old label Aug 16, 2020
@frankier
Copy link
Contributor Author

Please review!

@stale stale bot removed the stale/old label Aug 16, 2020
@stale
Copy link

stale bot commented Oct 17, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale/old label Oct 17, 2020
@frankier
Copy link
Contributor Author

Please review!

@stale stale bot removed the stale/old label Oct 23, 2020
@gineshidalgo99
Copy link
Member

Sorry for the HUGE delay! I have finally reviewed it, there is a big question I have:

The new Python example you added (examples/tutorial_api_python/12_asynchronous_custom_output.py), how is it an asynchronous example? Where in that example you set it to be asynchronous?

@frankier
Copy link
Contributor Author

You're right -- that seems to have been an oversight. Fixed.

@frankier
Copy link
Contributor Author

Is there anything I can do to make this easier to review and merge?

@gineshidalgo99 gineshidalgo99 merged commit 7b96008 into CMU-Perceptual-Computing-Lab:master Oct 29, 2020
@gineshidalgo99
Copy link
Member

Pushed, this is an amazing PR, thanks a lot! (It just took me forever to review it given its complexity, sorry about that, but amazing PR!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants