opencv: Error while reading DeeplabV3+ xception_65 model in Opencv4.0

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 !

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Comments: 19 (3 by maintainers)

Most upvoted comments

@dkurt same error : terminate called after throwing an instance of ‘cv::Exception’ what(): OpenCV(4.1.0) /home/cas/environment/opencv-4.1.0/modules/dnn/src/tensorflow/tf_importer.cpp:1139: error: (-213:The function/feature is not implemented) Unsupported squeeze configuration in function ‘populateNet’

Did you resolve this issue?

no,but I found out another way to solve this problem for my project, namely, I didn’t use opencv to load model in my C++ program

@RustSon How did you load it then? using Tensorflow C/C++ API?

yes

@RustSon Can you please share the code you used to do inference?

sure. just give me your email

It’s kumar_harshit@outlook.com. Thanks.

The mail has been sent.

@dkurt same error : terminate called after throwing an instance of ‘cv::Exception’ what(): OpenCV(4.1.0) /home/cas/environment/opencv-4.1.0/modules/dnn/src/tensorflow/tf_importer.cpp:1139: error: (-213:The function/feature is not implemented) Unsupported squeeze configuration in function ‘populateNet’

Did you resolve this issue?

no,but I found out another way to solve this problem for my project, namely, I didn’t use opencv to load model in my C++ program