TailoredApps.Shared.MediatR.ML
2.1.0
See the version list below for details.
dotnet add package TailoredApps.Shared.MediatR.ML --version 2.1.0
NuGet\Install-Package TailoredApps.Shared.MediatR.ML -Version 2.1.0
<PackageReference Include="TailoredApps.Shared.MediatR.ML" Version="2.1.0" />
<PackageVersion Include="TailoredApps.Shared.MediatR.ML" Version="2.1.0" />
<PackageReference Include="TailoredApps.Shared.MediatR.ML" />
paket add TailoredApps.Shared.MediatR.ML --version 2.1.0
#r "nuget: TailoredApps.Shared.MediatR.ML, 2.1.0"
#:package TailoredApps.Shared.MediatR.ML@2.1.0
#addin nuget:?package=TailoredApps.Shared.MediatR.ML&version=2.1.0
#tool nuget:?package=TailoredApps.Shared.MediatR.ML&version=2.1.0
TailoredApps.Shared.MediatR.ML
Image classification with ML.NET as MediatR requests. ClassifyImage runs a trained model on an uploaded image
and TrainImageClassificationModel trains a new model from folders of labelled images. The code lives in the
namespace TailoredApps.Shared.MediatR.ImageClassification, not under the package name.
Installation
dotnet add package TailoredApps.Shared.MediatR.ML
Registration
using Microsoft.Extensions.ML;
using TailoredApps.Shared.MediatR.ImageClassification.Infrastructure;
using TailoredApps.Shared.MediatR.ImageClassification.Interfaces.Domain.Models;
// The handlers of both commands are in this package's assembly
builder.Services.AddMediatR(cfg =>
{
cfg.RegisterServicesFromAssembly(typeof(Program).Assembly);
cfg.RegisterServicesFromAssembly(typeof(AddPredictionEngineExtension).Assembly);
});
builder.Services.AddPredictionEngine(engine =>
engine.RegisterMachineLearningModel<InMemoryImageData, ImagePredictionScore>(pool =>
pool.FromFile(builder.Configuration[ImageClassificationOptions.ModelFilePathConfig]!)));
AddPredictionEngine registers IImageClassificationService, IModelInfoService and IModelHelper (scoped)
and binds ImageClassificationOptions. RegisterMachineLearningModel adds the ML.NET PredictionEnginePool;
where the model is loaded from is decided by the pool builder you configure (FromFile above), not by the options.
Usage
using TailoredApps.Shared.MediatR.ImageClassification.Domain.DataModel.Message.Commands;
var classified = await mediator.Send(new ClassifyImage { FileByteArray = imageBytes, FileName = "photo.jpg" });
var label = classified.ImagePrediction?.PredictedLabel;
var score = classified.ImagePrediction?.PredictedScore;
var trained = await mediator.Send(new TrainImageClassificationModel
{
Source = "pets", // folder inside TrainingRoot, one sub-folder per label
ModelDestFolderPath = "pets.zip", // model file inside ModelsRoot
});
// trained.ModelPath, trained.ModelVersion, trained.Labels, trained.ModelInfo (evaluation metrics as text)
Configuration
The ImageClassification section:
{
"ImageClassification": {
"ModelFilePath": "/var/app/models/current.zip",
"TrainingRoot": "/var/app/training-sets",
"ModelsRoot": "/var/app/models",
"MaxImageBytes": 10485760
}
}
| Key | Meaning | Default |
|---|---|---|
ModelFilePath |
Model file described by IImageClassificationService.GetModelInfo() (name, checksum, version, labels); the registration above also loads the model from it |
none |
TrainingRoot |
Directory that training sets must be inside; required for training | none |
ModelsRoot |
Directory that trained models are written inside; required for training | none |
MaxImageBytes |
Largest image accepted by ClassifyImage; 0 turns the limit off |
10485760 (10 MB) |
Good to know
- The section is required: without it the options throw
InvalidOperationExceptionwhen first used. ClassifyImagethrowsArgumentExceptionfor empty content, for content overMaxImageBytesand for content that does not start with a JPEG or PNG signature. OnlyFileName,PredictedLabelandPredictedScoreof the returnedImagePredictionare filled;ScoresandModelInfostaynull.- Training paths are resolved against
TrainingRootandModelsRoot. A path outside its root throwsArgumentException; a root that is not configured throwsInvalidOperationException. - Training reads files with the extension
.jpgor.pngfromSourceand its sub-folders and uses the name of the folder a file is in as its label. It runs inside the request and can take long; a fifth of the images is held back for evaluation. The saved model is a zip archive to whichVersion.txt(ayyyyMMdd.HHmmsstimestamp) andLabels.txtare added. - Prediction uses the default model of the pool, so register the model without a model name.
PredictionEngineServiceConfigurationis the one public type in the namespaceTailoredApps.Shared.MediatR.ML.Infrastructure.
Documentation
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. net11.0 is compatible. |
-
net10.0
- FluentValidation (>= 12.2.0)
- Microsoft.Bcl.Memory (>= 10.0.14)
- Microsoft.Extensions.Caching.Abstractions (>= 10.0.15)
- Microsoft.Extensions.DependencyInjection (>= 10.0.15)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.15)
- Microsoft.Extensions.ML (>= 5.0.1)
- Microsoft.Extensions.Options (>= 10.0.15)
- Microsoft.ML (>= 5.0.1)
- Microsoft.ML.AutoML (>= 0.23.1)
- Microsoft.ML.ImageAnalytics (>= 5.0.1)
- Microsoft.ML.Vision (>= 5.0.1)
- TailoredApps.Shared.MediatR (>= 2.1.0)
-
net11.0
- FluentValidation (>= 12.2.0)
- Microsoft.Bcl.Memory (>= 10.0.14)
- Microsoft.Extensions.DependencyInjection (>= 11.0.0)
- Microsoft.Extensions.ML (>= 5.0.1)
- Microsoft.ML (>= 5.0.1)
- Microsoft.ML.AutoML (>= 0.23.1)
- Microsoft.ML.ImageAnalytics (>= 5.0.1)
- Microsoft.ML.Vision (>= 5.0.1)
- TailoredApps.Shared.MediatR (>= 2.1.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 3.0.0-preview.2 | 39 | 11/12/2026 |
| 3.0.0-preview.1 | 61 | 11/12/2026 |
| 2.1.0 | 62 | 11/12/2026 |
| 2.0.1 | 67 | 11/12/2026 |
| 2.0.0 | 69 | 11/12/2026 |
| 1.6.0 | 67 | 11/12/2026 |
| 1.4.19 | 106 | 10/26/2026 |
| 1.4.18 | 104 | 10/23/2026 |
| 1.4.17 | 115 | 10/6/2026 |
| 1.4.16 | 114 | 9/28/2026 |
| 1.4.15 | 118 | 9/21/2026 |
| 1.4.14 | 125 | 8/20/2026 |
| 1.4.13 | 132 | 8/20/2026 |
| 1.4.12 | 138 | 8/20/2026 |
| 1.4.11 | 140 | 8/7/2026 |
| 1.4.10 | 149 | 7/8/2026 |
| 1.4.9 | 149 | 7/8/2026 |
| 1.4.8 | 143 | 7/6/2026 |
| 1.4.7 | 153 | 5/20/2026 |
| 1.4.6 | 153 | 5/20/2026 |