techwingslab / yolov5-net

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

Hi, Can it be configured to detect only one of 80 classes? #37

Closed luopinluobo closed 3 years ago

luopinluobo commented 3 years ago

image

I have a few questions:

  1. I want to use the original [yolov5n. Onnx] and configure it to detect. For example, in the class of [person], I want to filter during detection, not after the results come out. Can I do this?
  2. Will this increase our detection speed?
  3. If we can't do this, can we only realize it by starting a new training model?

I am a beginner of yolov5. This code example is very helpful to me. Thank you

kkarahainko commented 3 years ago

@luopinluobo you have to train a new model if you need only 1 class, you may change Dimensions, Labels but it won't work, beacuse output tensor will have size of 85 anyway and will contain predictions for all trained classes.

luopinluobo commented 3 years ago

@kkarahainko Thank you very much for your reply. It seems that we can't directly use some trained models and use their subclasses. If the new model has only one class, will the prediction speed be significantly improved?

kkarahainko commented 3 years ago

@luopinluobo it depends on what you're going to achieve, number of classes will not significantly improve the detection speed, pay attention to GPU acceleration, Im getting 30+ fps on laptop with rtx 3060, it's enough for tasks like video, stream processing etc.

kkarahainko commented 3 years ago

@luopinluobo im not sure why can't you use pre-trained models )

var persons = predictions.Where(x => x.Label.Name == "person"); persons will containt only "person" predictions

luopinluobo commented 3 years ago

@kkarahainko I just want to test whether there is a big improvement. Now I have also obtained 30 + FPs in gtx1080ti, but the target machine is gtx1050. I haven't tested whether it can be met, so I want to find out whether there is any way to improve the speed. If the speed meets my requirements. I will use your recommendation and filter the results

luopinluobo commented 3 years ago

@kkarahainko image image image It seems that [Python] can be used, but I don't know how to use .Net to implement it

kkarahainko commented 3 years ago

@luopinluobo technically it's possible, copy whole tensor to smaller one, like this

var output = new DenseTensor<float>(new[] { 1, 25200, 6 });

Parallel.For(0, 1, (a) =>
{
    Parallel.For(0, 25200, (b) =>
    {
        Parallel.For(0, 6, (c) =>
        {
            output[a, b, c] = original[a, b, c];
        });
    });
});

but I didn't see any difference + C# has no Tensor range and GPU acceleration operations, so I've decided not to implement this type of filtering for now, see no sense and didn't find elegant way.