# Batch forward onnx model

**URL:** <https://forum.opencv.org/t/batch-forward-onnx-model/19371>\
**Category:** C++\
**Tags:** dnn\
**Created:** [November 25, 2024, 2:34pm UTC](https://forum.opencv.org/t/batch-forward-onnx-model/19371 "2024-11-25T14:34:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ella\_Mendelson](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/ella_mendelson/32/11549_2.png) [@Ella\_Mendelson](https://forum.opencv.org/u/Ella_Mendelson)\
**Post date:** [November 25, 2024, 2:34pm UTC](https://forum.opencv.org/t/batch-forward-onnx-model/19371/1 "2024-11-25T14:34:41Z")

</div>

Hello,  
I’m running YOLO model on CPP code using opencv::dnn.

when forwarding single image using the code -

```
vector<Mat> pre_process(cv::Mat input_image)
{
	// Convert to blob.
	Mat blob;
	dnn::blobFromImage(input_image, blob, 1.0 / 255, Size(INPUT_WIDTH, INPUT_HEIGHT), Scalar(), true, false);
	net.setInput(blob);
	// Forward propagate.
	vector<Mat> outputs;
	net.forward(outputs, net.getUnconnectedOutLayersNames());
	return outputs;

}

```

it works perfectly fine.  
However, when trying to forward multiple images in a batch, using the code

```
vector <vector<Mat>> pre_process(vector <cv::Mat> input_images)
{
	// Convert to blob.
	Mat blob;
	dnn::blobFromImages(input_images, blob, 1.0 / 255, Size(INPUT_WIDTH, INPUT_HEIGHT), Scalar(), true, false);
	net.setInput(blob);
	// Forward propagate.
	vector <vector<Mat>> AllOutputs;
	net.forward(AllOutputs, net.getUnconnectedOutLayersNames());
	return AllOutputs;
}

```

I get the following error:

[ERROR:0@8.011] global net\_impl.cpp:1165 cv::dnn::dnn4\_v20240521::Net::Impl::getLayerShapesRecursively OPENCV/DNN: [Permute]:(onnx\_node!/model.24/Transpose): getMemoryShapes() throws exception. inputs=1 outputs=0/1 blobs=0

[ERROR:0@8.012] global net\_impl.cpp:1168 cv::dnn::dnn4\_v20240521::Net::Impl::getLayerShapesRecursively input[0] = [135 1 3 7 80 80]

[ERROR:0@8.012] global net\_impl.cpp:1178 cv::dnn::dnn4\_v20240521::Net::Impl::getLayerShapesRecursively Exception message: OpenCV(4.10.0) C:\opencv\opencv-4.10.0\modules\dnn\src\layers\permute\_layer.cpp:162: error: (-215:Assertion failed) (int)\_numAxes == inputs[0].size() in function ‘cv::dnn::PermuteLayerImpl::getMemoryShapes’

any idea how to process multiple images as a batch?

thanks 🙂

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [November 25, 2024, 10:33pm UTC](https://forum.opencv.org/t/batch-forward-onnx-model/19371/2 "2024-11-25T22:33:57Z")

</div>

are they all the same size and such?

---

<div class="post-metadata">

**Author:** ![Ella\_Mendelson](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/ella_mendelson/32/11549_2.png) [@Ella\_Mendelson](https://forum.opencv.org/u/Ella_Mendelson)\
**Post date:** [November 26, 2024, 8:28am UTC](https://forum.opencv.org/t/batch-forward-onnx-model/19371/3 "2024-11-26T08:28:44Z")

</div>

sure. all the same size
