Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Classification #10

Closed
sctrueew opened this issue Aug 27, 2023 · 5 comments
Closed

Classification #10

sctrueew opened this issue Aug 27, 2023 · 5 comments

Comments

@sctrueew
Copy link

Hi, thanks for your work. Is it possible to support classification?

@dme-compunet
Copy link
Owner

Yes, here is a sample code:

var image = "path/to/image";

using var predictor = new YoloV8("path/to/model");

var result = predictor.Classify(image);

@sctrueew
Copy link
Author

sctrueew commented Aug 27, 2023

@dme-compunet Hi, I exported my trained model with this script

from ultralytics import YOLO model = YOLO(r"..\runs\classify\train19\weights\best.pt") model.export(format='onnx', opset=15, imgsz = 224)
and then I used this code for inference:

` void ClassifyDemo(string image1, string model)
{
Console.WriteLine();
Console.WriteLine("================ CLASSIFICATION DEMO ================");
Console.WriteLine();
Console.WriteLine("Loading model...");
using var predictor = new YoloV8(model);

  Console.WriteLine("Working...");
  var result = predictor.Classify(image);

  Console.WriteLine();

  Console.WriteLine($"Result: {result}");
  Console.WriteLine($"Speed: {result.Speed}");

  Console.WriteLine();

  foreach (var item in result.Probabilities)
  {
      Console.WriteLine($"{item.Class} {item.Confidence}");
  }

}
`

but the results are not correct.

@dme-compunet
Copy link
Owner

dme-compunet commented Aug 28, 2023

I'm missing details, in the pre-trained model on ImageNet it works great, can you try to understand what the problem is?

@sctrueew
Copy link
Author

I tested with the Yolo command:
yolo classify predict model=runs\classify\train32\weights\best.onnx source="..\n02099601_1421.JPEG" imgsz=224

The result is correct, but when I run it with C# code, the output is different.

@xumix
Copy link

xumix commented Aug 30, 2023

I tested with the Yolo command: yolo classify predict model=runs\classify\train32\weights\best.onnx source="..\n02099601_1421.JPEG" imgsz=224

The result is correct, but when I run it with C# code, the output is different.

Try sorting by item.Confidence

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants