Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to process output of detection network when batch of images is used as network input

I have a yolov3 network trained on custom dataset and i am using opencv's dnn module for inference. Up until now i was passing a single image to the network for inference and was able to get detection outputs using code from opencv dnn detection sample.

But now i want to process a batch of images at a time so i change the code to use cv::dnn::blobFromImages for creating network input blob and forward it through the network and it works fine.

cv::Mat inputBlob = cv::dnn::blobFromImages(input_images_vec, scalefactor, netInputSize, meanToSubtract, swapRB, crop);

std::vector<std::vector<cv::Mat>> outs;
net.forward(outs, outNames);

Now i am unable to process the output of the network to get detections from it because in case of batch size > 1 the rows and cols of output are -1, -1 and the output processing code needs to know rows and cols.

std::cout << "Input blob size: " << std::endl;
std::cout << inputBlob.size << std::endl;
for (size_t i = 0; i < outs.size(); i++)
   std::vector<cv::Mat> o =;
   for (size_t j = 0; j < o.size(); j++)
      cv::Mat blob =;
      std::cout << "blob size: " << blob.size << std::endl;
      std::cout << "dims: " << blob.size.dims() << std::endl;
      std::cout << "rows: " << blob.rows << " cols: " << blob.cols << " channels: " << blob.channels() << std::endl;

when batch size is 1

when batch size is one

when batch size is 2

when batch size is 2