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

Converting frame.pixels to usable form is too slow in Python #187

Closed
lydiatliu opened this issue Jul 14, 2016 · 3 comments · Fixed by #196
Closed

Converting frame.pixels to usable form is too slow in Python #187

lydiatliu opened this issue Jul 14, 2016 · 3 comments · Fixed by #196
Labels

Comments

@lydiatliu
Copy link

lydiatliu commented Jul 14, 2016

See for example the following line (86) from run_mission.py
#image = Image.frombytes('RGB', (frame.width, frame.height), str(bytearray(frame.pixels)) )

str(bytearray(frame.pixels)) by itself takes 0.056 seconds per call on average and takes up > 50% of my network training time. In particular, it seems that bytearray() is the slow operation.

Is there a way to get around this slowness in python if I still want to use Pillow for image processing? Thanks!

@lydiatliu
Copy link
Author

@DaveyBiggers @timhutton

@DaveyBiggers
Copy link
Member

I tried a few different methods for the ALE_HAC.py and found nothing that was particularly performant. We need to do some digging.

@DaveyBiggers
Copy link
Member

The boost python vector_indexing_suite that we use to expose vectors as python objects apparently doesn't implement the buffer protocol, which is what things like numpy, PIL etc use for fast memory access (eg to get at the raw bytes without needing to copy).
Hopefully we can use something else to expose the unsigned char vector - if necessary we can create our own Python/C wrapper for that one object manually (without using boost python), though I'm sure there are easier ways...

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

Successfully merging a pull request may close this issue.

2 participants