Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

cv2.dnn.readNetFromTensorflow returns errors when loading .pb and .pbtxt files

I have created an Enet in Keras (with two custom layers which are MaxPooling2DWithArgmax and MaxUnpooling2D), i have also ported the keras model (using the custom_objects argument in model.load_model( ) function ) to tensorflow to generate the .pb as well as.pbtxt files. Now, when i load these files into cv2.readNetFromTensorflow it throws me the following error.

error: OpenCV(3.4.3) C:\projects\opencv-python\opencv\modules\dnn\src\tensorflow\tf_importer.cpp:614: error: (-215:Assertion failed) const_layers.insert(std::make_pair(name, li)).second in function 'cv::dnn::experimental_dnn_34_v7::`anonymous-namespace'::addConstNodes'

When i load just the .pb file into the function, it throws me different error which is shown below.

error: OpenCV(3.4.3) C:\projects\opencv-python\opencv\modules\dnn\src\tensorflow\tf_importer.cpp:495: error: (-2:Unspecified error) Input layer not found: zero_padding2d_10/Pad in function 'cv::dnn::experimental_dnn_34_v7::`anonymous-namespace'::TFImporter::connect'

PS: i have tried with the latest version OpenCv(4.0) as well, still the same issues.

click to hide/show revision 2
retagged

updated 2019-02-14 02:33:15 -0600

berak gravatar image

cv2.dnn.readNetFromTensorflow returns errors when loading .pb and .pbtxt files

I have created an Enet in Keras (with two custom layers which are MaxPooling2DWithArgmax and MaxUnpooling2D), i have also ported the keras model (using the custom_objects argument in model.load_model( ) function ) to tensorflow to generate the .pb as well as.pbtxt files. Now, when i load these files into cv2.readNetFromTensorflow it throws me the following error.

error: OpenCV(3.4.3) C:\projects\opencv-python\opencv\modules\dnn\src\tensorflow\tf_importer.cpp:614: error: (-215:Assertion failed) const_layers.insert(std::make_pair(name, li)).second in function 'cv::dnn::experimental_dnn_34_v7::`anonymous-namespace'::addConstNodes'

When i load just the .pb file into the function, it throws me different error which is shown below.

error: OpenCV(3.4.3) C:\projects\opencv-python\opencv\modules\dnn\src\tensorflow\tf_importer.cpp:495: error: (-2:Unspecified error) Input layer not found: zero_padding2d_10/Pad in function 'cv::dnn::experimental_dnn_34_v7::`anonymous-namespace'::TFImporter::connect'

PS: i have tried with the latest version OpenCv(4.0) as well, still the same issues.