zzh8829/yolov3-tf2

How to generate pbtxt file for cv2.dnn.readNetFromTensorflow

giorgiomondauto opened this issue · 1 comments

  • OpenCV => 4.4.0
  • Operating System / Platform => macOS
  • Compiler => Visual Studio Version: 1.52.1
Detailed description

I am training yolo model on my set of images as per tensorflow-yolov3 and I have generated the .pb model file. Now I am trying to use the following opencv library for detection:
cv2.dnn.readNetFromTensorflow(_.pb,_.pbtxt)
How would I get the correct .pbtxt file generated from pb?
I have tried the below code

with gfile.FastGFile(filename, 'rb') as f:

    graph_def = tf.GraphDef()
    graph_def.ParseFromString(f.read())
    tf.import_graph_def(graph_def, name='')
    tf.train.write_graph(graph_def, ',/',
                         'name.pbtxt', as_text=True)

which generates a pbtxt file. But when I run below:

cv2.dnn.readNetFromTensorflow(_.pb,_.pbtxt)
I get the following error:
error: (-215:Assertion failed) const_layers.insert(std::make_pair(name, li)).second in function 'addConstNodes'

If instead I use as pbtxt file below:
item { id: 1 name: 'ball' }

I get:

error: (-215:Assertion failed) inputs.size() == requiredOutputs in function 'getMemoryShapes'

Any hints on how to overcome this issue?
Thanks a lot

hello, it is a error that get the correct .pbtxt file