{"id":20503020,"url":"https://github.com/abhash-rai/traffic-image-classifier","last_synced_at":"2026-02-23T01:20:02.619Z","repository":{"id":207321363,"uuid":"708444797","full_name":"abhash-rai/traffic-image-classifier","owner":"abhash-rai","description":"A web-based solution utilizing a robust tensorflow model for precise traffic condition classification made in ReactJs and FastAPI for backend.","archived":false,"fork":false,"pushed_at":"2023-11-16T13:34:37.000Z","size":11146,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-07T05:42:06.255Z","etag":null,"topics":["cnn","cnn-classification","cnn-keras","cnn-model","data-analysis","data-science","data-visualization","fastapi","keras","keras-tensorflow","python","python-3","python3","react","reactjs","tensorflow","traffic","traffic-classification","transfer-learning"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/abhash-rai.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":"2023-10-22T15:30:45.000Z","updated_at":"2024-02-03T17:12:44.000Z","dependencies_parsed_at":null,"dependency_job_id":"fde24690-728a-4caf-9190-4a145170b895","html_url":"https://github.com/abhash-rai/traffic-image-classifier","commit_stats":null,"previous_names":["abhash-rai/traffic-image-classifier"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/abhash-rai/traffic-image-classifier","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhash-rai%2Ftraffic-image-classifier","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhash-rai%2Ftraffic-image-classifier/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhash-rai%2Ftraffic-image-classifier/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhash-rai%2Ftraffic-image-classifier/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/abhash-rai","download_url":"https://codeload.github.com/abhash-rai/traffic-image-classifier/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhash-rai%2Ftraffic-image-classifier/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266640797,"owners_count":23960805,"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-07-23T02:00:09.312Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"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":["cnn","cnn-classification","cnn-keras","cnn-model","data-analysis","data-science","data-visualization","fastapi","keras","keras-tensorflow","python","python-3","python3","react","reactjs","tensorflow","traffic","traffic-classification","transfer-learning"],"created_at":"2024-11-15T19:28:54.604Z","updated_at":"2026-02-23T01:20:02.573Z","avatar_url":"https://github.com/abhash-rai.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# traffic-image-classifier\n\n\u003e #### TASKS PERFORMED 🡆 Data Collection (Manual, Web Scrapping)✅, Exploratory Data Analysis✅, Data Augmentation✅, Model Training (ML Algorithms, CNN, Transfer Learning)✅, Hyperparameter Tuning✅, Model Validation✅, Deployment (UI Design, React and FastAPI)✅\n\n\u003cp align=\"center\"\u003e\n  \u003cimg width=\"100%\" src=\"./documentation/demo.gif\" alt=\"App Demo\"\u003e\n\u003c/p\u003e\n\nUpload images and make classification on:\n\n- `traffic_unrelated`: Indicates an absence of traffic related situation\n- `congested_traffic`: Indicates complete standstill caused by congestion or blockages or accidents\n- `heavy_traffic`: Indicates high volume of vehicles causing slow moving traffic conditions\n- `moderate_traffic`: Indicates moderate or steady flow of traffic with moderate number of vehicles\n- `light_traffic`: Indicates minimal or very few vehicles on the road\n\nFor more details on the model training process, please visit the Kaggle project [here](https://www.kaggle.com/code/abhashrai/traffic-congestion-prediction-cnn-xception/).\n\n# Table of Content\n\n- [Prerequisites](#prerequisites)\n- [Demo](#demo)\n- [Usage](#usage)\n- [Model Summary](#model-summary)\n- [Model Evaluation](#model-evaluation)\n- [Acknowledgement](#acknowledgement)\n\n# Prerequisites\n\n- You must have `Python 3` installed on your system.\n- You must have `Git` installed on your system.\n- You must have `Git LFS` installed on your system (for cloning/downloading pre-trained model file).\n- **(Optional)** You should have `Node.js` (npm) installed on your system (if using development server)\n\n# Demo\n\n\u003ch4 align=\"center\"\u003e\n  \u003cb\u003eStep 1: Upload an image ↓\u003c/b\u003e\n\u003c/h4\u003e\n\n![Step 1 - Upload Image](./documentation/step1.png)\n\n\u003ch4 align=\"center\"\u003e\n  \u003cb\u003eStep 2: Crop the image into square ratio ↓\u003c/b\u003e\n\u003c/h4\u003e\n\n![Step 2 - Crop Image](./documentation/step2.png)\n\n\u003ch4 align=\"center\"\u003e\n  \u003cb\u003eStep 3: Get the results ↓\u003c/b\u003e\n\u003c/h4\u003e\n\n![Step 3 - Result](./documentation/step3.png)\n\n# Usage\n\n1. Clone the repository (In terminal):\n\n    ```\n    git clone https://github.com/AbhashChamlingRai/traffic-image-classifier.git\n    ```\n\n2. Enter into the project directory:\n\n    ```\n    cd traffic-image-classifier\n    ```\n\n    \u003e Before following the below procedure, go to \u003ca href='https://drive.google.com/file/d/1ytKJ1jTt6GEtDOpTHRtWaNHQIAaRSHPF/view?usp=sharing'\u003ethis link\u003c/a\u003e and download the model `traffic_classifier.h5` and place it into the `/traffic-image-classifier` directory.\n    \n3. Install the required dependencies:\n\n    ```\n    pip install -r requirements.txt\n    ```\n\n4. Start Fast-API:\n\n   Open `/fastapi` directory in your terminal. Then run the below command and wait until you see the message `Application startup complete.` in your terminal:\n\n    ```\n    uvicorn main:app --port 8000 --reload\n    ```\n\n5. Run React App:\n\n   Open `/react-app-build/index.html` file in your browser. Upload images in the web app and make predictions.\n\n6. **(Optional)** If you want to run development server:\n\n   Open `/react-app-development` directory in your terminal. Then install project dependencies using `npm install` command. Wait until installation process completes, then run the development server by running the command `npm start`.\n\n# Model Summary\n\n```Python\n_________________________________________________________________\n Layer (type)                Output Shape              Param #   \n=================================================================\n input_4 (InputLayer)        [(None, 300, 300, 3)]     0         \n                                                                 \n tf.cast_1 (TFOpLambda)      (None, 300, 300, 3)       0         \n                                                                 \n tf.math.truediv_1 (TFOpLamb  (None, 300, 300, 3)      0         \n da)                                                             \n                                                                 \n tf.math.subtract_1 (TFOpLam  (None, 300, 300, 3)      0         \n bda)                                                            \n                                                                 \n xception (Functional)       (None, 2048)              20861480  \n                                                                 \n batch_normalization_11 (Bat  (None, 2048)             8192      \n chNormalization)                                                \n                                                                 \n dense_3 (Dense)             (None, 368)               754032    \n                                                                 \n batch_normalization_12 (Bat  (None, 368)              1472      \n chNormalization)                                                \n                                                                 \n dense_4 (Dense)             (None, 112)               41328     \n                                                                 \n batch_normalization_13 (Bat  (None, 112)              448       \n chNormalization)                                                \n                                                                 \n dropout_1 (Dropout)         (None, 112)               0         \n                                                                 \n dense_5 (Dense)             (None, 5)                 565       \n                                                                 \n=================================================================\nTotal params: 21,667,517\nTrainable params: 800,981\nNon-trainable params: 20,866,536\n_________________________________________________________________\n```\n\nThe model needs input of a 300x300 pixel color image represented a NumPy array with RGB (3 channels). So, the input array must be of shape (1, 300, 300, 3). You don't have to worry about normalizing the pixel values (scaling by 1/255) because the first four layers of the model take care of it.\n\nIt generates prediction confidence scores represented by 5 consecutive numbers, each corresponding to a specific class: congested_traffic, heavy_traffic, light_traffic, moderate_traffic, and traffic_unrelated (in the specified order).\n\n# Model Evaluation\n\n![Data split distribution chart](./documentation/data_split.png)\n\nThe data was partitioned into two sets for training, and validation, each containing samples from five distinct classes. The split ratios are as follows: 85% for training, 15% for validation. Despite the limited data, the model successfully met my expectations:\n\n\u003e #### For validation data:\n\n```Python\nscore, acc = model.evaluate(validation_generator)\nprint('Test Loss =', score)\nprint('Test Accuracy =', acc)\n\nOutput:\n8/8 [==============================] - 12s 1s/step - loss: 0.1525 - accuracy: 0.9468\nTest Loss = 0.15245917439460754\nTest Accuracy = 0.9468421339988708\n```\n\n```Python\nConfusion Matrix:\n[[350  15   1  11   1]\n [ 14 290   1  15   0]\n [  1   1 345  11   2]\n [  5  12   2 332   0]\n [  4   0   5   0 482]]\n\nClassification Report:\n              precision    recall  f1-score   support\n\n           0       0.94      0.93      0.93       378\n           1       0.91      0.91      0.91       320\n           2       0.97      0.96      0.97       360\n           3       0.90      0.95      0.92       351\n           4       0.99      0.98      0.99       491\n\n    accuracy                           0.95      1900\n   macro avg       0.94      0.94      0.94      1900\nweighted avg       0.95      0.95      0.95      1900\n```\n\n\u003e #### For train data:\n\n```Python\nscore, acc = model.evaluate(train_generator)\nprint('Test Loss =', score)\nprint('Test Accuracy =', acc)\n\nOutput:\n43/43 [==============================] - 239s 6s/step - loss: 0.0883 - accuracy: 0.9695\nTest Loss = 0.08829263597726822\nTest Accuracy = 0.9695025682449341\n```\n\n```Python\nConfusion Matrix:\n[[2055   48   11   21    3]\n [  57 1711    5   36    1]\n [   4    3 2001   27    5]\n [  18   35   14 1920    2]\n [   3    1    4    4 2766]]\n\nClassification Report:\n              precision    recall  f1-score   support\n\n           0       0.96      0.96      0.96      2138\n           1       0.95      0.95      0.95      1810\n           2       0.98      0.98      0.98      2040\n           3       0.96      0.97      0.96      1989\n           4       1.00      1.00      1.00      2778\n\n    accuracy                           0.97     10755\n   macro avg       0.97      0.97      0.97     10755\nweighted avg       0.97      0.97      0.97     10755\n```\n\n![Training and validation loss and accuracy graph](./documentation/training_valid_loss_acc.png)\n\n# Acknowledgement\n\nSpecial thanks to Asha Limbu for her work in creating the UI/UX design.\n\n- Connect with Asha on [LinkedIn](https://www.linkedin.com/in/ashalimbu/) or [GitHub](https://github.com/asha-limbu)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabhash-rai%2Ftraffic-image-classifier","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fabhash-rai%2Ftraffic-image-classifier","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabhash-rai%2Ftraffic-image-classifier/lists"}