codeburst

Bursts of code to power through your day. Web Development articles, tutorials, and news.

Follow publication

Handwriting Recognition using ML.NET

Machine learning in .NET

Changhui Xu
codeburst
Published in
10 min readDec 10, 2019

--

Handwriting recognition — ML.NET

ML.NET is a cross-platform machine learning framework which provides state-of-the-art machine learning algorithms, transforms, and components. ML.NET allows .NET developers to develop/train models and integrate machine learning with their .NET applications, even without prior expertise in fine-tuning machine learning models.

In this blog post, we will make a web application to recognize handwritten numbers using ML.NET. The demo web app (link) is running in a Linux container, which demonstrates the cross-platform capability of ML.NET and ASP.NET Core. You can find the complete solution in this GitHub repository.

In the demo web app, we can draw a single digit number [0–9] on the canvas via mouse or touch. Then we make an API call which returns the prediction result of the number based on the canvas image drawn in the web page. The following screen recording shows some handwriting predictions made by the web app.

handwriting digits recognition

The meaty part of the web app is the API endpoint which predicts handwritten numbers using a pre-trained ML.NET model. In the following sections, we will focus on how to build a machine learning model from a training data set, and how to serve the trained model in an ASP.NET Core Web API. At the end of this blog post, I summarize some learning materials for beginners.

Obtain the MNIST optdigits Training Data Set

The GitHub repository for ML.NET Samples (link) contains some common data sets. We can download the MNIST data set for handwritten digits from this location. The data set contains thousands of handwritten digits in CSV format. We save the optdigits-train.csv (training data set) and the optdigits-test.csv (testing data set) files in a Data folder for later usage.

It is important to understand our data before we proceed to the machine learning process, because we need to prepare API requests with image data in the same format (a.k.a. schema) as that of the training data set in order to make predictions.

--

--

Published in codeburst

Bursts of code to power through your day. Web Development articles, tutorials, and news.

Written by Changhui Xu

Lead Application Developer. MBA. I write blogs about .NET, Angular, JavaScript/TypeScript, Docker, AWS, DDD, and many others.

Responses (1)

Write a response