2025.NET · ML

Drawings Identifier

A desktop application that classifies hand-drawn sketches in real time, built on a custom neural network library written from scratch in C#.

Drawings Identifier screenshot

Overview

Drawings Identifier is a Windows desktop application that classifies user-drawn sketches in real time. Each drawing is assigned to one of nine classes from Google's Quick, Draw! dataset: axe, cactus, cat, diamond, moustache, pants, snowman, stairs and sword.

The application does not rely on any existing machine learning framework. All networks are created, trained and evaluated with ToyNeuralNetwork, a neural network library implemented from scratch for this project and published as a NuGet package.

Features

Real-time classification

The sketching window provides a canvas with a pen, an eraser and a clear tool. While the user draws, two independent neural networks classify the sketch and display their predictions side by side.

Network configuration

Two configuration windows allow the user to design both networks without writing code. The upper panel sets the training parameters used by the Trainer class, which are applied immediately. The lower panel defines the network structure layer by layer: fully connected, convolutional, max pooling and dropout layers, each with its own parameters. Structural changes are applied only on explicit save, since modifying the architecture discards training progress.

Network configuration

Training and evaluation

Both networks can be trained at the same time. Progress is reported by two progress bars, one for samples within the current epoch and one for epochs overall, together with the average error of the last batch. Navigation between views is locked while training is running. After training stops, the application computes accuracy on the training and test sets. Networks can be saved to and loaded from XML files.

Training a network

Data loading

The data loading window imports Quick, Draw! samples from .npy files. The user selects the source folder and the number of drawings to load per class. Once loading completes, the window displays a random selection of samples, showing what kind of input the networks expect.

Loaded dataset samples

Results

The repository includes two pre-trained example networks, both operating on 28x28 greyscale drawings:

NetworkArchitectureTrain acc.Test acc.
Feed-forward784 → 128 → 128 → 9 (ReLU, softmax)81.3%79.5%
ConvolutionalConv 16@5x5 → Conv 32@3x3 → dense → 991.1%88.9%

The addition of two convolutional layers increases test accuracy by approximately 9 percentage points, which illustrates why convolutional networks are the standard choice for image classification.

ToyNeuralNetwork library

ToyNeuralNetwork is a .NET 8 class library that exposes a high-level interface for building and training multilayer perceptrons and convolutional networks. It implements its own Matrix type and all underlying operations, including convolution, pooling and activation functions (ReLU, sigmoid, softmax). The final layer is always fully connected with softmax, and the error is computed with cross-entropy. External dependencies are limited to NumSharp for reading .npy files and ImageSharp for image processing.

The library is organised into five modules: mathematics, image processing, utilities, Quick, Draw! data handling and neural networks.

Library structure

Usage

The library is available on NuGet:

dotnet add package ToyNeuralNetwork

A network is defined as an array of LayerTemplate objects and created from the input shape (depth, rows, columns):

LayerTemplate[] templates = [
    LayerTemplate.CreateConvolutionLayer(kernelSize: 5, depth: 12, activationFunction: ActivationFunction.ReLU),
    LayerTemplate.CreateMaxPoolingLayer(poolSize: 2, stride: 2),
    LayerTemplate.CreateDropoutLayer(dropoutRate: 0.5f),
    LayerTemplate.CreateFullyConnectedLayer(layerSize: 64, activationFunction: ActivationFunction.ReLU),
    LayerTemplate.CreateFullyConnectedLayer(layerSize: 9, activationFunction: ActivationFunction.Softmax)
];

var nn = new NeuralNetwork(inputDepth: 1, inputRowsAmount: 28, inputColumnsAmount: 28, layerTemplates: templates);

Training data is a collection of (Matrix[] input, Matrix expected) pairs. The network is trained with Train, or with TrainOnNewTask to run on a separate task:

nn.Train(data: data, learningRate: 0.01f, epochAmount: 30, batchSize: 50);

The trained network can then be used for prediction, evaluated and saved:

Matrix prediction = nn.Predict([sample]);
float correctness = nn.CalculateCorrectness(testData: testData);
nn.SaveToXmlFile(path: "network.xml", testCorrectness: correctness);

For more control, the Trainer class adds automatic learning-rate reduction when the error stops decreasing, and logs training progress, per-class accuracy and the trained network to files. The full developer guide is available in the repository.

View code on GitHub
Next project Tetris DQL →