1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-31 08:13:04 +04:00

Merge pull request #14440 from alalek:async_array

This commit is contained in:
Alexander Alekhin
2019-06-08 20:57:15 +00:00
23 changed files with 944 additions and 145 deletions
+3 -3
View File
@@ -2557,7 +2557,7 @@ struct Net::Impl
}
#ifdef CV_CXX11
std::future<Mat> getBlobAsync(const LayerPin& pin)
AsyncArray getBlobAsync(const LayerPin& pin)
{
CV_TRACE_FUNCTION();
#ifdef HAVE_INF_ENGINE
@@ -2586,7 +2586,7 @@ struct Net::Impl
#endif
}
std::future<Mat> getBlobAsync(String outputName)
AsyncArray getBlobAsync(String outputName)
{
return getBlobAsync(getPinByAlias(outputName));
}
@@ -2714,7 +2714,7 @@ Mat Net::forward(const String& outputName)
return impl->getBlob(layerName);
}
AsyncMat Net::forwardAsync(const String& outputName)
AsyncArray Net::forwardAsync(const String& outputName)
{
CV_TRACE_FUNCTION();
#ifdef CV_CXX11
+28 -10
View File
@@ -849,7 +849,7 @@ void InfEngineBackendNet::InfEngineReqWrapper::makePromises(const std::vector<Pt
outsNames.resize(outs.size());
for (int i = 0; i < outs.size(); ++i)
{
outs[i]->futureMat = outProms[i].get_future();
outs[i]->futureMat = outProms[i].getArrayResult();
outsNames[i] = outs[i]->dataPtr->name;
}
}
@@ -906,20 +906,38 @@ void InfEngineBackendNet::forward(const std::vector<Ptr<BackendWrapper> >& outBl
{
InfEngineReqWrapper* wrapper;
request->GetUserData((void**)&wrapper, 0);
CV_Assert(wrapper);
CV_Assert(wrapper && "Internal error");
for (int i = 0; i < wrapper->outProms.size(); ++i)
size_t processedOutputs = 0;
try
{
const std::string& name = wrapper->outsNames[i];
Mat m = infEngineBlobToMat(wrapper->req.GetBlob(name));
for (; processedOutputs < wrapper->outProms.size(); ++processedOutputs)
{
const std::string& name = wrapper->outsNames[processedOutputs];
Mat m = infEngineBlobToMat(wrapper->req.GetBlob(name));
if (status == InferenceEngine::StatusCode::OK)
wrapper->outProms[i].set_value(m.clone());
else
try
{
CV_Assert(status == InferenceEngine::StatusCode::OK);
wrapper->outProms[processedOutputs].setValue(m.clone());
}
catch (...)
{
try {
wrapper->outProms[processedOutputs].setException(std::current_exception());
} catch(...) {
CV_LOG_ERROR(NULL, "DNN: Exception occured during async inference exception propagation");
}
}
}
}
catch (...)
{
std::exception_ptr e = std::current_exception();
for (; processedOutputs < wrapper->outProms.size(); ++processedOutputs)
{
try {
std::runtime_error e("Async request failed");
wrapper->outProms[i].set_exception(std::make_exception_ptr(e));
wrapper->outProms[processedOutputs].setException(e);
} catch(...) {
CV_LOG_ERROR(NULL, "DNN: Exception occured during async inference exception propagation");
}
+5 -2
View File
@@ -12,6 +12,9 @@
#include "opencv2/core/cvstd.hpp"
#include "opencv2/dnn.hpp"
#include "opencv2/core/async.hpp"
#include "opencv2/core/detail/async_promise.hpp"
#include "opencv2/dnn/utils/inference_engine.hpp"
#ifdef HAVE_INF_ENGINE
@@ -208,7 +211,7 @@ private:
void makePromises(const std::vector<Ptr<BackendWrapper> >& outs);
InferenceEngine::InferRequest req;
std::vector<std::promise<Mat> > outProms;
std::vector<cv::AsyncPromise> outProms;
std::vector<std::string> outsNames;
bool isReady;
};
@@ -264,7 +267,7 @@ public:
InferenceEngine::DataPtr dataPtr;
InferenceEngine::Blob::Ptr blob;
std::future<Mat> futureMat;
AsyncArray futureMat;
};
InferenceEngine::Blob::Ptr wrapToInfEngineBlob(const Mat& m, InferenceEngine::Layout layout = InferenceEngine::Layout::ANY);