Emgu crash when running Net in parallel

19 Views Asked by At

Trying to run multiple DNNs in parallel on ROIs of the same image mat, I get this error

System.AggregateException: One or more errors occurred. ---> Emgu.CV.Util.CvException: OpenCV: mapIt != reuseMap.end()

Stack Trace:  CvInvoke.CvErrorHandler(Int32 status, IntPtr funcName, IntPtr errMsg, IntPtr fileName, Int32 line, IntPtr userData) DnnInvoke.cveDnnNetForward(IntPtr net, IntPtr outputName, IntPtr output) Net.Forward(String outputName)

Basically I do this:

Parallel.For(0, 2, i =>
{
   Net net = ... (load from file)...
   using (Mat inputblob = DnnInvoke.BlobFromImage(GetRoi(i), 1.0, new Size(netImgSize, 
         netImgSize), new MCvScalar(0, 0, 0), false, false, DepthType.Cv32F))
   {
      net.SetInput(inputBlob);
      Mat detections = net.Forward();
   }
}

From google I get the impression that Emgu should be thread safe. But to be sure, each thread gets its own Net.

The code works, if I do not run it in parallel.

Does anybody know what the error means?

0

There are 0 best solutions below