Demo#

The demo for the project is in the form of a convolutional neural network which trains on the MNIST digit dataset. It uses only SimpleTensor’s tensors to build up the network, showing the purpose of this project and the power it has.

While it’s not fully implemented, SimpleTensor can practically be used to fully mimic a library like PyTorch or TensorFlow when trying to make a deep learning model, due to its vast array of differentiable operations. Also, if an operation is not defined, a program can simply create the gradient function and use the tensors as is.

Usage: An executable script is included in this package, provided you install the tqdm module. In the command line, you can simply run

simpletensor-train-mnist optional arguments here

These optional arguments can be seen by running

simpletensor-train-mnist -h

You can specify the learning rate for the Adam optimizer, the number of dense neurons in the intermediate dense layer, the number of filters in the convolutional layer, the path for all files to be created, the batch size for training and validation datasets, the number of epochs, the dropout value, and whether or not you want to use a GPU (if you have one, and it will default to true so the demo will use a GPU if you have CuPy installed).

This will need internet connection to download the MNIST dataset from an Amazon S3 bucket.

The model will be trained deterministically, and afterwards you can use the model to predict your own hand drawn digits. An OpenCV window will open which you can draw on. To reset the canvas, you can press R. To predict what you’ve drawn, you can press P. If you want to quit the program, you can press Q.

Here is a video of actually using the CLI script to run the MNIST training (sped up for convenience):

from IPython.display import Video

Video("training_video.mp4", embed=True, width=640, height=320)

This example used 32 convolutional filters, 5 epochs, \(\alpha=0.02\), and a batch size of 64. It was trained on a GPU. You can also see how the model predicts the user-drawn numbers. For the most part, it does fine, but the hand-drawn images are different from those in the dataset so it struggles sometimes.