onnx / onnxmltools

ONNXMLTools enables conversion of models to ONNX
https://onnx.ai
Apache License 2.0
967 stars 178 forks source link

Core ML Tiny-yoloV2 confidence drops significantly after conversion #256

Open walterPeyton opened 5 years ago

walterPeyton commented 5 years ago

Dear fellow programmers,

I'm currently trying to build my own self trained version of a tiny-yolov2 network comparable to: https://github.com/onnx/models/tree/master/tiny_yolov2

I want only 6 custom classes instead of the given 20 classes that the Zoo model offers. So far I've successfully trained and converted the model from darknet to tensorflow, to CoreML. I'm very very sure that those conversions have been successful since I built dummy Apps for either Framework and they work like a charm.

Now the problem:

I'm not able to convert the Core ML model to ONNX. The conversion runs fine but the output values (such as predicted bounding boxes but especially the confidence) are getting super low. The network is practically unusable after the conversion.

I'm currently using the following ONNX parser that I modified so that it only detects 6 classes (changed the class number to 6, channel count to 55 etc): https://github.com/TakahiroMiyaura/HoloLensOnnxTinyYoLo/blob/master/UwpOnnxTinyYoloV2_2D/UwpOnnxTinyYoloV2/UWPOnnxTinyYoloV2.Common/Yolo9000/YoloWinMLParser.cs

As I mentioned before, the confidence of the new model is very very small, the detection is worse than before as well.

Here are the Graphs of the networks (created with Netron):

First, the ONNX Model: yolo_onnx

Second, the Core ML that I used to create the ONNX model:

yolo_coreml

The code I used to convert the model was the one that was put on the official ONNXMLTools site: https://github.com/onnx/onnxmltools

image

Is there anything that I could change or maybe even a simpler way to train a tiny yolo model to run it in a UWP or even on the HoloLens directly?

I'm very thankful for any idea, tip, opinion on this problem.

If you need more information, please ask! :)

Thanks in advance

Walter

wenbingl commented 5 years ago

If you already have a tensorflow model, why not try this tensorflow-onnx converter? https://github.com/onnx/tensorflow-onnx

walterPeyton commented 5 years ago

Hey wenbingl,

thanks very much for the reply! I already tried the converter you mentioned but the result is the same :/ Is it possible that my network (regardless if it's in tensorflow/Coreml etc.) has a specialty that simply can't be converted to ONNX?

wschin commented 5 years ago

One possibility is that input format is not expected. It can be either RGB, GBR, and so on. Could you try a constant image (for example, a tensor with all values set to 1) and compare results from the original model and its onnx one?

3265 commented 4 years ago

I got a similar problem when I try out inference after converting YAD2K (yolov2-tiny-voc.h5) to onnx model . But that reason was i just haven't done image normalization as input on my script. ref https://github.com/allanzelener/YAD2K/blob/master/test_yolo.py#L139