I followed this microsoft tutorial and there was no problem. but i wanted to change model to yolo v3 or v4. I get the YOLOv4 onnx model from onnx/models and was able to get all three array of float outputs of yolov4 onnx model but the problem is with post-processing and i can't get proper boundinboxes from these outputs.
I changed all things like anchors, strides, output grid sizes, some functios and... in microsoft tutorial src code to be compatible with yolov4. but I cant get proper results. I checked all my code with python implementation but i don't know where is the problem. Does anyone have a link or knows how to implement yolo v3 or v4 onnx models in c# with ML.Net
Any help will be appreciated
I think it is not possible to directly port microsoft's tutorial from YOLO v2 to v3 as it relies on the inputs and outputs of each model.
As a side note, I did a port of another YOLO v3 model to ML.Net in this GitHub repo: 'YOLOv3MLNet'. It contains a fully functionning ML.Net pipeline.
I've also made the code of this answer available here:
To go back to your models, I'll take the YOLO v3 (available in the onnx/models repo) as an example. A good explaination of the model can be found here.
First advice would be to look at the model using Netron. Doing so, you will see the input and output layers. They also describe these layers in the onnx/models documentation.
Netron's yolov3-10 screenshot
(I see in Netron that this particular YOLO v3 model also does some post-processing by doing the Non-maximum supression step.)
input_1
,image_shape
yolonms_layer_1/ExpandDims_1:0
,yolonms_layer_1/ExpandDims_3:0
,yolonms_layer_1/concat_2:0
As per the model documentation, the input shapes are:
We first need to define the ML.Net input and output classes as follow:
We then create the ML.Net pipeline and load the prediction engine:
NB: We need to define the
shapeDictionary
parameter because they are not completly defined in the model.As per the model documentation, the output shapes are:
The function below will help you process the results, I leave it to you fine-tune it.
In this version of the model, they are 80 classes (see the model's GitHub documentation for the link).
You can use the above like this:
You can find a result example here.