dme-compunet / YoloV8

Integrate YOLOv8 into your C# project for a variety of real-time tasks including object detection, instance segmentation, pose estimation and more, using ONNX Runtime.
https://www.nuget.org/packages/YoloV8
GNU Affero General Public License v3.0
242 stars 45 forks source link

Model not supported #22

Closed uri-el99 closed 11 months ago

uri-el99 commented 11 months ago

Hello author, hope you are doing well.

I am currently trying to use the NuGet Package but I am getting some troubles. I am starting with programming so I´m a bigginer, I used your code reference but I get this: System.InvalidOperationException: 'The loaded model does not support this task' and I do not why, I´ve searched for some solutions but I´m still stuck. Can you help me out? I´d highly apreciate. image

dme-compunet commented 11 months ago

Hello @uri-el99, this exception is thrown because you are trying to perform detection from a model whose task is not 'detect'. YOLOv8 has models for several tasks, you must make sure that the inference you make matches to task of the model. (you can see the model task in the Netron tool)

uri-el99 commented 11 months ago

Hello @uri-el99, this exception is thrown because you are trying to perform detection from a model whose task is not 'detect'. YOLOv8 has models for several tasks, you must make sure that the inference you make matches to task of the model. (you can see the model task in the Netron tool)

I greatly appreciate your response and help on this problem, thank you very much for that observation. Hoping not to take up your time, I would like to know if you can help me with another question. I want to load an image in WindowsForms through an OpneFileDialog and display the image in another one, but already with the results obtained by the model. Do you know how I can make the conversion from System.Drawing.Image to Compunet.YoloV8.ImageSelector?

FunJoo commented 11 months ago
var ofd = new Microsoft.Win32.OpenFileDialog();
if (ofd.ShowDialog() == true)
{
    var image = Compunet.YoloV8.ImageSelector(ofd.FileName)
}
uri-el99 commented 11 months ago
var ofd = new Microsoft.Win32.OpenFileDialog();
if (ofd.ShowDialog() == true)
{
    var image = Compunet.YoloV8.ImageSelector(ofd.FileName)
}

Hi @FunJoo hope I am not disturbing you. Rephrasing my question, how can I display the result in a PictureBox? I want to open an image that is displayed in a PictureBox, and, subsequently, that selected image is analysed and the result is displayed in another PictureBox. I hope you can help me a bit and sorry for the inconvenience.

FunJoo commented 11 months ago

Hi, @uri-el99 I do not use WinForm, but I can provide you with a method given by ChatGPT4.

public static SixLabors.ImageSharp.Image<Rgb24> ConvertToImageSharpImage(System.Drawing.Image systemDrawingImage)
{
    using MemoryStream memoryStream = new MemoryStream();
    systemDrawingImage.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Png);
    memoryStream.Seek(0, SeekOrigin.Begin);
    return SixLabors.ImageSharp.Image.Load<Rgb24>(memoryStream);
}

public static System.Drawing.Image ConvertToSystemDrawingImage(SixLabors.ImageSharp.Image<Rgb24> imageSharpImage)
{
    using MemoryStream memoryStream = new MemoryStream();
    imageSharpImage.Save(memoryStream, new SixLabors.ImageSharp.Formats.Png.PngEncoder());
    memoryStream.Seek(0, SeekOrigin.Begin);
    return System.Drawing.Image.FromStream(memoryStream);
}

When encountering situations where Compunet.YoloV8.ImageSelector is needed, you can directly use SixLabors.ImageSharp.Image.

uri-el99 commented 11 months ago

@FunJoo Thanks for all your support, using the information you provided, I was able to solve that problem, and, although others came up later, I was able to solve them. I appreciate the time you took to find a solution, thank you very much. best regards!