{"id":18742838,"url":"https://github.com/kmr0877/digit-recognition","last_synced_at":"2026-05-02T02:31:58.271Z","repository":{"id":135772383,"uuid":"100319224","full_name":"kmr0877/Digit-Recognition","owner":"kmr0877","description":"Implementation of CNNs for handwritten digit recognition ","archived":false,"fork":false,"pushed_at":"2017-09-18T02:21:53.000Z","size":27,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-05-20T06:08:41.164Z","etag":null,"topics":["convolutional-neural-networks","deep-learning","deep-learning-algorithms","deep-neural-networks","mnist","mnist-classification","mnist-dataset","mnist-handwriting-recognition","mnist-image-dataset","python3","recurrent-neural-networks","tensorflow"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kmr0877.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-08-14T23:54:52.000Z","updated_at":"2017-09-18T01:55:56.000Z","dependencies_parsed_at":null,"dependency_job_id":"e398a1ba-dc6c-4707-8b15-016c95556d0c","html_url":"https://github.com/kmr0877/Digit-Recognition","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/kmr0877/Digit-Recognition","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kmr0877%2FDigit-Recognition","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kmr0877%2FDigit-Recognition/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kmr0877%2FDigit-Recognition/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kmr0877%2FDigit-Recognition/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kmr0877","download_url":"https://codeload.github.com/kmr0877/Digit-Recognition/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kmr0877%2FDigit-Recognition/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32520835,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-02T01:12:54.858Z","status":"online","status_checked_at":"2026-05-02T02:00:05.923Z","response_time":132,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["convolutional-neural-networks","deep-learning","deep-learning-algorithms","deep-neural-networks","mnist","mnist-classification","mnist-dataset","mnist-handwriting-recognition","mnist-image-dataset","python3","recurrent-neural-networks","tensorflow"],"created_at":"2024-11-07T16:09:22.428Z","updated_at":"2026-05-02T02:31:58.250Z","avatar_url":"https://github.com/kmr0877.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Digit-Recognition\n\nCOMP9444 Neural Networks and Deep Learning\n\nSession 2, 2017\n\nProject 1 - Digit Recognition\n\n## _Introduction_\n\nIn this assignment, you will be implementing a single layer network, a two layer network and a convolutional network to classify handwritten digits. you will work with the MNIST dataset, a common dataset used to evaluate Machine Learning models.\nPreliminaries\n\nBefore commencing this assignment, you should download and install TensorFlow, and the appropriate python version. It is also helpful to complete the 'MNIST for beginners' tutorial located on the TensorFlow website https://www.tensorflow.org/get_started/mnist/beginners\nTensorFlow (TF) is an opensource library primarily used to construct, train and evaluate machine learning models. TF allows rapid development and supports automatic differentiation - meaning backprop is able to be done automatically for any model adequately defined. TF also abstracts away much of the low-level code required to set up training on GPU's; in many cases TF will automatically detect and utilize your computer's GPU if it has one. Central to the design of TF is the concept of a 'graph' - a low level representation of a model consisting of nodes and tensors. Broadly, implementing a TF model can be broken down into two sections; creating the graph, and training/testing it. This assignment is mainly concerned with graph creation. You can read more about the general structure of TensorFlow here.\n\nGetting Started\n\nYou will see two files: train.py  and  hw1.py\nNow run  train.py  by typing\n\npython3 train.py\nWhen run for the first time,  train.py  should create a new folder called  data  and download a copy of the MNIST dataset into this folder. All subsequent runs of  train.py  will use this local data. (Don't worry about the  ValueError  at this stage.)\nThe file  train.py  contains the TensorFlow code required to create a session, build the graph, and run training and test iterations. It has been provided to assist you with the testing and evaluation of your model. \n\nThe file  train.py  calls functions defined in hw1.py  and should not be modified during the course of the assignment.  The only situation where you should modify  train.py  is when you need to switch between different network architectures. This can be done by setting the global variable on line 7:\n\nnetwork = \"none\"\nto any of the following values:\nnetwork = \"onelayer\"\nnetwork = \"twolayer\"\nnetwork = \"conv\"\nThe file  hw1.py  contains function definitions for the three networks to be created. You may also define helper functions in this file if necessary, as long as the original function names and arguments are not modified. Changing the function name, argument list, or return value will cause all tests to fail for that function. Your marks will be automatically generated by a test script, which will evaluate the correctness of the implemented networks. For this reason, it is important that you stick to the specification exactly. \n\n## _Stage 0: Provided Code_\n\nThe functions  input_placeholder()  and target_placeholder()  specify the inputs and outpus of your networks in the TensorFlow graph. They have been implemented for you.\nIn addition, there is a function  train_step()  that passes batches of images to the constructed TensorFlow Graph during training. It's implementation should help you understand the shape and structure of the actual data that is being provided to the model.\n\nUnless otherwise specified, the underlying type (dtype) for each TF object should be  float32.  INPUT_SIZE, where it appears in comments, refers to the length of a flattened single image; in this case 784.  OUTPUT_SIZE, where it appears in comments, refers to the length of a one-hot output vector; in this case 10.\n\nIn the provided file  hw1.py, detailed specifications are provided in the comments for each function.\n\n## _Stage 1: Single-Layer Network_\n\nWrite a function  onelayer(X, Y, layersize=10)  which creates a TensorFlow model for a one layer neural network (sometimes also called logistic regression). Your model should consist of one fully connected layer with weights w  and biases  b, using softmax activation.\nYour function should take two parameters  X  and  Y that are TensorFlow placeholders as defined in  input_placeholder()  and target_placeholder(). It should return varibles  w, b, logits, preds, batch_xentropy  and  batch_loss, where:\n\n w  and  b  are TensorFlow variables representing the weights and biases, respectively\n logits  and  preds  are the input to the activation function and its output\n xentropy_loss  is the cross-entropy loss for each image in the batch\n batch_loss  is the average of the cross-entropy loss for all images in the batch\nChange line 7 of  train.py  to network = \"onelayer\" and test your network on the MNIST dataset by typing\npython3 train.py\nIt should achieve about 92% accuracy after 5 epochs of training.\n\n\n## _Stage 2: Two-Layer Network_\n\nCreate a TensorFlow model for a Neural Network with two fully connected layers of weights  w1, w2  and biases  b1, b2, with ReLU activation functions on the first layer, and softmax on the second. Your function should take two parameters  X  and  Y that are TensorFlow placeholders as defined in  input_placeholder()  and target_placeholder(). It should return varibles  w1, b1, w2, b2, logits, preds, batch_xentropy  and  batch_loss, where:\n w1  and  b1  are TensorFlow variables representing the weights and biases of the first layer\n w2  and  b2  are TensorFlow variables representing the weights and biases of the second layer\n logits  and  preds  are the inputs to the final activation functions and their output\n xentropy_loss  is the cross-entropy loss for each image in the batch\n batch_loss  is the average of the cross-entropy loss for all images in the batch\nChange line 7 of  train.py  to network = \"twolayer\" and test your network on the MNIST dataset by typing\npython3 train.py\n\n## _Stage 4: Convolutional Network_\n\nCreate a TensorFlow model for a Convolutional Neural Network. This network should consist of two convolutional layers followed by a fully connected layer of the form:\nconv_layer1 → conv_layer2 → fully-connected → output\nYour function should take two parameters  X  and  Y that are TensorFlow placeholders as defined in  input_placeholder()  and target_placeholder(). It should return varibles  conv1, conv2, w, b, logits, preds, batch_xentropy  and  batch_loss, where:\n conv1  is a convolutional layer of  convlayer_sizes[0]  filters of shape  filter_shape\n conv2  is a convolutional layer of  convlayer_sizes[1]  filters of shape  filter_shape\n w  and  b  are TensorFlow variables representing the weights and biases of the final fully connected layer\n logits  and  preds  are the inputs to the final activation functions and their output\n xentropy_loss  is the cross-entropy loss for each image in the batch\n batch_loss  is the average of the cross-entropy loss for all images in the batch\n\nHints:\n\nuse tf.layer.conv2d\nthe final layer is very similar to the  onelayer  network, except that the input will be from the  conv2  layer. If you reshape the  conv2  output using  tf.reshape, you should be able to call  onelayer()  to get the final layer of your network\nChange line 7 of  train.py  to network = \"conv\" and test your network on the MNIST dataset by typing\npython3 train.py\nIt may take several minutes to run, depending on your processor.\n\n## _Notes_\n\nAll TensorFlow objects, if not otherwise specified, should be explicity created with  tf.float32  datatypes. Not specifying this datatype for variables and placeholders will cause your code to fail some tests.\nTensorFlow provides multiple API's, at various levels of abstraction. For the specified functionality in this assignment, there are generally high level TensorFlow library calls that can be used. As we are assessing TensorFlow, functionality that is technically correct but implemented manually, using a library such as  numpy, will fail tests. If you find yourself writing 50+ line methods, it may be a good idea to look for a simpler solution.\n\n## _Visualizing Your Models_\n\nIn addition to the output of  train.py, you can view the progress of your models and the created TensorFlow graph using the TensorFlow visualization platform, TensorBoard. After beginning training, run the following command from the src directory:\npython3 -m tensorflow.tensorboard --logdir=./summaries\nDepending on your installation, the following command might also work:\ntensorboard --logdir=./summaries\nopen a Web browser and navigate to  http://localhost:6006\nyou should be able to see a plot of the train and test accuracies in TensorBoard\nif you click on the histogram tab you'll also see some histograms of your weights, biases and the pre-activation inputs to the softmax in the final layer\nMake sure you are in the same directory from which train.py is running. Don't worry if you are unable to get TensorBoard working; it is not required to complete the assignment, but it can be a useful tool to monitor training, so it is probably worth your while becoming familiar with it. Click here for more information:\n\n# _Sample Interaction_\n\nSingle Layer\n\n\u003cimg width=\"682\" alt=\"screen shot 2017-09-04 at 4 42 09 pm\" src=\"https://user-images.githubusercontent.com/26761582/30014545-2f5b5970-9190-11e7-80b0-0418d1a597f6.png\"\u003e\n\nTwo Layer Network\n\n\u003cimg width=\"682\" alt=\"screen shot 2017-09-04 at 4 46 28 pm\" src=\"https://user-images.githubusercontent.com/26761582/30014627-a1b794d4-9190-11e7-8235-2c5bb9caf7c8.png\"\u003e\n\nConv Layer\n\n\u003cimg width=\"682\" alt=\"screen shot 2017-09-04 at 4 57 21 pm\" src=\"https://user-images.githubusercontent.com/26761582/30015429-0835feb4-9194-11e7-9060-05f7d04e650b.png\"\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkmr0877%2Fdigit-recognition","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkmr0877%2Fdigit-recognition","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkmr0877%2Fdigit-recognition/lists"}