Ask Your Question
0

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

asked 2019-05-06 00:28:42 -0500

Pawan gravatar image

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);
net.setInput(inputBlob);

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 = outs.at(i);
   for (size_t j = 0; j < o.size(); j++)
   {
      cv::Mat blob = o.at(j);
      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

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2019-05-06 00:36:41 -0500

dkurt gravatar image

There is no cols and rows for cv::Mat with number of dimensions >2 (source). Check blob.size[0], blob.size[1] and blob.size[2] instead.

edit flag offensive delete link more

Comments

thanks was able to parse network output using this information.

Pawan gravatar imagePawan ( 2019-05-06 02:17:09 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2019-05-06 00:28:42 -0500

Seen: 147 times

Last updated: May 06