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:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user