Issue 1:
System information (version)

OpenCV => 4.1.1

Operating System / Platform => Linux

Compiler => gcc/g++

Detailed description

I'm trying to load the pretrained DeepLabv3+ xception_65 model available from Tensorflow repository using OpenCV DNN C++. It throws the following error:

terminate called after throwing an instance of 'cv::Exception'
what(): OpenCV(4.1.1) /content/opencv-4.1.1/modules/dnn/src/tensorflow/tf_importer.cpp:544: error: (-2:Unspecified error) Input layer not found: Shape_4 in function 'connect'

Steps to reproduce

#include <opencv2/opencv.hpp>
#include <opencv2/dnn.hpp>
#include "iostream"

#include <opencv2/dnn/layer.details.hpp> // CV_DNN_REGISTER_LAYER_CLASS

using namespace cv;
using namespace cv::dnn;

int main()
{
// Original frozen model
//std::string model = "deeplabv3_cityscapes_train/frozen_inference_graph.pb";

// Read image
cv::Mat imgOrig = cv::imread("000001.png", cv::IMREAD_COLOR);
imgOrig.convertTo(imgOrig, CV_8UC3);

// Resize image
cv::Mat img;
cv::resize(imgOrig, img, cv::Size(513, 513));

// Read model
cv::dnn::Net graph = cv::dnn::readNetFromTensorflow(model);

// Get blob from image
cv::Mat blob = cv::dnn::blobFromImage(img, 4.0, cv::Size(513, 513), cv::Scalar(), true, false);

// Set the input tensor
std::string inBlobName = "ImageTensor";
graph.setInput(blob, inBlobName);

cv::Mat detectionOut = graph.forward();

std::cout << "Worked fine!";

return 0;
}

Even when I use pbtxt file as well while loading model by

cv::dnn::Net graph = cv::dnn::readNetFromTensorflow(model, pbtxt_file); created using

# Read the graph.
with tf.gfile.FastGFile('deeplabv3_cityscapes_train/frozen_inference_graph.pb', 'rb') as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())

# Remove Const nodes.
for i in reversed(range(len(graph_def.node))):
if graph_def.node[i].op == 'Const':
del graph_def.node[i]

for attr in ['T', 'data_format', 'Tshape', 'N', 'Tidx', 'Tdim',
'use_cudnn_on_gpu', 'Index', 'Tperm', 'is_training',
'Tpaddings']:
if attr in graph_def.node[i].attr:
del graph_def.node[i].attr[attr]

# Save as text.
tf.train.write_graph(graph_def, "", "frozen_inference_graph.pbtxt", as_text=True)

the error is same.

Issue 2:
System information (version)

OpenCV => 4.0

Operating System / Platform => Ubuntu 16.04

Compiler => cmake

Tensorflow => 1.13.1

Python => 3.5

protobuf => 3.6.1

Detailed description

terminate called after throwing an instance of 'cv::Exception' what(): OpenCV(4.0.0) /home/cas/work/opencv-4.0.0/modules/dnn/src/tensorflow/tf_importer.cpp:1155: error: (-213:The function/feature is not implemented) Unsupported squeeze configuration in function 'populateNet'

Steps to reproduce

when i run the codes below, above problem occurred:

#include <string>
#include <iostream>
#include <fstream>
#include <opencv2/opencv.hpp>
#include <opencv2/dnn.hpp>
#include <opencv2/dnn/dnn.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/core/utils/filesystem.hpp>
using namespace std;
using namespace cv;
int main()
{
cv::Mat src;
src = imread("/home/cas/work/readpb_opencv/src/opencv_pb/test_image/33.jpg");
string weights = "/home/cas/work/readpb_opencv/src/opencv_pb/model/step13000.pb";
string prototxt = "/home/cas/work/readpb_opencv/src/opencv_pb/model/step13000_graph.pbtxt";
dnn::Net net = cv::dnn::readNetFromTensorflow(weights, prototxt);
cv::Mat blob = cv::dnn::blobFromImage(src,1.0,cv::Size(640, 480),cv::Scalar(),true,false,CV_8U);
net.setInput(blob);
Mat output = net.forward();
imshow("result",output);
waitKey(0);
return 0;
}

the way i get the 'step13000_graph.pbtxt' is :

import tensorflow as tf
# Read the graph.
with tf.gfile.FastGFile('/home/cas/work/readpb_opencv/src/opencv_pb/model/step13000.pb','rb') as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
# Remove Const nodes.
for i in reversed(range(len(graph_def.node))):
if graph_def.node[i].op == 'Const':
del graph_def.node[i]
for attr in ['T', 'data_format', 'Tshape', 'N', 'Tidx', 'Tdim',
'use_cudnn_on_gpu', 'Index', 'Tperm', 'is_training',
'Tpaddings']:
if attr in graph_def.node[i].attr:
del graph_def.node[i].attr[attr]
# Save as text.
tf.train.write_graph(graph_def, "", "/home/cas/work/readpb_opencv/src/opencv_pb/model/step13000_graph.pbtxt", as_text=True)

Any help in resolving this would be greatly appreciated. Thanks !