Re:Object Detection from 9 FPS to 650 FPS
by whimsicalism on Saturday October 10, 2020 @05:42PM
(#24742077)
The fact that batching is faster does not inherently imply some sort of inefficiency, but rather is indicative of the fact that sequential memory access is faster than random.
I am curious what the basis behind the idea that Python is the performance bottleneck for inference is.
Re:Object Detection from 9 FPS to 650 FPS
by g_airborne on Saturday October 10, 2020 @05:46PM
(#24742104)
It's not that Python is by definition much slower than C++, rather, doing inference in C++ makes it much easier to control exactly when memory is initialised, copied and moved between CPU and GPU. Especially on frame-by-frame models like object detection this can make a big difference. Also, the GIL can be a real problem if you are trying to scale inference on multiple incoming video streams for example.
Re:Object Detection from 9 FPS to 650 FPS
by threatripper on Sunday October 11, 2020 @09:22AM
(#24745577)
Control is probably the main point. The python interface makes things easy but doesn't offer enough control for my case. I tested it with a cut down example (no video decoding, no funny stuff) and it all comes down to the batch size that is passed to model.predict. Large batches level out at around 10000 fps depending on the GPU and batch size 1 goes down to 200 fps independent of the GPU. This tells me that some kind of overhead (hidden to me) is slowing things down. I guess that I have to go much deeper into the internals of TF to find out more - so far I did not because it's a large time hole that only offers better performance in a part that is not super critical right now.
The GIL and slowness of Python become a problem when processing multiple streams or doing further time consuming calculations in Python.
Do you have experience how single frame processing compares between Python and C++? I see that batched processing in Python gives me a huge speed boost which hints at inefficiencies at some point but I don't know if those are related to Python, Tensorflow or CUDA itself. (Or just bad resource management that requires re-initalization of some costly things in between evaluations.)