1. Manual
1.1 Installation
To install the package, run the command pip install digit_recognition in the command prompt (windows) or terminal (mac) (alternative: download the package and run the setup.py script with python setup.py install).
The package uses the following dependencies: numpy, urllib3, gzip, tkinter, Pillow. These should be installed automatically during the installation if necessary. If the package does not run as intended, please ensure that the dependencies listed here have been installed correctly.
1.2 Setting up the NN
The package does not include a trained NN, but only the necessary functions to build it. Therefore, prior to using the interface, the NN has to be set up (this has only to be done once). To do so, run the command install_network in the command prompt/terminal (alternative: import the ‘digit_recognition’ module in python and call the install_network() function).
This creates a folder in the current directory (“DR_Data”) and downloads training and test sets from the MNIST database to this folder. It uses this data to train a NN with 784, 200, 100, and 10 nodes in each of four layers, respectively. The training algorithm goes through three epochs each with 60.000 training digits (this may take a few minutes). The NN is evaluated and the accuracy as well as the recall and precision for each digit are printed to the console (important: accuracy should be above 95%). Finally, the NN is saved to the “DR_Data” folder.
1.3 Starting up the interface
To start the interface, run the command digit_recognition in the command prompt/terminal (alternative: import the ‘digit_recognition’ module in python and call the run_gui() function).
Important: Ensure that the “DR_Data” folder is located in the current working directory.
1.4 Using the interface
The interface consists of two fields: a drawing field framed in black (left) and a feedback field showing several outputs (right). The user can draw in the drawing field by pressing the left mouse button and moving the mouse. Located below the drawing field are two buttons: the “Recognize!” button passes the drawing to the NN and displays its output in the feedback field; The “Reset” button deletes the current drawing and output. In the feedback field, three outputs are displayed: first, the digit recognized by the NN in the user’s drawing; second, the confidence of this recognition (i.e. the probability that the recognition is correct); and third, a possible alternative (i.e. the second most likely recognition). If the confidence is above 80%, no alternative is displayed.
Important: The performance of the NN is highly sensitive to size and location of the user’s digit in the drawing field. The grey rectangle in the drawing field indicates location and size for optimal performance.
2. Documentation
2.1 NeuralNetwork (class)
-
__init__(self, design, weights=None, step_size=0.01, activation_function=sigmoid, bias=False) Set up basic attributes of neural network.
Attributes ---------- design: list Contains the number of nodes in each layer (length is number of layers) weights: list Contains weight matrices step_size: float Step size for training algorithm activation_function: function Activation function used in neural network bias: boolean Bias nodes on or off activation: list Contains activation of nodes at each layer confusion_matrix: np.array Confusion matrix produced in 'evaluate' method (true labels in rows, predicitons in columns) accuracy, recall, precision: float Accuracy, recall, and precision of neural network produced in 'evaluate' method Methods ------- train(input_data, target_data, epochs=1) Loops of 'one_training' function one_training(input_data, target_data) Computes cost and updates weights accordingly using backpropagation run(input_data) Forward propagation for single input evaluate(input_data, target_data) Assesses performance of neural network and computes performance measures save(file_name) Saves weights of neural network as np.array -
train(self, input_data, target_data, epochs=1) Loop for 'one_train' (backpropagation) function (see below).
Arguments --------- input_data: array 3-dimensional numpy array containing input data (see pre_processing function for exact format). target_data: array 2-dimensional numpy array containing target data in one-hot representation. epochs: int Number of times the training algorithms iterates through the *entire* dataset. Defaults to 1. -
one_training(self, input_data, target_data) Backpropagation algorithm to train neural network.
Arguments --------- input_data: array 2-dimensional numpy array containing a single input. Passed by train function (see above). target_data: array 2-dimensional numpy array containing a single target. Passed by train function (see above). -
run(self, input_data) Forward propagation algorithm.
Computes output of neural network for a single input. Arguments --------- input_data: array 2-dimensional numpy array containing a single input. -
evaluate(self, input_data, target_data) Evaluates performance of neural network. Computes accuracy of neural network, as well as recall and precision for each class using a confusion matrix. Results are printed to the console, but also defined as attributes of the neural network. Note: Use independent test data!
Arguments --------- input_data: array 3-dimensional numpy array containing test input data. target_data: array 2-dimensional numpy array containing test target data in one-hot representation. -
save(self, file_name) Saves weights of neural network as np.array
Arguments --------- file_name: string Name of the file that is saved (without file extension)
2.2 Pre-processing (function)
-
pre_processing( ) Downloads, imports and preprocess data for digit recognition. Data is downloaded from the MNIST database. Consists of 70.000 handwritten digits of 28x28 pixels. Each with a corresponding, manually added label. Data is split into 60.000 instances for training and 10.000 instances for testing.
Returns: Matrix representations of digits and correspondings labels in a format optimized for the neural network.
3. Example
# Import data
train_images, train_labels, test_images, test_labels = pre_processing()
# Build neural network (with two hidden layers of 200/100 nodes respectively)
neural_network = NeuralNetwork([784,200,100,10], bias=True)
neural_network.train(train_images, train_labels, epochs=3)
neural_network.evaluate(test_images, test_labels)
# Export neural network
os.chdir('DR_Data')
neural_network.save('my_network')
os.chdir('..')
Metadata
Release files for digit-recognition 0.0.11
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| digit_recognition-0.0.11.tar.gz | 9.3 kB | Without provenance | Details for digit_recognition-0.0.11.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| digit_recognition-0.0.11-py3-none-any.whl | Python 3 | none | any | Details for digit_recognition-0.0.11-py3-none-any.whl |
Total release size: 23.4 kB
Release files / digit_recognition-0.0.11.tar.gz
| Download URL | digit_recognition-0.0.11.tar.gz |
|---|---|
| Size | 9.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a5f3a5512a16c92c19d6c4cdaaed3b8f5170c946aeb54ba95af9d1ada983d12b
|
|
BLAKE2b-256 checksum How to use checksums |
41dde34456c7ea08f77d0335acdd7edc38d0dc60e6fbec8569b94e23eb50a555
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.4.2 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.1
|
Release files / digit_recognition-0.0.11-py3-none-any.whl
| Download URL | digit_recognition-0.0.11-py3-none-any.whl |
|---|---|
| Size | 14.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
382931554173c01ca4376c09e7bb0e64b45266f420d32f02f4186a00cf2b09e4
|
|
BLAKE2b-256 checksum How to use checksums |
203d38a7cebea5623fb0566869af245015e1cb3b222ad57c7d93e26b441505ad
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.4.2 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.1
|
Security for digit-recognition 0.0.11
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.