Closed michalek-marcin closed 3 years ago
Hi @michalek-marcin ,
Did you freeze the tf graph to convert model parameters into constants? You may need tf weights (.ckpt, you can get it here: DW2TF) and the tf graph (.pb). Somthing like this:
python3 -m tensorflow.python.tools.freeze_graph --input_graph=./checkpoint_dir/yolov2-tiny.pb --input_binary=true --output_node_names=yolov2-tiny/convolutional9/BiasAdd --input_checkpoint=./checkpoint_dir/yolov2-tiny.ckpt --output_graph=./checkpoint_dir/yolov2-tiny-freeze.pb
I then convert the frozen graph to onnx through:
python3 -m tf2onnx.convert --graphdef ./yolov2-tiny-freeze.pb --output yolov2-tiny.onnx --inputs yolov2-tiny/net1:0 --outputs yolov2-tiny/convolutional9/BiasAdd:0
Make sure you use the correct graph inputs and outputs.
Hi @derenlei ,
I found different solution.
keras
keras
to coreml
coreml
to onnx
Tools which I used: https://github.com/hollance/YOLO-CoreML-MPSNNGraph https://github.com/onnx/onnxmltools
I got onnx file and it looks good, but when i paste my model and change DetectorYolo2 component on scene it doesn't work:
Here is my onnx file: https://drive.google.com/file/d/110foE_F0fDRtKByt-dFjyHb8EeVqDkOu/view?usp=sharing
My classes: emiratestower-left emiratestower-right emiratestower-back
App should detect this building:
Ok, I tried your method @derenlei and I have new Onnx file, but I think I did something wrong. Maybe I wrote wrong output node name? I need to understand how read neural network graph in Netron.
What I did:
Freeze graph python3 -m tensorflow.python.tools.freeze_graph --input_graph='/home/ubuntu/Downloads/DW2TF-master/data/yolov2-tiny-custom.pb' --input_binary=true --output_node_names=yolov2-tiny/convolutional9/BiasAdd --input_checkpoint='/home/ubuntu/Downloads/DW2TF-master/data/yolov2-tiny-custom.ckpt' --output_graph='/home/ubuntu/Downloads/DW2TF-master/data/yolov2-tiny-custom_freeze.pb'
https://github.com/onnx/tensorflow-onnx python3 -m tf2onnx.convert --graphdef '/home/ubuntu/Documents/yolo/yolov2-tiny-custom_freeze.pb' --output yolov2-tiny.onnx --inputs yolov2-tiny/net1:0 --outputs yolov2-tiny/convolutional9/BiasAdd:0
Here are my files (cfg, weights and onnx): https://drive.google.com/drive/folders/1GXXe2ej5w8pKkM4XNPDrPArxFUTHa3YD?usp=sharing
My classes: emiratestower-left emiratestower-right emiratestower-back
Hi,
I tried your 'yolov2-tiny_freeze' model and I think it works well. Set the INPUT_NAME to yolov2-tiny/net1 and OUTPUT_NAME to yolov2-tiny/convolutional9/BiasAdd. Also, we use different scripts for yolov2 and v3 so make sure the Selected_detector under Camera Image is yolo 2_tiny.
@derenlei's first answer worked for me. Though for a noob like me it was quite difficult to figure out the parameters and tech stack versions I needed to use in order to get it working. I summarized all the steps I did in my Jupyter Notebook that I uploaded here: https://github.com/DaphiFluffi/Yolov3-To-Onnx-Unity. It converts a Darknet-trained yolov3-tiny model into a Tensorflow model, then into a frozen Tensorflow Graph and then into the Barracuda format. You can open it in Google Colab. Feel free to use it. I tried to describe everything as noob-friendly as I could. I hope it helps ✌
Hello, I'm having a hard time converting the darknet yolov2 model to onnx. It has been converted but does not detect anything when running Barracuda. I want to know in detail how you did it, is it possible?
https://github.com/derenlei/Unity_Detection2AR/issues/39
Here's what I tried.
I remember that my converted model also didn't detect anything in Unity. Somebody wrote this under the repository I posted. Maybe it helps: _
For others coming here from Derenley's repo, i used @Kanyade 's answer from this issue https://github.com/derenlei/Unity_Detection2AR/issues/29 and my model is working now
_
Hello @jjeongmin0308 @DaphiFluffi This was the final colab snippet with which I converted the model successfully which can also be found at the end of the issue linked by Daphi:
https://gist.github.com/Kanyade/c8ee3b7eca6f6e470e418b018ea02e83
Please note that there may be redundant parts as I just copied it from a project of mine to share. Also note that the project the snippet is based on (https://github.com/jkjung-avt/tensorrt_demos) had been updated since then so it may or may not work with its latest version but you can always switch back to an earlier version.
Hi,
Can someone give me instructions how convert my custom darknet model (yolov2-tiny) to ONNX? I know I should convert my darknet model to tensorflow, then to onnx, but I struggle with this for several days.
What I've tried: Convert darknet model (weights + cfg) to tensorflow using darkflow -> I got .pb file (SUCCESS)
Then I wanted to convert pb file to onnx:
mmconvert -sf tensorflow -iw path_to_my_pb_file -df onnx -om yolotfonnx --inNodeName input --dstNodeName output
error:TypeError: can only concatenate list (not "NoneType") to list
python3 -m tf2onnx.convert --graphdef path_to_my_pb_file --output yolov2-tiny.onnx --inputs input:0 --outputs output:0
error:AssertionError: output is not in graph
this also doesn't work:
python3 -m tf2onnx.convert --saved-model path_to_my_pb_file --output yolov2-tiny.onnx
error:onnx-tf convert -i path_to_my_pb_file -o path_for_output_onnx_file
error:ValidationError: The model does not have an ir_version set properly.
I think darkflow can be not compatible with yolov2-tiny. I also tried to convert original darknet yolov2 model and have same problems after conversion with darkflow.