Skip to content

Asynchronous API from Intel's Inference Engine - #13694

Merged
alalek merged 6 commits into
opencv:3.4from
dkurt:dnn_ie_async
Apr 19, 2019
Merged

alalek merged 6 commits into
opencv:3.4from
dkurt:dnn_ie_async

Conversation

@dkurt

@dkurt dkurt commented Jan 25, 2019 •

Copy link
Copy Markdown
Member

resolves #13667

Proposed a way to enable Intel's Inference Engine asynchronous API in OpenCV.

Experimented with two different scenarios: inference without postprocessing and with a dummy postprocessing simulated by 10ms delay:

  1. Inference only
Model name CPU CPU async OCL OCL async OCL, fp16 OCL, fp16 async VPU VPU async
squeezenet_v1.1 495.4 486.5 (x0.98) 221.9 227.6 (x1.02) 285.9 288.4 (x1) 26.3 28.6 (x1.08)
MobileNetSSD 151.6 149.9 (x0.98) 59.3 60.4 (x1.01) 75.6 77.6 (x1.02) 10.8 11.3 (x1.04)
human-pose-estimation-0001 28.6 28.5 (x1) 16.3 16.4 (x1) 22.5 22.7 (x1) 2.24 2.28 (x1.01)
  1. 10ms postprocessing
Model name CPU CPU async OCL OCL async OCL, fp16 OCL, fp16 async VPU VPU async
squeezenet_v1.1 81.3 97.8 (x1.20) 65.6 96.4 (x1.46) 70.3 96.9 (x1.37) 20.6 28.6 (x1.38)
MobileNetSSD 59.5 97.0 (x1.63) 36.1 60.39 (x1.67) 41.5 76.2 (x1.83) 9.68 11.32 (x1.16)
human-pose-estimation-0001 21.9 28.6 (x1.30) 13.9 16.3 (x1.17) 18.2 22.6 (x1.24) 2.19 2.28 (x1.04)

As you may see, with inference only we can achieve quite small efficiency boost however in a pipeline overall FPS reaching numbers from experiment without postprocessing delay (Maybe except ones close to 100FPS because it's just a top number we can achieve with 10ms delay).

All numbers in FPS (frames per second): the higher the better
CPU: Intel® Core™ i7-6700K CPU @ 4.00GHz x 8
GPU: Intel® HD Graphics 530 (Skylake GT2)
VPU: Intel® Movidius™ Neural Compute Stick

Net net = readNet(..., ...);
net.setPreferableBackend(DNN_BACKEND_INFERENCE_ENGINE);
net.setPreferableTarget(...);

int blobSize[] = {1, 3, H, W};  // Depends on model
Mat blob(4, &blobSize[0], CV_32F);
randu(blob, 0.0f, 1.0f);

// Warmup
net.setInput(blob);
Mat out = net.forward();

TickMeter tm;
tm.start();

const int numFrames = 1000;  // 100 for human-pose-estimation-0001 on Myriad

// Uncomment to test asynchronous mode
{
  int numProcessed = 0;
  net.enableAsync(true);
  for (int i = 0; i < numFrames; ++i) {
    net.setInput(blob);
    Mat out = net.forward();
    numProcessed += !out.empty();
  }

  net.enableAsync(false);
  for (int i = numProcessed; i < numFrames; ++i) {
    Mat out = net.forward();
    CV_Assert(!out.empty());
  }
}

// Uncomment to test synchronous mode
{
  // for (int i = 0; i < numFrames; ++i) {
  //   net.setInput(blob);
  //   Mat out = net.forward();
  // }
}

tm.stop();

std::cout << "time: " << tm.getTimeMilli() << std::endl;
std::cout << "FPS: " << numFrames / tm.getTimeSec() << std::endl;

Postprocessing imitation:

TickMeter tm;
tm.start();

const int numFrames = 1000;  // 100 for human-pose-estimation-0001 on Myriad

// Uncomment to test asynchronous mode
{
  int numProcessed = 0;
  net.enableAsync(true);
  for (int i = 0; i < numFrames; ++i) {
    net.setInput(blob);
    Mat out = net.forward();
    if (!out.empty()) {
      usleep(10000);  // 10 milliseconds
      numProcessed += 1;
    }
  }

  net.enableAsync(false);
  for (int i = numProcessed; i < numFrames; ++i) {
    Mat out = net.forward();
    usleep(10000);
  }
}

// Uncomment to test synchronous mode
{
  // for (int i = 0; i < numFrames; ++i) {
  //   net.setInput(blob);
  //   Mat out = net.forward();
  //   usleep(10000);
  // }
}

tm.stop();
force_builders=Custom,Linux AVX2
buildworker:Custom=linux-2
docker_image:Custom=ubuntu-openvino-2019r1:16.04
test_opencl:Custom=ON
test_bigdata:Custom=1
test_filter:Custom=*
test_modules:Custom=dnn

ci_branch:Linux AVX2=no-checks
docker_image:Linux AVX2=ubuntu-openvino-2018r5:16.04
test_opencl:Linux AVX2=OFF
buildworker:Linux AVX2=linux-1
build_parallel_tests:Linux AVX2=1
test_bigdata:Linux AVX2=1
test_module:Linux AVX2=dnn,python2,python3,java
tests_filter:Linux AVX2=*

buildworker:Mac=macosx-1
build_image:Mac=openvino-2019r1

@dkurt dkurt changed the title Dnn ie async Asynchronous API from Intel's Inference Engine Jan 25, 2019
@lunalulu

This comment has been minimized.

@dkurt

This comment has been minimized.

@dkurt
dkurt force-pushed the dnn_ie_async branch 4 times, most recently from 3d856a4 to 5d8943f Compare February 7, 2019 07:47
@teng88

teng88 commented Feb 18, 2019

Copy link
Copy Markdown
Contributor

Any plans to merge this feature? @dkurt

@dkurt

dkurt commented Feb 18, 2019

Copy link
Copy Markdown
Member Author

@teng88, I guess we'll merge it this week. The only thing is that we wanted to finalize forwardAsync's output type. Do not add a class Future_Mat which actually was introduced for correct wrapping in Python and Java but fix each wrapper independently.

@dkurt
dkurt force-pushed the dnn_ie_async branch 4 times, most recently from 158679d to 6c8a5ad Compare March 5, 2019 05:35
@dkurt
dkurt force-pushed the dnn_ie_async branch 3 times, most recently from 7444825 to 55d78c0 Compare March 6, 2019 12:52
Comment thread modules/dnn/include/opencv2/dnn/dnn.hpp Resolved
Comment thread modules/dnn/include/opencv2/dnn/dnn.hpp Resolved
Comment thread modules/dnn/src/dnn.cpp Resolved
Comment thread modules/python/test/test_dnn.py Resolved
@dkurt
dkurt force-pushed the dnn_ie_async branch 6 times, most recently from 1301cce to 8a5cb59 Compare April 16, 2019 16:34
@dkurt

dkurt commented Apr 17, 2019 •

Copy link
Copy Markdown
Member Author

There is something wrong with OpenVINO models tests. Please do not merge.

log
[----------] 20 tests from DNNTestOpenVINO
[ RUN      ] DNNTestOpenVINO.models/0, where GetParam() = (CPU, "age-gender-recognition-retail-0013")
[       OK ] DNNTestOpenVINO.models/0 (109 ms)
[ RUN      ] DNNTestOpenVINO.models/1, where GetParam() = (CPU, "face-person-detection-retail-0002")
[       OK ] DNNTestOpenVINO.models/1 (756 ms)
[ RUN      ] DNNTestOpenVINO.models/2, where GetParam() = (CPU, "head-pose-estimation-adas-0001")
[       OK ] DNNTestOpenVINO.models/2 (127 ms)
[ RUN      ] DNNTestOpenVINO.models/3, where GetParam() = (CPU, "person-detection-retail-0002")
[       OK ] DNNTestOpenVINO.models/3 (810 ms)
[ RUN      ] DNNTestOpenVINO.models/4, where GetParam() = (CPU, "vehicle-detection-adas-0002")
[       OK ] DNNTestOpenVINO.models/4 (364 ms)
[ RUN      ] DNNTestOpenVINO.models/5, where GetParam() = (MYRIAD, "age-gender-recognition-retail-0013")
E: [ncAPI] [    721287] resetAll:348	 Failed to connect to stalled device, rc: X_LINK_ERROR
unknown file: Failure
C++ exception with description "OpenCV(3.4.6-dev) /build/precommit_custom_linux/3.4/opencv/modules/dnn/test/test_ie_models.cpp:197: error: (-215:Assertion failed) Failed to initialize Inference Engine backend: Can not init USB device: NC_ERROR in function 'runIE'
" thrown in the test body.
[  FAILED  ] DNNTestOpenVINO.models/5, where GetParam() = (MYRIAD, "age-gender-recognition-retail-0013") (7262 ms)
[ RUN      ] DNNTestOpenVINO.models/6, where GetParam() = (MYRIAD, "face-person-detection-retail-0002")
E: [ncAPI] [    728552] resetAll:348	 Failed to connect to stalled device, rc: X_LINK_ERROR
F: [xLink] [    735267] dispatcherResponseServe:320	no request for this response: XLINK_WRITE_RESP 1 0

#### (i == MAX_EVENTS) XLINK_WRITE_RESP 1 0
0) header->id 10, header->type XLINK_PING_REQ(5), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
1) header->id 11, header->type XLINK_CREATE_STREAM_REQ(3), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
2) header->id 12, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
3) header->id 13, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 1, EVENT_PENDING 1
4) header->id 14, header->type XLINK_READ_REQ(1), curr->lQueue.q[i].isServed 2, EVENT_PENDING 1
5) header->id 0, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
6) header->id 0, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
7) header->id 0, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
8) header->id 0, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
9) header->id 0, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
10) header->id 0, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
11) header->id 0, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
12) header->id 0, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
13) header->id 0, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
14) header->id 0, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
15) header->id 0, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
16) header->id 0, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
17) header->id 0, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
18) header->id 0, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
19) header->id 0, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
20) header->id 0, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
21) header->id 0, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
22) header->id 0, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
23) header->id 0, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
24) header->id 0, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
25) header->id 0, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
26) header->id 0, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
27) header->id 0, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
28) header->id 0, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
29) header->id 0, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
30) header->id 0, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
31) header->id 0, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
32) header->id 0, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
33) header->id 0, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
34) header->id 0, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
35) header->id 0, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
36) header->id 0, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
37) header->id 0, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
38) header->id 0, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
39) header->id 0, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
40) header->id 0, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
41) header->id 0, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
42) header->id 0, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
43) header->id 0, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
44) header->id 0, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
45) header->id 0, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
46) header->id 0, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
47) header->id 0, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
48) header->id 0, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
49) header->id 0, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
50) header->id 0, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
51) header->id 0, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
52) header->id 0, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
53) header->id 0, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
54) header->id 0, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
55) header->id 0, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
56) header->id 0, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
57) header->id 0, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
58) header->id 0, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
59) header->id 0, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
60) header->id 0, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
61) header->id 0, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
62) header->id 0, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
63) header->id 0, header->type XLINK_WRITE_REQ(0), curr->lQueue.q[i].isServed 4, EVENT_PENDING 1
E: [xLink] [    735381] dispatcherEventReceive:368	dispatcherEventReceive() Read failed -4 | event 0x7f489b7fd460 XLINK_WRITE_RESP

E: [xLink] [    735381] eventReader:230	eventReader stopped
E: [xLink] [    747267] dispatcherWaitEventComplete:709	waiting is timeout, sending reset remote event
E: [watchdog] [    759267] sendPingMessage:132	Failed send ping message: X_LINK_TIMEOUT
E: [xLink] [    759267] XLinkReadDataWithTimeOut:1377	E: [watchdog] [    759268] sendPingMessage:132	Failed send ping message: X_LINK_ERROR
E: [watchdog] [    759268] watchdog_routine:327	[0x36b270d0] device, not respond, removing from watchdog
Event data is invalid

E: [ncAPI] [    759268] getDevAttributes:929	Failed to read data, rc: X_LINK_ERROR
unknown file: Failure
C++ exception with description "OpenCV(3.4.6-dev) /build/precommit_custom_linux/3.4/opencv/modules/dnn/test/test_ie_models.cpp:197: error: (-215:Assertion failed) Failed to initialize Inference Engine backend: Can not init USB device: NC_ERROR in function 'runIE'
" thrown in the test body.
[  FAILED  ] DNNTestOpenVINO.models/6, where GetParam() = (MYRIAD, "face-person-detection-retail-0002") (30729 ms)
[ RUN      ] DNNTestOpenVINO.models/7, where GetParam() = (MYRIAD, "head-pose-estimation-adas-0001")
E: [xLink] [    760905] dispatcherEventReceive:368	dispatcherEventReceive() Read failed -4 | event 0x7f489a7fb460 XLINK_WRITE_RESP

E: [xLink] [    760905] eventReader:230	eventReader stopped
E: [xLink] [    760905] XLinkReadDataWithTimeOut:1377	Event data is invalid
E: [ncAPI] [    760905] checkGraphMonitorResponse:1635	XLink error, rc: X_LINK_ERROR
E: [ncAPI] [    760905] ncGraphAllocate:1757	can't receive graph header verification response
unknown file: Failure
C++ exception with description "OpenCV(3.4.6-dev) /build/precommit_custom_linux/3.4/opencv/modules/dnn/test/test_ie_models.cpp:197: error: (-215:Assertion failed) Failed to initialize Inference Engine backend: Failed to allocate graph: NC_ERROR in function 'runIE'
" thrown in the test body.
[  FAILED  ] DNNTestOpenVINO.models/7, where GetParam() = (MYRIAD, "head-pose-estimation-adas-0001") (1905 ms)
[ RUN      ] DNNTestOpenVINO.models/8, where GetParam() = (MYRIAD, "person-detection-retail-0002")
[       OK ] DNNTestOpenVINO.models/8 (4430 ms)
[ RUN      ] DNNTestOpenVINO.models/9, where GetParam() = (MYRIAD, "vehicle-detection-adas-0002")
[       OK ] DNNTestOpenVINO.models/9 (4216 ms)
[ RUN      ] DNNTestOpenVINO.models/10, where GetParam() = (OCL, "age-gender-recognition-retail-0013")
[       OK ] DNNTestOpenVINO.models/10 (2148 ms)

Update: Fixed that

Comment thread modules/dnn/src/op_inf_engine.hpp Resolved
Comment thread modules/dnn/src/op_inf_engine.cpp Resolved

@alalek alalek left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done 👍

@alalek
alalek merged commit a5c92c2 into opencv:3.4 Apr 19, 2019
@alalek alalek mentioned this pull request Apr 22, 2019
@dkurt
dkurt deleted the dnn_ie_async branch May 6, 2019 05:49
SavyaSanchi-Sharma pushed a commit to SavyaSanchi-Sharma/opencv that referenced this pull request Jul 30, 2026
Asynchronous API from Intel's Inference Engine (opencv#13694)

* Add forwardAsync for asynchronous mode from Intel's Inference Engine

* Python test for forwardAsync

* Replace Future_Mat to AsyncMat

* Shadow AsyncMat

* Isolate InferRequest callback

* Manage exceptions in Async API of IE
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.

4 participants