{"id":17831129,"url":"https://github.com/dragonxdev/pytorch-mnist-nn","last_synced_at":"2025-08-12T12:34:35.135Z","repository":{"id":237829910,"uuid":"795318918","full_name":"DragonXDev/pytorch-mnist-nn","owner":"DragonXDev","description":"A neural network designed to convert handwritten digits into their numerical value.","archived":false,"fork":false,"pushed_at":"2024-05-09T17:14:36.000Z","size":25524,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-25T00:35:23.818Z","etag":null,"topics":["machine-learning","mnist","neural-network","pytorch"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DragonXDev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2024-05-03T02:52:29.000Z","updated_at":"2024-05-05T00:20:28.000Z","dependencies_parsed_at":null,"dependency_job_id":"aeb91bec-9f6b-4854-8328-d9a24b7fac1e","html_url":"https://github.com/DragonXDev/pytorch-mnist-nn","commit_stats":null,"previous_names":["dragonxdev/pytorch-mnist-nn"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/DragonXDev/pytorch-mnist-nn","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DragonXDev%2Fpytorch-mnist-nn","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DragonXDev%2Fpytorch-mnist-nn/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DragonXDev%2Fpytorch-mnist-nn/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DragonXDev%2Fpytorch-mnist-nn/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DragonXDev","download_url":"https://codeload.github.com/DragonXDev/pytorch-mnist-nn/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DragonXDev%2Fpytorch-mnist-nn/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270061612,"owners_count":24520328,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-12T02:00:09.011Z","response_time":80,"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":["machine-learning","mnist","neural-network","pytorch"],"created_at":"2024-10-27T19:41:11.324Z","updated_at":"2025-08-12T12:34:35.117Z","avatar_url":"https://github.com/DragonXDev.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MNIST PyTorch Neural Network\r\n\r\nA MNIST CNN developed to recognize handwritten digits; grayscale input channel of 1 accepted, ```1x28x28``` input.\r\n\r\n![image](https://github.com/DragonXDev/pytorch-mnist-nn/assets/99859617/f77a5f9d-09bd-4624-bb14-cf64ca919dd3)\r\n\r\n\r\n## Usage \u0026 Information\r\nThe CNN is trained in batches of ```32``` from the DB. Each of the 32 filters is a 2D ```3x3``` and extracted from the ```1x28x28```\r\n\r\nA Visual of an MNIST CNN\r\n\r\n![image](https://github.com/DragonXDev/pytorch-mnist-nn/assets/99859617/0f4a9be1-07e3-4632-9048-8a741a7fdeef)\r\n\r\nTo train the CNN, \r\n\r\n```bash\r\npoetry run python src/train_model.py\r\n```\r\n\r\nThis will contact the MNIST DB \u0026 run 10 epochs to train the model. The appropriate state after the model is finished executing will be created\r\nas the ```digital_model.pt``` file.\r\n\r\nOnce completed, run the model with the binary generated using\r\n\r\n```bash\r\npoetry run python src/main.py\r\n```\r\n\r\n## Optimizers\r\n\r\nFor the purpose of MNIST, the Adam optimizer with ```lr=1e-3``` performs best\r\n\r\n![image](https://github.com/DragonXDev/pytorch-mnist-nn/assets/99859617/8ac61337-e8e0-45aa-9383-35fb368731fa)\r\n\r\n### Adam\r\n\r\nStarting with Stochastic Gradient Descent\r\n\r\n```math\r\ng = \\frac{1}{m} \\nabla_{\\theta}\\sum_{i}L(f(x^{(i)};\\theta),y^{(i)})\r\n```\r\nWhere $\\theta$ is the models' params, $g$ is the negative direction of the gradient, $m$ is the size of the mini-batches of data, $f(x^{(i)}; \\theta)$ is the neural network, $x^{(i)}$ is the training data, $y^{(i)}$ are the training labels, and $L()$ is the loss function.\r\n\r\nThe Adam optimizer redefines SGD's params as such:\r\n\r\n```math\r\nm = \\beta_{1}m + (1-\\beta_{1})g\r\n```\r\n```math\r\ns = \\beta_{2}s + (1-\\beta_{2})g^{T}g\r\n```\r\n```math\r\n\\theta = \\theta - \\epsilon_{k}\\cdot\\frac{m}{\\sqrt{s+eps}}\r\n```\r\n\r\nFor this project, $\\beta_{1} = 0.9$, $\\beta_{2} = 0.999$, and $eps$ (learning rate) $=$ 1e-3.\r\n\r\n### Nesterov Momentum $\\nabla$\r\n\r\nNesterov's Momentum Acceleration $\\nabla$ (NAG) performs significantly worse than Adam.\r\n\r\n```math\r\n\\nu = \\alpha\\nu - \\epsilon\\nabla_{\\theta}(\\frac{1}{m}\\sum_{i}L(f(x^{(i)};\\theta+\\alpha\\cdot\\nu),y^{(i)})\r\n```\r\n```math\r\n\\theta = \\theta + \\nu\r\n```\r\n\r\nThe loss / cost after ```Epoch 10``` ended at ~ ```0.01253``` on average.\r\n\r\n## Contributors\r\n\r\nI am the sole contributor of this project.\r\n\r\n## License\r\n\r\nThis project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md)\r\n\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdragonxdev%2Fpytorch-mnist-nn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdragonxdev%2Fpytorch-mnist-nn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdragonxdev%2Fpytorch-mnist-nn/lists"}