dnn: use AsyncArray
This commit is contained in:
@@ -2,13 +2,6 @@
|
||||
typedef dnn::DictValue LayerId;
|
||||
typedef std::vector<dnn::MatShape> vector_MatShape;
|
||||
typedef std::vector<std::vector<dnn::MatShape> > vector_vector_MatShape;
|
||||
#ifdef CV_CXX11
|
||||
typedef std::chrono::milliseconds chrono_milliseconds;
|
||||
typedef std::future_status AsyncMatStatus;
|
||||
#else
|
||||
typedef size_t chrono_milliseconds;
|
||||
typedef size_t AsyncMatStatus;
|
||||
#endif
|
||||
|
||||
template<>
|
||||
bool pyopencv_to(PyObject *o, dnn::DictValue &dv, const char *name)
|
||||
@@ -46,46 +39,6 @@ bool pyopencv_to(PyObject *o, std::vector<Mat> &blobs, const char *name) //requi
|
||||
return pyopencvVecConverter<Mat>::to(o, blobs, ArgInfo(name, false));
|
||||
}
|
||||
|
||||
#ifdef CV_CXX11
|
||||
|
||||
template<>
|
||||
PyObject* pyopencv_from(const std::future<Mat>& f_)
|
||||
{
|
||||
std::future<Mat>& f = const_cast<std::future<Mat>&>(f_);
|
||||
Ptr<cv::dnn::AsyncMat> p(new std::future<Mat>(std::move(f)));
|
||||
return pyopencv_from(p);
|
||||
}
|
||||
|
||||
template<>
|
||||
PyObject* pyopencv_from(const std::future_status& status)
|
||||
{
|
||||
return pyopencv_from((int)status);
|
||||
}
|
||||
|
||||
template<>
|
||||
bool pyopencv_to(PyObject* src, std::chrono::milliseconds& dst, const char* name)
|
||||
{
|
||||
size_t millis = 0;
|
||||
if (pyopencv_to(src, millis, name))
|
||||
{
|
||||
dst = std::chrono::milliseconds(millis);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
template<>
|
||||
PyObject* pyopencv_from(const cv::dnn::AsyncMat&)
|
||||
{
|
||||
CV_Error(Error::StsNotImplemented, "C++11 is required.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif // CV_CXX11
|
||||
|
||||
template<typename T>
|
||||
PyObject* pyopencv_from(const dnn::DictValue &dv)
|
||||
{
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
#error This is a shadow header file, which is not intended for processing by any compiler. \
|
||||
Only bindings parser should handle this file.
|
||||
|
||||
namespace cv { namespace dnn {
|
||||
|
||||
class CV_EXPORTS_W AsyncMat
|
||||
{
|
||||
public:
|
||||
//! Wait for Mat object readiness and return it.
|
||||
CV_WRAP Mat get();
|
||||
|
||||
//! Wait for Mat object readiness.
|
||||
CV_WRAP void wait() const;
|
||||
|
||||
/** @brief Wait for Mat object readiness specific amount of time.
|
||||
* @param timeout Timeout in milliseconds
|
||||
* @returns [std::future_status](https://en.cppreference.com/w/cpp/thread/future_status)
|
||||
*/
|
||||
CV_WRAP AsyncMatStatus wait_for(std::chrono::milliseconds timeout) const;
|
||||
};
|
||||
|
||||
}}
|
||||
@@ -69,8 +69,9 @@ def printParams(backend, target):
|
||||
|
||||
class dnn_test(NewOpenCVTests):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(dnn_test, self).__init__(*args, **kwargs)
|
||||
def setUp(self):
|
||||
super(dnn_test, self).setUp()
|
||||
|
||||
self.dnnBackendsAndTargets = [
|
||||
[cv.dnn.DNN_BACKEND_OPENCV, cv.dnn.DNN_TARGET_CPU],
|
||||
]
|
||||
@@ -168,7 +169,7 @@ class dnn_test(NewOpenCVTests):
|
||||
normAssertDetections(self, ref, out, 0.5, scoresDiff, iouDiff)
|
||||
|
||||
def test_async(self):
|
||||
timeout = 5000 # in milliseconds
|
||||
timeout = 500*10**6 # in nanoseconds (500ms)
|
||||
testdata_required = bool(os.environ.get('OPENCV_DNN_TEST_REQUIRE_TESTDATA', False))
|
||||
proto = self.find_dnn_file('dnn/layers/layer_convolution.prototxt', required=testdata_required)
|
||||
model = self.find_dnn_file('dnn/layers/layer_convolution.caffemodel', required=testdata_required)
|
||||
@@ -209,11 +210,9 @@ class dnn_test(NewOpenCVTests):
|
||||
outs.insert(0, netAsync.forwardAsync())
|
||||
|
||||
for i in reversed(range(numInputs)):
|
||||
ret = outs[i].wait_for(timeout)
|
||||
if ret == 1:
|
||||
self.fail("Timeout")
|
||||
self.assertEqual(ret, 0) # is ready
|
||||
normAssert(self, refs[i], outs[i].get(), 'Index: %d' % i, 1e-10)
|
||||
ret, result = outs[i].get(timeoutNs=float(timeout))
|
||||
self.assertTrue(ret)
|
||||
normAssert(self, refs[i], result, 'Index: %d' % i, 1e-10)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Reference in New Issue
Block a user