You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add asynchronous mode for dnn's Net with Intel's Inference Engine backend #13667
Intel's Inference Engine supports asynchronous forward passes using multiple inference requests. Let users enable async. networks inference.
Initial proposal
Requires adding a new method Net::enableAsync(bool) to specify if we want to execute network asynchronously.
Net::setInput is used to set input data in the internal inputs queue and Net::forward to retrieve outputs in the same order.
Net::forward returns an empty Mat in case of output is not ready => User need to check that output is not empty.
Considered scenarios of Net in async mode:
Standard loop
net.enableAsync(1);
net.setInput(inp1);
out1 = net.forward();
net.setInput(inp2);
out = net.forward(); // out is output for inp1 if out1 is empty. Otherwise it's output for inp2
...
This way user should store inputs and pop them by ready outputs (i.e. render detections).
Prefetch
net.enableAsync(1);
net.setInput(inp1);
net.setInput(inp2);
...
out1 = net.forward();
out = net.forward(); // out is output for inp1 if out1 is empty. Otherwise it's output for inp2
Syncing
net.enableAsync(1);
net.setInput(inp1);
out = net.forward(); // assume out is empty here (not ready)
out = net.forward(); // assume out is not ready again
net.enableAsync(0);
out = net.forward(); // wait here until output is ready
Syncing let users control maximum number of asynchronous requests. In example, if number of fetched inputs equals to specified maximum number of requests, we disable async mode and wait for the output of the first input in queue. Note that it doen't disable asynchronous computations at that time but specifies that next Net::forward invocation should return output.
@AyushP123, In my opinion it's quite complicated task. If you have no experience working with OpenCV's deep learning module it's better to start with simpler issues. In example:
We can collaborate doing this feature at some point. In example, I can prepare all the internal changes and then ask you to modify our samples to enable asynchronous mode. What do you think about it?
Wanted to understand a bit ( sorry if I sound dumb ):
Q1. Will Net::forward() launch a thread which will keep reading inputs from the input queue?? and run the network in parallel for each input??
Q2. if the network is a fully convolution network then there is a possibility that inp2 might finish before inp1, how do we ensure that in standard loop out is the output for inp1??.
Is there any resource that I should read for understanding this a bit more??.
Q1. Will Net::forward() launch a thread which will keep reading inputs from the input queue?? and run the network in parallel for each input??
Yes. That means that forward initiates asynchronous inference. We can continue capturing new frames from camera and call setInput for example. This way user should collect frames somehow and render detections on them by readiness.
Q2. if the network is a fully convolution network then there is a possibility that inp2 might finish before inp1, how do we ensure that in standard loop out is the output for inp1??.
You're right. inp2 can be processed faster. However Net::forward should return an empty Mat if inp1 is still processing or out1. After that we can return out2 (output for inp2) which will be ready at that moment.
Sorry for the long time waiting. We were making this feature as much stable and easy to use as it possible and I think the last version is good enough.
So as we discussed earlier I would like to ask you to propose a PR with modified sample which can demonstrate a new feature. I think that it's better to modify both C++ and Python versions of object detection sample. We have the following expectations from it:
Add a new argument which can control number of maximum asynchronous requests at the same time. That means if we reached a limit of std::future queue, we'll wait for the end of the oldest one. This argument will have especial values: 1 for synchronous mode and -1 for unlimited number of requests.
The sample should demonstrate the profit of asynchronous mode. That means you need to introduce appropriate way to measure number of processed frames per second which shows the real difference between synchronous mode and asynchronous with different limits.
You may check the tests for C++ and Python that added in the PR #13694 for reference.
If you have no time for it please let us know so we can open a separate issue for this task. Thanks you!
Hi @dkurt, sorry for the late response, I got the notification for the closure of this PR but not for the comment weirdly. I would like to contribute towards writing a sample to demonstrate the feature. I don't think anyone has started working on it. I am a bit busy with work these days, but I will definitely open a PR by this weekend if you are okay with it.
Activity
AyushP123 commentedon Jan 22, 2019
Hi @dkurt, have you started working on this or should I have a go at it.
dkurt commentedon Jan 22, 2019
@AyushP123, In my opinion it's quite complicated task. If you have no experience working with OpenCV's deep learning module it's better to start with simpler issues. In example:
#13479
#13462
#13626
AyushP123 commentedon Jan 22, 2019
Thanks a lot for your response @dkurt, will start those issues. Have been using OpenCV's dnn for a year, but didnt play a lot with the codebase.
dkurt commentedon Jan 22, 2019
@AyushP123, wow, that's cool. Thank you!
We can collaborate doing this feature at some point. In example, I can prepare all the internal changes and then ask you to modify our samples to enable asynchronous mode. What do you think about it?
AyushP123 commentedon Jan 22, 2019
Sounds awesome!!
AyushP123 commentedon Jan 22, 2019
Wanted to understand a bit ( sorry if I sound dumb ):
Q1. Will Net::forward() launch a thread which will keep reading inputs from the input queue?? and run the network in parallel for each input??
Q2. if the network is a fully convolution network then there is a possibility that inp2 might finish before inp1, how do we ensure that in standard loop out is the output for inp1??.
Is there any resource that I should read for understanding this a bit more??.
dkurt commentedon Jan 22, 2019
@AyushP123, In my current vision,
Yes. That means that
forwardinitiates asynchronous inference. We can continue capturing new frames from camera and callsetInputfor example. This way user should collect frames somehow and render detections on them by readiness.You're right.
inp2can be processed faster. HoweverNet::forwardshould return an empty Mat ifinp1is still processing orout1. After that we can returnout2(output forinp2) which will be ready at that moment.dkurt commentedon Jan 28, 2019
Proposal number 2
Instead of introducing new behavior of
Net::forward, add new methods withAsyncsuffix for existing methods:No
enableAsync(1)is required -forwardAsyncinitiates asynchronous request and returns an empty Mat if it's not ready.To finish existing requests synchronously, do not turn
enableAsync(0)but just call a regularforward.dkurt commentedon Apr 22, 2019
@AyushP123, Hi!
Sorry for the long time waiting. We were making this feature as much stable and easy to use as it possible and I think the last version is good enough.
So as we discussed earlier I would like to ask you to propose a PR with modified sample which can demonstrate a new feature. I think that it's better to modify both C++ and Python versions of object detection sample. We have the following expectations from it:
Add a new argument which can control number of maximum asynchronous requests at the same time. That means if we reached a limit of
std::futurequeue, we'll wait for the end of the oldest one. This argument will have especial values:1for synchronous mode and-1for unlimited number of requests.The sample should demonstrate the profit of asynchronous mode. That means you need to introduce appropriate way to measure number of processed frames per second which shows the real difference between synchronous mode and asynchronous with different limits.
You may check the tests for C++ and Python that added in the PR #13694 for reference.
If you have no time for it please let us know so we can open a separate issue for this task. Thanks you!
AyushP123 commentedon May 15, 2019
Hi @dkurt, sorry for the late response, I got the notification for the closure of this PR but not for the comment weirdly. I would like to contribute towards writing a sample to demonstrate the feature. I don't think anyone has started working on it. I am a bit busy with work these days, but I will definitely open a PR by this weekend if you are okay with it.
AyushP123 commentedon May 15, 2019
Ahh, I am late, saw the PRs #14538, #14516 merged. I will try to contribute more actively for other issues.
dkurt commentedon May 16, 2019
@AyushP123, sure, thank you!