# Reshape - pass trough layer error

**URL:** <https://forum.opencv.org/t/reshape-pass-trough-layer-error/4407>\
**Category:** C++\
**Tags:** dnn\
**Created:** [July 20, 2021, 7:13am UTC](https://forum.opencv.org/t/reshape-pass-trough-layer-error/4407 "2021-07-20T07:13:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![benedetto\_michelozzi](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/benedetto_michelozzi/32/2670_2.png) [@benedetto\_michelozzi](https://forum.opencv.org/u/benedetto_michelozzi)\
**Post date:** [July 20, 2021, 7:13am UTC](https://forum.opencv.org/t/reshape-pass-trough-layer-error/4407/1 "2021-07-20T07:13:19Z")

</div>

**Foreword** : OpenCV 4.5.3 + CUDA 10.0, Windows 10, C++, weights (.pb) generated using Tensorflow 1.14

**Problem:** When i try to run a custom network in which i inserted a reshape - pass trough layer some errors are issued and the inference is not performed.  
The network is essentially an YoloV3 with some modifications and a single output layer.

**Network structure:** the involved part of the network has the structure  
 ![reshape_1](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/0/0255e19c5a0101eb09b56cfb29c47bc676ea7d06.png)  
summarized as follows:

input = add\_3/add

op: Shape  
input = add\_3/add  
output =reshape\_1/Shape

op: StridedSlice  
input =reshape\_1/Shape  
inputs ( const ) = reshape\_1/strided\_slice/stack, reshape\_1/strided\_slice/stack\_1, reshape\_1/strided\_slice/stack\_2  
output = reshape\_1/strided\_slice

op: Pack  
input = reshape\_1/strided\_slice  
inputs ( const ) = reshape\_1/Reshape/shape/1 ( value 52 ), reshape\_1/Reshape/shape/2 (value 52 ), reshape\_1/Reshape/shape/3 (value 512 )  
output = reshape\_1/Reshape/shape

op: Reshape  
input = add\_3/add  
input = reshape\_1/Reshape/shape  
output = reshape\_1/Reshape

The output goes to a  
ConcatV2 operation

**Errors:** the errors are summarized as follows:  
[ERROR:8] global D:\Flyby\OpenSIGHT-3rdParty\OpenCV\opencv-4.5.3\modules\dnn\src\dnn.cpp (3512) cv::dnn::dnn4\_v20210608::Net::Impl::getLayerShapesRecursively  
OPENCV/DNN: [Concat]:(concatenate\_1/concat): getMemoryShapes() throws exception. inputs=3 outputs=1/1 blobs=0  
input[0] = [1 128 52 52]  
input[1] = [1 256 52 52]  
input[2] = [1 52 52 512]  
output[0] = [1 128 52 52]  
Exception message: OpenCV(4.5.3) D:\Flyby\OpenSIGHT-3rdParty\OpenCV\opencv-4.5.3\modules\dnn\src\layers\concat\_layer.cpp:102:  
error: (-201:Incorrect size of input array) Inconsistent shape for ConcatLayer in function ‘cv::dnn::ConcatLayerImpl::getMemoryShapes’

**Observation** : it seems that an input layer of the Pack operation has a wrong dimensions order  
it is  
input[2] = [1 52 52 512]  
it should be ( i suppose )  
input[2] = [1 512 52 52]

the output then should be  
output[0] = [1 128 52 52]

then, the ConcatV2 operation generates the error

---

<div class="post-metadata">

**Author:** ![benedetto\_michelozzi](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/benedetto_michelozzi/32/2670_2.png) [@benedetto\_michelozzi](https://forum.opencv.org/u/benedetto_michelozzi)\
**Post date:** [July 23, 2021, 2:22pm UTC](https://forum.opencv.org/t/reshape-pass-trough-layer-error/4407/2 "2021-07-23T14:22:56Z")

</div>

The correct output of the operation should be  
output[0] = [1 896 52 52]

( not [1 128 52 52], that is generated because the concat operation has been interrupted )
