<h5 dir="auto">System information (version)</h5>
<ul dir="auto">
<li>OpenCV =&gt; 4.1.1</li>
<li>Operating System / Platform =&gt; Linux</li>
<li>Compiler =&gt; gcc/g++</li>
</ul>
<h5 dir="auto">Detailed description</h5>

<p dir="auto">I'm trying to load the pretrained <a href="http://download.tensorflow.org/models/deeplabv3_cityscapes_train_2018_02_06.tar.gz" rel="nofollow">DeepLabv3+ xception_65 model</a> available from <a href="https://github.com/tensorflow/models/blob/master/research/deeplab/g3doc/model_zoo.md#deeplab-models-trained-on-cityscapes">Tensorflow repository</a> using OpenCV DNN C++. It throws the following error:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="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'"><pre class="notranslate"><code class="notranslate">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'
</code></pre></div>
<h5 dir="auto">Steps to reproduce</h5>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="#include &lt;opencv2/opencv.hpp&gt;
#include &lt;opencv2/dnn.hpp&gt;
#include &quot;iostream&quot;

#include &lt;opencv2/dnn/layer.details.hpp&gt;  // CV_DNN_REGISTER_LAYER_CLASS

using namespace cv;
using namespace cv::dnn;

int main()
{
    // Original frozen model
    //std::string model = &quot;deeplabv3_cityscapes_train/frozen_inference_graph.pb&quot;;
    	
    // Read image
    cv::Mat imgOrig = cv::imread(&quot;000001.png&quot;, 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 = &quot;ImageTensor&quot;;
    graph.setInput(blob, inBlobName);

    cv::Mat detectionOut = graph.forward();
    
    std::cout &lt;&lt; &quot;Worked fine!&quot;;
   
    return 0;
}"><pre class="notranslate"><code class="notranslate">#include &lt;opencv2/opencv.hpp&gt;
#include &lt;opencv2/dnn.hpp&gt;
#include "iostream"

#include &lt;opencv2/dnn/layer.details.hpp&gt;  // 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 &lt;&lt; "Worked fine!";
   
    return 0;
}
</code></pre></div>
<hr>
<p dir="auto">Even when I use <a href="https://drive.google.com/drive/folders/1B83G3uA-OP18j0Rr9so343gSBbxaio5x?usp=sharing" rel="nofollow"><code class="notranslate">pbtxt</code></a> file as well while loading model by<br>
<code class="notranslate">cv::dnn::Net graph = cv::dnn::readNetFromTensorflow(model, pbtxt_file);</code> created using</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="# 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, &quot;&quot;, &quot;frozen_inference_graph.pbtxt&quot;, as_text=True)"><pre class="notranslate"><code class="notranslate"># 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)
</code></pre></div>
<p dir="auto">the error is same.</p>
<h5 dir="auto">System information (version)</h5>
<ul dir="auto">
<li>OpenCV =&gt; 4.0</li>
<li>Operating System / Platform =&gt; Ubuntu 16.04</li>
<li>Compiler =&gt; cmake</li>
<li>Tensorflow =&gt; 1.13.1</li>
<li>Python =&gt; 3.5</li>
<li>protobuf =&gt; 3.6.1</li>
</ul>
<h5 dir="auto">Detailed description</h5>
<p dir="auto">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'</p>
<h5 dir="auto">Steps to reproduce</h5>
<p dir="auto">when i run the codes below, above problem occurred:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="#include &lt;string&gt;
#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;opencv2/opencv.hpp&gt;
#include &lt;opencv2/dnn.hpp&gt;
#include &lt;opencv2/dnn/dnn.hpp&gt;
#include &lt;opencv2/imgproc.hpp&gt;
#include &lt;opencv2/highgui.hpp&gt;
#include &lt;opencv2/core/utils/filesystem.hpp&gt;
using namespace std;
using namespace cv;
int main()
{
  cv::Mat src;
  src = imread(&quot;/home/cas/work/readpb_opencv/src/opencv_pb/test_image/33.jpg&quot;);
  string weights = &quot;/home/cas/work/readpb_opencv/src/opencv_pb/model/step13000.pb&quot;;
  string prototxt = &quot;/home/cas/work/readpb_opencv/src/opencv_pb/model/step13000_graph.pbtxt&quot;;
  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(&quot;result&quot;,output);
  waitKey(0);
  return 0;
}"><pre class="notranslate"><code class="notranslate">#include &lt;string&gt;
#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;opencv2/opencv.hpp&gt;
#include &lt;opencv2/dnn.hpp&gt;
#include &lt;opencv2/dnn/dnn.hpp&gt;
#include &lt;opencv2/imgproc.hpp&gt;
#include &lt;opencv2/highgui.hpp&gt;
#include &lt;opencv2/core/utils/filesystem.hpp&gt;
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;
}
</code></pre></div>
<p dir="auto">the way i get the 'step13000_graph.pbtxt' is :</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="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, &quot;&quot;, &quot;/home/cas/work/readpb_opencv/src/opencv_pb/model/step13000_graph.pbtxt&quot;, as_text=True)"><pre class="notranslate"><code class="notranslate">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)
</code></pre></div>
<p dir="auto">Any help in resolving this would be greatly appreciated. Thanks !</p>