1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-30 15:53:03 +04:00

dnn: use AsyncArray

This commit is contained in:
Alexander Alekhin
2019-05-01 11:51:12 +00:00
parent 9340af1a8a
commit 132253c9f3
10 changed files with 66 additions and 124 deletions
+12 -10
View File
@@ -341,12 +341,13 @@ TEST(Net, forwardAndRetrieve)
}
#ifdef HAVE_INF_ENGINE
static const std::chrono::milliseconds async_timeout(500);
// This test runs network in synchronous mode for different inputs and then
// runs the same model asynchronously for the same inputs.
typedef testing::TestWithParam<tuple<int, Target> > Async;
TEST_P(Async, set_and_forward_single)
{
static const int kTimeout = 5000; // in milliseconds.
const int dtype = get<0>(GetParam());
const int target = get<1>(GetParam());
@@ -383,16 +384,16 @@ TEST_P(Async, set_and_forward_single)
{
netAsync.setInput(inputs[i]);
std::future<Mat> out = netAsync.forwardAsync();
if (out.wait_for(std::chrono::milliseconds(kTimeout)) == std::future_status::timeout)
CV_Error(Error::StsAssert, "Timeout");
normAssert(refs[i], out.get(), format("Index: %d", i).c_str(), 0, 0);
AsyncArray out = netAsync.forwardAsync();
ASSERT_TRUE(out.valid());
Mat result;
EXPECT_TRUE(out.get(result, async_timeout));
normAssert(refs[i], result, format("Index: %d", i).c_str(), 0, 0);
}
}
TEST_P(Async, set_and_forward_all)
{
static const int kTimeout = 5000; // in milliseconds.
const int dtype = get<0>(GetParam());
const int target = get<1>(GetParam());
@@ -426,7 +427,7 @@ TEST_P(Async, set_and_forward_all)
}
// Run asynchronously. To make test more robust, process inputs in the reversed order.
std::vector<std::future<Mat> > outs(numInputs);
std::vector<AsyncArray> outs(numInputs);
for (int i = numInputs - 1; i >= 0; --i)
{
netAsync.setInput(inputs[i]);
@@ -435,9 +436,10 @@ TEST_P(Async, set_and_forward_all)
for (int i = numInputs - 1; i >= 0; --i)
{
if (outs[i].wait_for(std::chrono::milliseconds(kTimeout)) == std::future_status::timeout)
CV_Error(Error::StsAssert, "Timeout");
normAssert(refs[i], outs[i].get(), format("Index: %d", i).c_str(), 0, 0);
ASSERT_TRUE(outs[i].valid());
Mat result;
EXPECT_TRUE(outs[i].get(result, async_timeout));
normAssert(refs[i], result, format("Index: %d", i).c_str(), 0, 0);
}
}