{"id":15906791,"url":"https://github.com/logancyang/traffic-sign-classifier","last_synced_at":"2025-04-02T23:26:25.241Z","repository":{"id":71209237,"uuid":"89202996","full_name":"logancyang/traffic-sign-classifier","owner":"logancyang","description":"Udacity SDCND: Traffic sign recognition for self-driving cars","archived":false,"fork":false,"pushed_at":"2017-05-07T04:47:11.000Z","size":17175,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-08T13:42:57.198Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","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/logancyang.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":"2017-04-24T05:57:23.000Z","updated_at":"2017-08-15T21:29:07.000Z","dependencies_parsed_at":"2023-03-16T20:00:39.345Z","dependency_job_id":null,"html_url":"https://github.com/logancyang/traffic-sign-classifier","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/logancyang%2Ftraffic-sign-classifier","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/logancyang%2Ftraffic-sign-classifier/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/logancyang%2Ftraffic-sign-classifier/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/logancyang%2Ftraffic-sign-classifier/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/logancyang","download_url":"https://codeload.github.com/logancyang/traffic-sign-classifier/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246907976,"owners_count":20853170,"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","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":[],"created_at":"2024-10-06T13:41:46.284Z","updated_at":"2025-04-02T23:26:25.225Z","avatar_url":"https://github.com/logancyang.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# **Traffic Sign Recognition**\n\nLogan Yang\n---\n\n**Build a Traffic Sign Recognition Project**\n\nThe goals / steps of this project are the following:\n* Load the data set (see below for links to the project data set)\n* Explore, summarize and visualize the data set\n* Design, train and test a model architecture\n* Use the model to make predictions on new images\n* Analyze the softmax probabilities of the new images\n* Summarize the results with a written report\n\n[//]: # (Image References)\n\n[image0]: ./examples/classes.png \"Visualization\"\n[image1]: ./examples/class_distribution.png \"Distribution\"\n[image2]: ./examples/normalization.png \"Normalization\"\n[image3]: ./examples/grayscale.png \"Grayscale\"\n[image4]: ./examples/random_noise0.png \"Translation\"\n[image5]: ./examples/random_noise1.png \"Rotation\"\n[image6]: ./examples/random_noise2.png \"Zoom\"\n[image7]: ./examples/new_distribution.png \"Augmented Data\"\n\n[image8]: ./my-signs/00000.png \"Traffic Sign 1\"\n[image9]: ./my-signs/00003.png \"Traffic Sign 2\"\n[image10]: ./my-signs/00004.png \"Traffic Sign 3\"\n[image11]: ./my-signs/00005.png \"Traffic Sign 4\"\n[image12]: ./my-signs/00007.png \"Traffic Sign 5\"\n[image13]: ./my-signs/00010.png \"Traffic Sign 6\"\n[image14]: ./examples/results.png \"Traffic Sign 6\"\n\n### Data Set Summary \u0026 Exploration\n\n#### 1. Provide a basic summary of the data set. In the code, the analysis should be done using python, numpy and/or pandas methods rather than hardcoding results manually.\n\n* The size of training set is 34799.\n* The size of the validation set is 4410.\n* The size of test set is 12630.\n* The shape of a traffic sign image is `32, 32, 3`\n* The number of unique classes/labels in the data set is 43.\n\n#### 2. Include an exploratory visualization of the dataset.\n\nHere is an exploratory visualization of the data set. First, all classes are shown with a representative image. Next, a bar chart showing how the classes are distributed. Some of the classes are over-represented and some are under-represented. The idea of data augmentation comes in at this point.\n\n![alt text][image0]\n\n![alt text][image1]\n\n### Design and Test a Model Architecture\n\n#### 1. Describe how you preprocessed the image data. What techniques were chosen and why did you choose these techniques? Consider including images showing the output of each preprocessing technique. Pre-processing refers to techniques such as converting to grayscale, normalization, etc. (OPTIONAL: If you generated additional data for training, describe why you decided to generate additional data, how you generated the data, and provide example images of the additional data. Then describe the characteristics of the augmented training set like number of images in the set, number of images for each class, etc.)\n\nFirst, the images need to be preprocessed. I normalized the images to `[0, 1]` and converted them to grayscale because the significance of color is negligible in this problem.\n\nHere is an example of a traffic sign image before and after normalization.\n\n![alt text][image2]\n\nHere is an example of a traffic sign image before and after grayscaling.\n\n![alt text][image3]\n\nNext, given the imbalance training set, I generated images by translating, rotating or zooming the existing images by a random small amount. In this way, new images can be generated and the key information in the image, aka the sign is still preserved.\n\nHere is an example of an original image and an augmented image:\n\n![alt text][image4]\n![alt text][image5]\n![alt text][image6]\n\nThe difference in distribution between the original data set and the augmented data set is shown below\n\n![alt text][image7]\n\n#### 2. Describe what your final model architecture looks like including model type, layers, layer sizes, connectivity, etc.) Consider including a diagram and/or table describing the final model.\n\nMy final model consisted of the following layers:\n\n| Layer             |     Description                   |\n|:---------------------:|:---------------------------------------------:|\n| Input             | 32x32x1 grayscale image                 |\n| Convolution 5x5       | 1x1 stride, valid padding, outputs 28x28x6  |\n| RELU          |                       |\n| Max pooling         | 2x2 stride,  outputs 14x14x6         |\n| Convolution 5x5     | 1x1 stride, valid padding, outputs 10x10x16    |\n| RELU          |                       |\n| Max pooling         | 2x2 stride,  outputs 5x5x16         |\n| Convolution 5x5     | 1x1 stride, valid padding, outputs 1x1x400    |\n| RELU          |                       |\n| Fully connected   | Flatten the two previous convnets 5x5x16 and 1x1x400, concatenate to size 800, outputs 400  |\n| RELU          |                       |\n| DROPOUT          | Dropout with probability 0.5                      |\n| Fully connected   | outputs 43  |\n| RELU          |                       |\n| Softmax       | Return the logits  |\n|           |                       |\n\n\n#### 3. Describe how you trained your model. The discussion can include the type of optimizer, the batch size, number of epochs and any hyperparameters such as learning rate.\n\nTo train the model, I used `AdamOptimizer` which is better than vanilla gradient descent.\n\n```\nEPOCHS = 20\nBATCH_SIZE = 150\nrate = 0.002\n```\n\n#### 4. Describe the approach taken for finding a solution and getting the validation set accuracy to be at least 0.93. Include in the discussion the results on the training, validation and test sets and where in the code these were calculated. Your approach may have been an iterative process, in which case, outline the steps you took to get to the final solution and why you chose those steps. Perhaps your solution involved an already well known implementation or architecture. In this case, discuss why you think the architecture is suitable for the current problem.\n\nMy final model results were:\n* training set accuracy of 99.8%.\n* validation set accuracy of 98.4%.\n* test set accuracy of 94.2%.\n\nAn iterative approach was chosen:\n* The first architecture was the vanilla LeNet5 from the lab. It yielded ~90% test accuracy out-of-the-box, which was not bad. However, both training and validation accuracies are not high, indicating there's underfitting. The architecture couldn't catch enough details from the dataset, so a deeper / more complex model is needed.\n* The next starting point should be an architecture from the Yann LeCun paper on traffic sign classification. I adapted to its description, added an extra fully connected layer, then managed to get a validation accuracy of ~94%, a significant advantage over the previous model.\n* By printing training accuracy, clearly there was overfitting happening - as the training accuracy went up, validation accuracy went down after it hit 94%. So DROPOUT is added, the validation accuracy went up to ~97%.\n* To fully utilize the training data and have a better training/validation split, `StratifiedShuffleSplit` is used to obtain a validation set that has approximately the same percentage of each class as the training data. I tried splitting a new pair of training and validation set for each epoch, but it turned out that the validation accuracy could go as high as ~99% but the test accuracy didn't improve. Theoretically I thought having a new split each time should reduce overfitting, but somehow it wasn't the case. Possibly it's because I have the generated data in both training and validation, but not in test, so the model fits better for the generated data, but not test data. One approach to find the cause is to do an exploration in the test data and see what's different between test and validation.\n\n### Test a Model on New Images\n\n#### 1. Choose five German traffic signs found on the web and provide them in the report. For each image, discuss what quality or qualities might be difficult to classify.\n\nHere are five German traffic signs that I found on the web:\n\n![alt text][image8] ![alt text][image9] ![alt text][image10]\n![alt text][image11] ![alt text][image12] ![alt text][image13]\n\nThese images have different resolutions, I transformed them to 32 by 32 but the difference in size and image quality is still a factor that could affect the prediction performance.\n\n#### 2. Discuss the model's predictions on these new traffic signs and compare the results to predicting on the test set. At a minimum, discuss what the predictions were, the accuracy on these new predictions, and compare the accuracy to the accuracy on the test set (OPTIONAL: Discuss the results in more detail as described in the \"Stand Out Suggestions\" part of the rubric).\n\nHere are the results of the prediction:\n\n| Image             |     Prediction                    |\n|:---------------------:|:---------------------------------------------:|\n| Vehicles over 3.5 metric tons prohibited         | Vehicles over 3.5 metric tons prohibited                     |\n| Turn right ahead          | Turn right ahead                    |\n| Right-of-way at the next intersection         | Right-of-way at the next intersection                     |\n| Keep right            | Keep right                  |\n| Ahead only     | Ahead only                   |\n| No entry     | No entry                   |\n\n\nThe model was able to correctly guess 6 of the 6 traffic signs, which gives an accuracy of 100%.\n\nCompared to the test accuracy, this is obviously larger, reason being this is a very small sample and there is a chance that a model could guess right 6 out of 6. Say we have a binomial distribution with the success rate of `p`, where `p` can be the test accuracy. There is a chance that `x` can range from `0 - 6` even with a \"true\" accuracy of `p`. In this case, `x = 6`. It doesn't necessarily mean the model is better than what the previous test accuracy suggested. To better evaluate the model's performance, a much larger data is needed so that we can confidently check how well the model generalizes in real world.\n\n#### 3. Describe how certain the model is when predicting on each of the five new images by looking at the softmax probabilities for each prediction. Provide the top 5 softmax probabilities for each image along with the sign type of each probability.\n\nFor the first image, the model is relatively sure that this is a stop sign (probability of 0.6), and the image does contain a stop sign. The top five soft max probabilities were\n\n![alt text][image14]\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flogancyang%2Ftraffic-sign-classifier","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flogancyang%2Ftraffic-sign-classifier","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flogancyang%2Ftraffic-sign-classifier/lists"}