Skip to content

A handcrafted convolutional neural network. Matrix multiplication instead of loop operation, very fast.

License

Notifications You must be signed in to change notification settings

Avafly/Handcrafted-CNN

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Handcrafted-CNN

A handcrafted CNN implementation using NumPy for matrix operations instead of loops, very fast, can use 100% usage of CPU for computation.

The model is defined in model_config.json, and you can edit it to build various architectures, just like TensorFlow's Sequential. Detailed comments are provided in nn_layers.py, you can clearly understand how each layer propagates, updates, and initializes from the comments.

This repo is inspired by my undergrad project. The training speed was improved by 60x after refactoring the code.

Available Layers

Conv, FullyConnected, MaxPool, AvgPool, ReLU, LeakyReLU, BatchNorm2D, BatchNorn1D, Softmax, CrossEntropy

How to run

  1. Create a virtual env and install dependencies:

    pip install tensorflow matplotlib scikit-image
    • TensorFlow here is only used to download the MNIST dataset.
  2. Start training:

    python3 main.py

Demo

Training

training

Evaluation

After training, the model is evaluated using test data.

test

If plot_sample_prediction == True, a sample prediction plot will be generated after the testing is completed.

test_result

CPU usage

training

About

A handcrafted convolutional neural network. Matrix multiplication instead of loop operation, very fast.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages