{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Demo" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The demo for the project is in the form of a convolutional neural network\n", "which trains on the MNIST digit dataset. It uses only SimpleTensor's tensors\n", "to build up the network, showing the purpose of this project and the power\n", "it has.\n", "\n", "While it's not fully implemented, SimpleTensor can practically be used to fully\n", "mimic a library like PyTorch or TensorFlow when trying to make a deep learning\n", "model, due to its vast array of differentiable operations. Also, if an operation\n", "is not defined, a program can simply create the gradient function and use the tensors\n", "as is.\n", "\n", "Usage:\n", "An executable script is included in this package, provided you install the tqdm\n", "module. In the command line, you can simply run\n", "\n", " simpletensor-train-mnist optional arguments here\n", "\n", "These optional arguments can be seen by running\n", "\n", " simpletensor-train-mnist -h\n", "\n", "You can specify the learning rate for the Adam\n", "optimizer, the number of dense neurons in the intermediate dense layer,\n", "the number of filters in the convolutional layer, the path for all files\n", "to be created, the batch size for training and validation datasets, the\n", "number of epochs, the dropout value, and whether or not you want to use a GPU (if you have one,\n", "and it will default to true so the demo will use a GPU if you have CuPy installed).\n", "\n", "This will need internet connection to download the MNIST dataset from an \n", "Amazon S3 bucket.\n", "\n", "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`." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Here is a video of actually using the CLI script to run the MNIST training (sped up for convenience):" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from IPython.display import Video\n", "\n", "Video(\"training_video.mp4\", embed=True, width=640, height=320)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.4" }, "widgets": { "application/vnd.jupyter.widget-state+json": { "state": {}, "version_major": 2, "version_minor": 0 } } }, "nbformat": 4, "nbformat_minor": 2 }