You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I trained a classification model in Python using the Ultralytics Yolo module, and it performs quite well. Then I exported the model to the ONNX format and used it in a .NET web service with this nuget package. There the classification results are way worse than with the original .pt model in the Python environment.
To be a bit more precise on what "worse" means: All my test images (not part of the training and test set of the model training) were classified correctly in Python, and also always with a certainty of >99%. In C#, most of the images are also classified correctly, but the certainty varies a lot. In some cases, the classification also leads to a wrong result, with something like 52% certainty for the wrong class and 47% certainty for the correct class.
I'm new to computer vision (AI), so it's probably not really a bug but just something that I'm missing.
This is the Python code I used for the training (I'm using a MacBook Air with M1):
from ultralytics import YOLO
# Load a model
model = YOLO("yolo11s-cls.pt") # load a pretrained model (recommended for training)
# Train the model with MPS
results = model.train(data="/Users/admin/PycharmProjects/trainingset", epochs=200, imgsz=640, device="mps")
This is the Python code I used to test the classification for several images (I used images which were neither part of the training nor part of the test set):
from ultralytics import YOLO
# Load a model
model = YOLO("./final_models/classify_amount.pt")
# Run batched inference on a list of images
results = model(["/Users/admin/Downloads/Card_1.jpeg"]) # return a list of Results objects
# Process results list
for result in results:
probs = result.probs # Probs object for classification outputs
result.show() # display to screen
result.save(filename="result.jpg") # save to disk
This is the simplified C# class I use in my web service which runs the classification:
public static class YoloImageProcessing
{
// Instantiate the yolo detection model
private static readonly Yolo AmountClassificationModel = new Yolo(new YoloOptions
{
OnnxModel = @"./YoloModels/classify_amount.onnx", // Your Yolo model in onnx format
ModelType = ModelType.Classification, // Set your model type
Cuda = false, // Use CPU or CUDA for GPU accelerated inference. Default = true
GpuId = 0, // Select Gpu by id. Default = 0
PrimeGpu = false, // Pre-allocate GPU before first inference. Default = false
});
public static List<Classification> ProcessCardAmount(IFormFile imageFormFile)
{
using var image = SKImage.FromEncodedData(imageFormFile.OpenReadStream());
return AmountClassificationModel.RunClassification(image, 3);
}
}
Are there any obvious issues in my code, or are there any fundamental misunderstandings on my side? Is it normal that the ONNX models behave differently (worse) than the pt models?
In case you need any further information about training data, training results or the general use case, I can share everything that's needed.
Thanks in advance for the support!
The text was updated successfully, but these errors were encountered:
Hello,
I trained a classification model in Python using the Ultralytics Yolo module, and it performs quite well. Then I exported the model to the ONNX format and used it in a .NET web service with this nuget package. There the classification results are way worse than with the original .pt model in the Python environment.
To be a bit more precise on what "worse" means: All my test images (not part of the training and test set of the model training) were classified correctly in Python, and also always with a certainty of >99%. In C#, most of the images are also classified correctly, but the certainty varies a lot. In some cases, the classification also leads to a wrong result, with something like 52% certainty for the wrong class and 47% certainty for the correct class.
I'm new to computer vision (AI), so it's probably not really a bug but just something that I'm missing.
This is the Python code I used for the training (I'm using a MacBook Air with M1):
This is the Python code I used to test the classification for several images (I used images which were neither part of the training nor part of the test set):
This is the simplified C# class I use in my web service which runs the classification:
Are there any obvious issues in my code, or are there any fundamental misunderstandings on my side? Is it normal that the ONNX models behave differently (worse) than the pt models?
In case you need any further information about training data, training results or the general use case, I can share everything that's needed.
Thanks in advance for the support!
The text was updated successfully, but these errors were encountered: