{"id":27923301,"url":"https://github.com/code-taweezy/udacity-image-classifier","last_synced_at":"2026-04-17T05:02:22.598Z","repository":{"id":291631891,"uuid":"978252861","full_name":"Code-Taweezy/udacity-image-classifier","owner":"Code-Taweezy","description":"Udacity AI Nanodegree project - Image Classifier built using PyTorch","archived":false,"fork":false,"pushed_at":"2025-05-05T18:05:43.000Z","size":1724,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-19T10:23:03.556Z","etag":null,"topics":["ai","image-classification","jupyter-notebooks","machine-learning","project","python","pytorch","udacity-nanodegree"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","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/Code-Taweezy.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,"zenodo":null}},"created_at":"2025-05-05T17:46:38.000Z","updated_at":"2025-05-05T18:10:03.000Z","dependencies_parsed_at":"2025-05-06T22:31:19.837Z","dependency_job_id":null,"html_url":"https://github.com/Code-Taweezy/udacity-image-classifier","commit_stats":null,"previous_names":["code-taweezy/udacity-image-classifier"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Code-Taweezy/udacity-image-classifier","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Code-Taweezy%2Fudacity-image-classifier","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Code-Taweezy%2Fudacity-image-classifier/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Code-Taweezy%2Fudacity-image-classifier/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Code-Taweezy%2Fudacity-image-classifier/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Code-Taweezy","download_url":"https://codeload.github.com/Code-Taweezy/udacity-image-classifier/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Code-Taweezy%2Fudacity-image-classifier/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31915900,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-16T18:22:33.417Z","status":"online","status_checked_at":"2026-04-17T02:00:06.879Z","response_time":62,"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":["ai","image-classification","jupyter-notebooks","machine-learning","project","python","pytorch","udacity-nanodegree"],"created_at":"2025-05-06T22:30:39.297Z","updated_at":"2026-04-17T05:02:22.580Z","avatar_url":"https://github.com/Code-Taweezy.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Create your own image classifier\n\n\u003e Final capstone that I worked on as part of the [AI programming in Python](https://www.udacity.com/course/ai-programming-python-nanodegree--nd089) nanodegree at Udacity. The aim of the project was to build an image classifier on the [102 Category Flower Dataset](https://www.robots.ox.ac.uk/~vgg/data/flowers/102/index.html), and then predict new flower images using the trained model.\n\n![This is an image taken from the Udacity website](images/header.png)\n\nThe project implements an image classification application. The application trains a deep learning model on a data set of images, then uses tha trained model to classify images. The code is first implemented in a Jupyter notebook.\n\n## Languages and tools\n\n## Goals of the project\n\n## Walk through: The classifier\n\n### Preparation of the Tensor data \u0026 label mapping\n\nTo make sure my neural network trained properly, I started the project by organising the training images in folders named as their class name. These were organised within training, testing and validation folders, as follows:\n\n```python\ndata_dir = 'flowers'\ntrain_dir = data_dir + '/train'\nvalid_dir = data_dir + '/valid'\ntest_dir = data_dir + '/test'\n```\n\nIt must be noted that the image folders names are not the actual names of the flowers in them, but rather numbers. Accordingly, Udacity provided a .json file, `cat_to_name.json`, which contained the mapping between flower names and folder labels. Basically, what will happen later on in the project is that my model will predict and return an index between 0 and 101, which corresponds to one of the folder labels (1-102). In turn, the folder labels (1-102) correspond to flower names that the .json file maps.\n\nI then adapted my images to work with the pre-trained networks of the torchvision library, which were trained on the ImageNet dataset. First, I defined transformations on the image data which included resizing these to 224x224 pixels. Subsequently, I created Torch Dataset objects using ImageFolder. This is done as follows:\n\n```python\n# loads the datasets using ImageFolder\ntrain_data = datasets.ImageFolder(data_dir + '/train', transform=train_transforms)\ntest_data = datasets.ImageFolder(data_dir + '/test', transform=test_transforms)\nvalid_data = datasets.ImageFolder(data_dir + '/valid', transform=test_transforms)\n```\n\nFinally, I created Data Loader objects to make sure I could work on my data. \n\n### Upload of the pre-trained model and preparation of the classifier\n\nThe fully-connected layer that I then trained on the flower images was as follows:\n\n```python\nclassifier = nn.Sequential(OrderedDict([\n                          ('fc1', nn.Linear(25088, hidden_units)),\n                          ('relu', nn.ReLU()),\n                          ('dropout1', nn.Dropout(0.05)),\n                          ('fc2', nn.Linear(hidden_units, no_output_categories)),\n                          ('output', nn.LogSoftmax(dim=1))\n                          ]))\n```\n\nI chose to work with a highly accurate Convolutional Network, VGG16, which is abysmally slow to train (in my case, about 30 minutes per epoch). Note that I had previously defined the `hidden_units` as being 4096, while `no_output_categories` corresponds to the length of `cat_to_name.json`, i.e. 102.\n\n### Training and testing the network\n\nTo train the network, I had to set the hyperparameters for the training (i.e. epochs, learning rate, etc.). I chose to work with 10 epochs to avoid overfitting. The code loops through each epoch, trains 20 batches at at time (1 batch corresponds to 64 images), and tests the model's progress on the validation data. At the end, the training and validation metrics are printed.\n\nAt this point, I had to go back to using Udacity's GPU because training the model locally proved impossible. The file developed on the Udacity portal is `image_classifier_project_GPU.ipynb`. I copy below the training results for the last epoch:\n\n```python\nEpoch 10/10 | Batch 20\nRunning Training Loss: 0.530\nRunning Training Accuracy: 100.99%\nValidation Loss: 0.271\nValidation Accuracy: 94.23%\n\nEpoch 10/10 | Batch 40\nRunning Training Loss: 0.413\nRunning Training Accuracy: 88.59%\nValidation Loss: 0.246\nValidation Accuracy: 95.31%\n\nEpoch 10/10 | Batch 60\nRunning Training Loss: 0.412\nRunning Training Accuracy: 88.36%\nValidation Loss: 0.338\nValidation Accuracy: 92.67%\n\nEpoch 10/10 | Batch 80\nRunning Training Loss: 0.431\nRunning Training Accuracy: 87.66%\nValidation Loss: 0.323\nValidation Accuracy: 93.03%\n\nEpoch 10/10 | Batch 100\nRunning Training Loss: 0.456\nRunning Training Accuracy: 87.81%\nValidation Loss: 0.317\nValidation Accuracy: 93.08%\n```\n\nI set aside test data that the model had never been exposed to in order to see how it performed. The very satisfactory results are shown in the image below (the aim was to score about 70%):\n\n![This is an image of the test results](images/test.png)\n\nI then created two functions to save the checkpoint in a .pth file, and load it when necessary.\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcode-taweezy%2Fudacity-image-classifier","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcode-taweezy%2Fudacity-image-classifier","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcode-taweezy%2Fudacity-image-classifier/lists"}