YunYang1994 / tensorflow-yolov3

🔥 TensorFlow Code for technical report: "YOLOv3: An Incremental Improvement"
https://yunyang1994.gitee.io/2018/12/28/YOLOv3-算法的一点理解/
MIT License
3.63k stars 1.36k forks source link

how generate pbtx file for cv2.dnn.readNetFromTensorflow(_.pb,_.pbtxt) #590

Open giorgiomondauto opened 3 years ago

giorgiomondauto commented 3 years ago
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