Skip to content

OpenCV readNetFromTensorflow returns unsupported Tensor's data type #15129

@paulbauriegel

Description

@paulbauriegel
System information (version)
  • OpenCV: 4.1.1-pre (master)
  • OS: Ubuntu 19.04 64bit
  • Compiler: gcc 8.3.0
Detailed description
----> 1 model = cv2.dnn.readNetFromTensorflow("model_lcnn_29v2_optim.pb")

error: OpenCV(4.1.1-pre) /home/paulb/opencv/modules/dnn/src/tensorflow/tf_graph_simplifier.cpp:890: error: (-2:Unspecified error) Tensor's data type is not supported in function 'getTensorContent'
Steps to reproduce
  1. Models
  1. I converted an existing ONNX model to Tensorflow
    onnx-tf convert -i model_lcnn_29v2.onnx -o model_lcnn_29v2.pb

  2. Optimize the model for inference as described in Error Loading frozen graph(.pb) using readNetFromTensorflow  #14073 (comment)

from tensorflow.python.tools import optimize_for_inference_lib

path = "model_lcnn_29v2.pb"
graph_def = tf.GraphDef()
with tf.Session() as sess:
    # Read binary pb graph from file
    with tf.gfile.Open(path, "rb") as f:
        data2read = f.read()
        graph_def.ParseFromString(data2read)
    
    # Optimize/Transform for inference: 
    graph_def = tf.graph_util.convert_variables_to_constants(sess, graph_def, ['MatMul_1'])
    graph_def = optimize_for_inference_lib.optimize_for_inference(graph_def, ['0'], ['MatMul_1'], tf.float32.as_datatype_enum)
    tf.train.write_graph(graph_def, "", path.rsplit('.', 1)[0]+'_optim.pb', as_text=False)
  1. Tried to read the model with OpenCV, but failed to load any
  • model = cv2.dnn.readNetFromTensorflow("model_lcnn_29v2_optim.pb")
  • model = cv2.dnn.readNetFromTensorflow("model_lcnn_29v2.pb")

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions