Opencv4.0.0 failed to parse *.pbtxt from tensorflow 1.12.0: "Unknown enumeration value of \"DT_RESOURCE\" for field \"type\"."

asked 2018-11-21 15:14:11 -0600

kvc gravatar image

updated 2018-11-23 12:48:51 -0600

Hi,

I used opencv3.4.1 to load pre-trained model from tensorflow. *.pb and *.pbtxt which were generated by the following code:

       output_nodes = [n.name for n in tf.get_default_graph().as_graph_def().node]

        # Freeze the graph
        frozen_graph_def = tf.graph_util.convert_variables_to_constants(
            sess,
            sess.graph_def,
            output_nodes)

        # Save the frozen graph
        with open('./model/output_graph.pb', 'wb') as f:
            f.write(frozen_graph_def.SerializeToString())

        tf.train.write_graph(sess.graph_def, "./model", "output_graph_def.pbtxt", True)

And I loaded them by using cv::dnn

 cv::dnn::Net local_cvNet = cv::dnn::readNetFromTensorflow("./model/output_graph.pb",
    "./model/output_graph_def.pbtxt");

That gave me an error :

       FAILED: ReadProtoFromTextFile(param_file, param). Failed to parse GraphDef file: ./output_graph_def.pbtxt"    char *

In addition, I used CTC_loss layer in tensorflow, it may be the problem for opencv parser ?

I dont know what is wrong ? in python script to generate *pbtxt or *.pbtxt itself ? Any suggestion ?

I switched to opencv4.0.0 as dkurt proposed, but the problem is still there. Here is callstack:

 (-2:Unspecified error)
  FAILED: ReadProtoFromTextFile(param_file, param). Failed to parse GraphDef file: ./output_graph_def.pbtxt"

    opencv_world400d.dll!cv::error(const cv::Exception & exc) Line 1032 C++
opencv_world400d.dll!cv::error(int _code, const 
    std::basic_string<char,std::char_traits<char>,std::allocator<char> > & _err, const char * _func, const char * 
   _file, int _line) Line 1044  C++
opencv_world400d.dll!cv::dnn::GLogWrapper::check() Line 90  C++
opencv_world400d.dll!cv::dnn::ReadTFNetParamsFromTextFileOrDie(const char * param_file, 
   opencv_tensorflow::GraphDef * param) Line 54 C++
  > opencv_world400d.dll!cv::dnn::dnn4_v20180917::`anonymous 
  namespace'::TFImporter::TFImporter(const char * model, const char * config) Line 438  C++
opencv_world400d.dll!cv::dnn::dnn4_v20180917::readNetFromTensorflow(const 
  std::basic_string<char,std::char_traits<char>,std::allocator<char> > & model, const 
  std::basic_string<char,std::char_traits<char>,std::allocator<char> > & config) Line 1931  C++

Well, go deep into these stack, I found this message:

 "Unknown enumeration value of \"DT_RESOURCE\" for field \"type\"." from text_format.cc

It seems this value type is new from Opencv ? Here is my graph followed l'architexture : CNN+BLSTM+CTC: You have to change the format from png-> pbtxt C:\fakepath\output_graph.png

Any luck ?

edit retag flag offensive close merge delete

Comments

the error msg looks incomplete. can you take another look ?

berak gravatar imageberak ( 2018-11-21 23:42:24 -0600 )edit

OpenCV 3.4.1 released 3 quarters ago. Please use the latest state or specify in your question that you're not able to use different version.

dkurt gravatar imagedkurt ( 2018-11-22 01:23:53 -0600 )edit

could you at least add the pbtxt file to your question ?

berak gravatar imageberak ( 2018-11-22 11:23:42 -0600 )edit