techwingslab / yolov5-net

YOLOv5 object detection with C#, ML.NET, ONNX
MIT License
351 stars 104 forks source link

Custom Model creation fail #85

Closed NBarile closed 12 months ago

NBarile commented 1 year ago

Hello

I have a problem when i try to create my own YoloModel class for my custom yolo model.

image

If I understand, I can't herit from YoloModel ?

But if I can't, how can i create my own model .

Have you a documentation to easly create custom model ?

Thanks !

Here is the code if need :

using Yolov5Net.Scorer;
using Yolov5Net.Scorer.Models.Abstract;

namespace YoloDotNetTest
{
    public class MyYolo : YoloModel
    {
        public override int Width { get; set; } = 640;
        public override int Height { get; set; } = 640;
        public override int Depth { get; set; } = 3;
        public override int Dimensions { get; set; } = 6;
        public override float[] Strides { get; set; } = new float[] { 8, 16, 32 };
        public override float[][][] Anchors { get; set; } = new float[][][]
        {
            new float[][] { new float[] { 010, 13 }, new float[] { 016, 030 }, new float[] { 033, 023 } },
            new float[][] { new float[] { 030, 61 }, new float[] { 062, 045 }, new float[] { 059, 119 } },
            new float[][] { new float[] { 116, 90 }, new float[] { 156, 198 }, new float[] { 373, 326 } }
        };
        public override int[] Shapes { get; set; } = new int[] { 80, 40, 20 };

        public override float Confidence { get; set; } = 0.20f;
        public override float MulConfidence { get; set; } = 0.25f;
        public override float Overlap { get; set; } = 0.45f;

        public override string[] Outputs { get; set; } = new[] { "output" };

        public override List<YoloLabel> Labels { get; set; } = new List<YoloLabel>()
        {
            new YoloLabel { Id = 0, Name = "bike" },
            new YoloLabel { Id = 1, Name = "car" }
        };

        public override bool UseDetect { get; set; } = true;

        public MyYolo() { }
    }
}
Haloroute commented 12 months ago

You need to create a Record, not a Class public record MyYolo : YoloModel not public class MyYolo : YoloModel

NBarile commented 12 months ago

You need to create a Record, not a Class public record MyYolo : YoloModel not public class MyYolo : YoloModel

Thanks !

Have you a exemple of class to show me ?

NBarile commented 12 months ago

You need to create a Record, not a Class public record MyYolo : YoloModel not public class MyYolo : YoloModel

Thanks !

Have you a exemple of class to show me ?

I find a working model :

public record MyYolo : YoloModel
{
    public MyYolo()
        : base(640, 640, 3, 7 /*Number of class + 5*/, new int[] { 8, 16, 32 }, new int[][][]
        {
            new int[][]
            {
                new int[] { 10, 13 },
                new int[] { 16, 30 },
                new int[] { 33, 23 }
            },
            new int[][]
            {
                new int[] { 30, 61 },
                new int[] { 62, 45 },
                new int[] { 59, 119 }
            },
            new int[][]
            {
                new int[] { 116, 90 },
                new int[] { 156, 198 },
                new int[] { 373, 326 }
            }
        }, new int[] { 80, 40, 20 }, 0.2f, 0.25f, 0.45f, new string[] { "output0" }, new List<YoloLabel>
        {
            new YoloLabel(0, "pointrouge"),
            new YoloLabel(1, "pointblanc")
        }, UseDetect: true)
    {
    }
}