Now supports both Blazor Server and WASM and MAUI Hybrid.
- Neural Network
- Image Classification
- Sound Classifier
- Object Detector (YOLO and COCOSSD based)
- PoseNet
- Sentiment Analyzer
- FaceMesh
Install Asp.Net Core payload and then follow Installation Instructions here to configure ML5 to use it from C# Blazor app.
API documentation can be followed from here after lib configuration.
.
@page "/nn"
@using BlazorML5
@using BlazorML5.Helpers
@inject IJSRuntime runtime
<PageTitle>Index</PageTitle>
<button @onclick="AddData">Add Data and Train</button>
@code
{
NeuralNetwork _network;
protected override async Task OnInitializedAsync()
{
await Ml5.InitAsync(runtime);
_network = await Ml5.NeuralNetworkAsync(new NeuralNetworkOptions()
{
Task = TaskType.Classification,
DataUrl = "https://raw.githubusercontent.com/ml5js/ml5-library/main/examples/p5js/NeuralNetwork/NeuralNetwork_color_classifier/data/colorData_small.json",
Debug = true,
Inputs = new object[]{"r", "g", "b"},
Outputs = new object[]{"label"}
});
_network.OnTraining+=(l,e)=>
{
Console.WriteLine($"Training: {e}%");
};
_network.OnTrainingComplete+=async ()=>
{
Console.WriteLine($"Training Complete");
await _network.ClassifyMultipleAsync(new object[]{new object[]{12,13,14},new object[]{15,16,17}});
};
_network.OnDataLoaded+=(e)=>
{
Console.WriteLine($"Data Loaded");
};
_network.OnClassify+=async (l,e)=>
{
Console.WriteLine(e.Length);
Console.WriteLine(e[0].Label);
};
_network.OnClassifyMultiple+=async (l,e)=>
{
Console.WriteLine(e.Length);
Console.WriteLine(e[0].Length);
Console.WriteLine(e[0][0].Label);
};
}
async void AddData()
{
//data fetched from .csv file no need to manually add and hence directly training
//await _network.NormalizeDataAsync();
await _network.TrainAsync();
}
}
More samples here