TailoredApps.Shared.MediatR.ML 2.1.0

There is a newer prerelease version of this package available.
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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TailoredApps.Shared.MediatR.ML" Version="2.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TailoredApps.Shared.MediatR.ML" Version="2.1.0" />
                    
Directory.Packages.props
<PackageReference Include="TailoredApps.Shared.MediatR.ML" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add TailoredApps.Shared.MediatR.ML --version 2.1.0
                    
#r "nuget: TailoredApps.Shared.MediatR.ML, 2.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package TailoredApps.Shared.MediatR.ML@2.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=TailoredApps.Shared.MediatR.ML&version=2.1.0
                    
Install as a Cake Addin
#tool nuget:?package=TailoredApps.Shared.MediatR.ML&version=2.1.0
                    
Install as a Cake Tool

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 InvalidOperationException when first used.
  • ClassifyImage throws ArgumentException for empty content, for content over MaxImageBytes and for content that does not start with a JPEG or PNG signature. Only FileName, PredictedLabel and PredictedScore of the returned ImagePrediction are filled; Scores and ModelInfo stay null.
  • Training paths are resolved against TrainingRoot and ModelsRoot. A path outside its root throws ArgumentException; a root that is not configured throws InvalidOperationException.
  • Training reads files with the extension .jpg or .png from Source and 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 which Version.txt (a yyyyMMdd.HHmmss timestamp) and Labels.txt are added.
  • Prediction uses the default model of the pool, so register the model without a model name.
  • PredictionEngineServiceConfiguration is the one public type in the namespace TailoredApps.Shared.MediatR.ML.Infrastructure.

Documentation

https://shared.tailoredapps.pl/en/Libraries/MediatR/ML/

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
Loading failed