Skip to content

reshape - pass trough layer in Tensorflow .pb file error #20433

@benedetto-michelozzi

Description

@benedetto-michelozzi

reshape_1
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.
The network, trained using TensorFlow 1.14 + Keras, and saved as a .pb file, runs correctly in inference using TensorFLow
Therefore the .pb file is correct.

Network structure: the involved part of the network, as from the .pb file, is summrized 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

OpenCV layer list: the layers list as reported by OpenCV contains the following rows, that should correspond to that of the previous section:
add_3/add
reshape_1/Reshape/nhwc
reshape_1/Reshape
reshape_1/Reshape/nchw

Errors: the errors are summarized as follows:
[ERROR:8] global D:\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:\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 of the ConcatLayer operation ( concatenate_1/concat ) 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 896 52 52 ]

then, the concatenate_1/concat operation generates the error

the problems is probably correlated to an erroneous nchw - nhwc handling

Output layers: the output layers reported by OpenCV are
reshape_1/Reshape/nchw
conv2d_25/convolution

but only the second ( conv2d_25/convolution ) should be the output layer, the other ( reshape_1/Reshape/nchw ) is probably the one that generates the problem

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions