Code Monkey home page Code Monkey logo

mnist-neural-network's Introduction

Simple MNIST Neural Network

Table of Contents

Overview

The project encompasses the implementation from the ground up of a simple feed-forward neural network, which is constructed solely using the NumPy library and trained on the MNIST dataset. As a result, the model is capable of recognizing hand-written digits. Additionally, the inclusion of a straightforward interactive GUI allows users to draw digits themselves and assess the model's accuracy.

Project Structure

  • main.py: The main script for initialization, training the network (or loading it), and interaction with the GUI.
  • utils.py: Helper functions for one-hot encoding, obtaining predictions, and calculating accuracy.
  • neural_network.py: Implementation of layers (Layer class) and the entire network (MNISTNeuralNetwork class), with methods for forward and backward propagation, training, evaluation, and model saving/loading.
  • gui.py: Simple interactive GUI for drawing digits and receiving predictions.
  • data_loader.py: Module for loading and processing data from the MNIST dataset. This module provides functionality for both downloading the dataset and loading it locally. It supports normalization and offers options for saving the dataset or reloading it anew each time the program is run.
  • activations.py: Contains activation functions (sigmoid, tanh, relu, linear, softmax) and their derivatives.

Installation

  1. Clone the repository:

    git clone https://github.com/jakub-krecisz/mnist-neural-network.git
  2. Install dependencies:

    pip install -r requirements.txt
  3. Sometimes an additional tool is needed without which the gui does not work

    • On Linux: Install Ghostscript using your system's package manager. For example, on Ubuntu, you can run sudo apt-get install ghostscript.
    • On macOS: Use Homebrew with brew install ghostscript.
    • On Windows: Download and install the Ghostscript executable from the official website: Ghostscript Downloads.

Usage

To get started, simply:

python main.py

By default, the loading of the MNIST dataset from the internet is implemented without saving, along with a sample implementation of a neural network, training (with all parameters set), and printing the model's accuracy, followed by testing on a sample. To use the GUI, simply uncomment:

gui = MNISTGui(model)
gui.start()

To save the loaded MNIST dataset during model loading, use:
custom_loader.load_mnist_data(save=True)

To avoid downloading the dataset each time when it's already locally available, use:
custom_loader.load_mnist_data(use_local=True)

To load a model from saved files, use:
model = MNISTNeuralNetwork.load_model('file_path/filename.csv', custom_loader)

To save a trained model, use:
MNISTNeuralNetwork.save_model(model, 'file_path/filename.csv')

Demo

demo_mnist

mnist-neural-network's People

Contributors

jakub-krecisz avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.