{"id":22777551,"url":"https://github.com/darth-vader-lg/machinelearning","last_synced_at":"2026-05-03T16:32:03.096Z","repository":{"id":98143514,"uuid":"359959076","full_name":"darth-vader-lg/MachineLearning","owner":"darth-vader-lg","description":"Machine learning library","archived":false,"fork":false,"pushed_at":"2021-10-04T13:53:21.000Z","size":10305,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-05T18:48:23.802Z","etag":null,"topics":["algorithms","computer-vision","csharp","dotnet","machine-learning","ml","object-detection","tensorflow","tensorflow2","training"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/darth-vader-lg.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-04-20T21:46:40.000Z","updated_at":"2022-01-28T16:44:06.000Z","dependencies_parsed_at":null,"dependency_job_id":"1d7b5e5b-36a1-4147-8b9a-6b9cd45b0663","html_url":"https://github.com/darth-vader-lg/MachineLearning","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darth-vader-lg%2FMachineLearning","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darth-vader-lg%2FMachineLearning/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darth-vader-lg%2FMachineLearning/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darth-vader-lg%2FMachineLearning/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/darth-vader-lg","download_url":"https://codeload.github.com/darth-vader-lg/MachineLearning/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246326600,"owners_count":20759436,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algorithms","computer-vision","csharp","dotnet","machine-learning","ml","object-detection","tensorflow","tensorflow2","training"],"created_at":"2024-12-11T19:14:49.970Z","updated_at":"2026-05-03T16:32:03.058Z","avatar_url":"https://github.com/darth-vader-lg.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"﻿\n\n# MachineLearning\n\n**MachineLearning** is a .NET library mainly based on Microsoft [ML.NET](https://dotnet.microsoft.com/apps/machinelearning-ai/ml-dotnet) framework but it could be considered a melting pot for various frameworks ([TensorFlow](https://www.tensorflow.org/), [TensorFlow models](https://github.com/tensorflow/models), [PyTorch](https://pytorch.org/), [Ultralytics](https://ultralytics.com/) [YoloV5](https://github.com/ultralytics/yolov5), etc...).\u003cBR\u003e\n\n## Main characteristics\n* It's based on the [ML.NET](https://dotnet.microsoft.com/apps/machinelearning-ai/ml-dotnet) framework.\n* Compatible with TensorFlow 2.6.x and [TensorFlow 2.6.x](https://www.tensorflow.org/) and [ONNX](https://onnx.ai/)\n* All code can be written in any .NET standard languages (C#, F#, Basic, etc...) without knowledge or needs of resources as Python or anything other.\n* It can be used with all .NET languages, simply including the package on your project.\n* It has a multitasking structure, providing base classes which allow background models' train and update while using them for the inference without stopping; all in the same device.\n* A growing model zoo with simple to use, ready-made and parametrized classes to solve main machine learning tasks.\n* It includes obviously all the [ML.NET](https://dotnet.microsoft.com/apps/machinelearning-ai/ml-dotnet) features at low level, but also wrapping some of them with more friendly classes for newbies.\n* An object detection class ([ObjectDetection.cs](https://github.com/darth-vader-lg/MachineLearning/blob/master/src/MachineLearning/ModelZoo/ObjectDetection.cs)), having both train and inference skills, is provided to bridge the gap of the missing train feature task of the .NET projects, which nowadays is accomplished mainly in Python.\n* Can import a plenty of pre-trained models (TensorFlow saved_model or frozen graph, Onnx, etc...)\n\n## Some ready-made classes\n|Class|Purpose|\n|--|--|\n|[ImageClassification](https://github.com/darth-vader-lg/MachineLearning/blob/master/src/MachineLearning/ModelZoo/ImageClassification.cs)|Classify images in categories, from standard pre-trained models or training custom models|\n|[ObjectDetection](https://github.com/darth-vader-lg/MachineLearning/blob/master/src/MachineLearning/ModelZoo/ObjectDetection.cs)|Detect objects in pictures with common standard pre-trained models or training custom models.|\n|[SentenceClassification](https://github.com/darth-vader-lg/MachineLearning/blob/master/src/MachineLearning/ModelZoo/SentenceClassification.cs)|To classify the meaning of text/phrases.|\n|[SizeEstimation](https://github.com/darth-vader-lg/MachineLearning/blob/master/src/MachineLearning/ModelZoo/SizeEstimation.cs)|Estimation of sizes from set of measures|\n|[SmartDictionary](https://github.com/darth-vader-lg/MachineLearning/blob/master/src/MachineLearning/ModelZoo/SmartDictionary.cs)|A dictionary having string keys but with elements addressable with expressions having just a similarity to the requested key.|\n\n## Getting started with MachineLearning\n\nSimply include the package (or the reference to the project if you include it in your solution) to used the library.\u003cBR\u003e\nInclude extra packages and runtimes if you need to use more advanced features.\u003cBR\u003e\n### Packages for advanced feature tasks:\n* **Onnx models inference**: [Onnx runtime](https://www.nuget.org/packages/Microsoft.ML.OnnxRuntime/) or [Onnx runtime GPU](https://www.nuget.org/packages/Microsoft.ML.OnnxRuntime.Gpu/)\n* **TensorFlow model inference**: [LG.TensorFlow.NET](https://www.nuget.org/packages/LG.TensorFlow.NET), [LG.SciSharp.TensorFlow.Redist](https://www.nuget.org/packages/LG.SciSharp.TensorFlow.Redist) or [LG.SciSharp.TensorFlow.Redist-Windows-GPU](https://www.nuget.org/packages/LG.SciSharp.TensorFlow.Redist-Windows-GPU).\n* **TensorFlow object detection train**: [ODModelBuilderTF](https://www.nuget.org/packages/ODModelBuilderTF), [ODModelBuilderTF-Redist-Win](https://www.nuget.org/packages/ODModelBuilderTF-Redist-Win), [ODModelBuilderTF-Redist-Win-TF](https://www.nuget.org/packages/ODModelBuilderTF-Redist-Win-TF)\n* **Pytorch Yolo v5 train**: *work in progress...*\n\n## Examples\nThere is a an [examples directory](https://github.com/darth-vader-lg/MachineLearning/tree/master/examples) containing some simple demos.\nFor a more exhaustive usage cases it would be interesting to take a look in the [test set directory](https://github.com/darth-vader-lg/MachineLearning/tree/master/test) containing hundred of snippets and real application code of many models.\n\n### Below some code example snippets:\n**Object detection inference**\n```C#\nstatic void Main(string[] args)\n{\n   // Define the data\n   var modelFile = ExampleData.File(\n      root: \"Workspace\",\n      path: Path.Combine(\"ssd_mobilenet_v2_320x320_coco17_tpu-8\", \"saved_model\", \"saved_model.pb\"),\n      url: \"http://download.tensorflow.org/models/object_detection/tf2/20200711/ssd_mobilenet_v2_320x320_coco17_tpu-8.tar.gz\");\n   var imageFile = ExampleData.File(\n      root: \"Workspace\",\n      path: \"banana.jpg\",\n      url: \"https://github.com/darth-vader-lg/ML-NET/raw/056c60479304a3b5dbdf129c9bc6e853322bb090/test/data/images/banana.jpg\");\n\n   // Download the data\n   Console.WriteLine($\"Downloading the model...\");\n   var modelPath = modelFile.Get();\n   Console.WriteLine($\"Downloading the image...\");\n   var imagePath = imageFile.Get();\n\n   // Import the model\n   using var m = new ObjectDetection { ModelStorage = new ModelStorageMemory { ImportPath = modelPath } };\n\n   // Do predictions\n   var dets = m.GetPrediction(imagePath);\n\n   // Get the boxes, draw them on bitmap and save the marked bitmap\n   var boxes = dets.GetBoxes(minScore: dets.DetectionScores.Max() * 0.8);\n   using (var bmp = new Bitmap(Image.FromFile(imagePath))) {\n      // Draw the boxes\n      foreach (var box in boxes)\n         DrawBoxesOnBitmap(bmp, box);\n      // Save the marked image\n      var dest = Path.ChangeExtension(imagePath, null) + \".scored\" + Path.GetExtension(imagePath);\n      bmp.Save(dest);\n      // Print the results\n      Console.WriteLine($\"Found {boxes.Count} objects\");\n      foreach (var box in boxes)\n         Console.WriteLine($\"{box.Name} (id:{box.Id}) {box.Score * 100f:###.#}%\");\n      Console.WriteLine($\"The image has been saved in {dest}\");\n   }\n}\n```\n**Image classification train**\n```C#\nstatic void Main(string[] args)\n{\n   var euroSATImages = ExampleData.Folder(\n      Path.Combine(\"Workspace\"),\n      \"assets\",\n      \"https://github.com/dotnet/machinelearning-samples/raw/04076c5f95814a735dd5ecdb17fcb2052b3c3c45/samples/modelbuilder/ImageClassification_Azure_LandUse/assets.zip\");\n         \n   // Parameters\n   var numCategories = 5;\n   var trainImagesPerCategory = 20;\n   var testImagesPerCategory = 5;\n   var crossValidationFolds = 5;\n         \n   // Prepare the train folder with just a subset of the downloaded images\n   var trainImagesFolder = Path.Combine(\"Workspace\", \"TrainImages\");\n   if (Directory.Exists(trainImagesFolder))\n      Directory.Delete(trainImagesFolder, true);\n\n   // Take a random subset of the images\n   Console.WriteLine(\"Preparing the train environment...\");\n   var rnd = new Random(0);\n   var folders = Directory.GetDirectories(euroSATImages.Get()).OrderBy(f =\u003e rnd.Next()).ToArray();\n   var categories = new string[numCategories][];\n   for (var i = 0; i \u003c numCategories; i++) {\n      categories[i] = Directory.GetFiles(folders[i], \"*.jpg\").OrderBy(f =\u003e rnd.Next()).Take(trainImagesPerCategory + testImagesPerCategory).ToArray();\n      var dest = Path.Combine(trainImagesFolder, Path.GetFileName(folders[i]));\n      Directory.CreateDirectory(dest);\n      foreach (var image in categories[i].Take(trainImagesPerCategory))\n         File.Copy(image, Path.Combine(dest, Path.GetFileName(image)), true);\n   }\n\n   // Create the model\n   var model = new ImageClassification\n   {\n      DataStorage = new DataStorageBinaryMemory(),\n      ImagesSources = new[] { trainImagesFolder },\n      ModelStorage = new ModelStorageMemory(),\n      ModelTrainer = new ModelTrainerCrossValidation { NumFolds = crossValidationFolds },\n      Name = \"Custom train\"\n   };\n\n   // Log the messages\n   MachineLearningContext.Default.Log += (sender, e) =\u003e\n   {\n      // Filter trace messages but not about training phase \n      if (e.Kind \u003c MachineLearningLogKind.Info \u0026\u0026 !e.Message.Contains(\"Phase: Bottleneck Computation\") \u0026\u0026 !e.Message.Contains(\"Phase: Training\"))\n         return;\n      Console.WriteLine(e.Message);\n   };\n                                              \n   // Do predictions\n   var predictions = (from category in categories\n                        from file in category.Skip(trainImagesPerCategory).Take(testImagesPerCategory)\n                        select (File: file, Result: model.GetPrediction(file))).ToArray();\n\n   // Check predictions comparing the kind with the folder name containing the image\n   var wrongPrediction = predictions.Where(prediction =\u003e string.Compare(prediction.Result.Kind, Path.GetFileName(Path.GetDirectoryName(prediction.File)), true) != 0);\n   var rightPredictionPercentage = ((double)predictions.Length - wrongPrediction.Count()) * 100 / predictions.Length;\n   if (wrongPrediction.Count() \u003e 0) {\n      Console.WriteLine(\"Wrong predictions:\");\n      foreach (var prediction in wrongPrediction)\n         Console.WriteLine($\"Expected {Path.GetFileName(Path.GetDirectoryName(prediction.File))} for {Path.GetFileName(prediction.File)}, got {prediction.Result.Kind}\");\n   }\n   Console.WriteLine($\"Right results percentage: {rightPredictionPercentage:###.#}%\");\n}\n```\n**Smart dictionary**\n```C#\nstatic void Main(string[] args)\n{\n   // Create the dictionary\n   var dictionary = new SmartDictionary\u003cstring\u003e()\n   {\n      { \"this is a house\", \"house\" },\n      { \"this is a car\", \"car\" },\n      { \"this is a window\", \"window\" },\n   };\n\n   // Test set of keys\n   var similarKeys = new[]\n   {\n      \"these are houses\",\n      \"I see a car\",\n      \"It seems a broken window\"\n   };\n\n   // Query the dictionary\n   foreach (var key in similarKeys)\n      Console.WriteLine($\"dictionary[\\\"{key}\\\"] =\u003e {dictionary.Similar[key]}\");\n}\n```\n\n\n## Packages\n[LG.MachineLearning](https://www.nuget.org/packages/LG.MachineLearning): the machine learning library.\n\n## License\n\nML.NET is licensed under the [MIT license](LICENSE) and it is free to use commercially.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdarth-vader-lg%2Fmachinelearning","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdarth-vader-lg%2Fmachinelearning","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdarth-vader-lg%2Fmachinelearning/lists"}