derenlei / Unity_Detection2AR

Localize 2D image object detection in 3D Scene with Yolo in Unity Barracuda and ARFoundation.
https://derenlei.medium.com/object-detection-with-localization-using-unity-barracuda-and-arfoundation-794b4eff02f8
MIT License
223 stars 61 forks source link

How to convert darkflow tiny-yolov2-voc .pb model to onnx model #20

Closed A6248384 closed 3 years ago

A6248384 commented 3 years ago

Hi. Thanks for your project.

my model is trained from darkflow. I'm trying to convert my .pb model to onnx model. But when I'm use below command I got error, python3 -m tf2onnx.convert --graphdef .yolov2-tiny-voc-2c.pb --output yolov2-tiny.onnx --inputs yolov2-tiny/net1:0 --outputs yolov2-tiny/convolutional9/BiasAdd:0

the error is AssertionError: yolov2-tiny/convolutional9/BiasAdd is not in graph

Is there any solution?

here is my model link. https://drive.google.com/drive/folders/1q-NnsnUMUpNy9m7IenWP2x_sVCOcfvOg?usp=sharing

derenlei commented 3 years ago

Hi @A6248384, I think you're not using the correct input/output name for your model. You could check their instructions: https://github.com/onnx/tensorflow-onnx#--inputs---outputs

You could also use the following script. It will output all the node info:

import tensorflow as tf

def load_graph(frozen_graph_filename):
    with tf.gfile.GFile(frozen_graph_filename, "rb") as f:
        graph_def = tf.GraphDef()
        graph_def.ParseFromString(f.read())

    with tf.Graph().as_default() as graph:
        tf.import_graph_def(graph_def, name="")
    return graph

graph = load_graph("YOUR_MODEL_FILE.pb")

for op in graph.get_operations():
    print(op.name, op.outputs)

If your TensorFlow model is valid, the input and output are input:0 and output:0

A6248384 commented 3 years ago

Thanks! I use follow command and can covert to onnx model. python -m tf2onnx.convert --input yolov2-tiny-voc-2c.pb --output yolov2-tiny-voc-2c.onnx --inputs input:0[1,416,416,3] --outputs output:0 --opset 7