{"id":30671524,"url":"https://github.com/tanim-mishkat/improved-image-classification-using-mobilenetv2","last_synced_at":"2026-04-21T05:32:41.641Z","repository":{"id":310490250,"uuid":"1040049356","full_name":"tanim-mishkat/Improved-Image-Classification-Using-MobileNetv2","owner":"tanim-mishkat","description":"Butterfly Image Classification improved model with MobileNetV2","archived":false,"fork":false,"pushed_at":"2025-08-18T11:55:48.000Z","size":295,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-18T13:31:27.969Z","etag":null,"topics":["colab-butterflies","computer-vision","data-augmentation","deep-learning","image-classification","keras","mixed-precision","mobilenetv2","tensorflow","transfer-learning"],"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/tanim-mishkat.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,"zenodo":null}},"created_at":"2025-08-18T11:33:33.000Z","updated_at":"2025-08-18T11:55:51.000Z","dependencies_parsed_at":"2025-08-18T13:31:30.951Z","dependency_job_id":"a7d6cc1f-26d1-46ac-9d10-97765f647cd6","html_url":"https://github.com/tanim-mishkat/Improved-Image-Classification-Using-MobileNetv2","commit_stats":null,"previous_names":["tanim-mishkat/improved-image-classification-using-mobilenetv2"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/tanim-mishkat/Improved-Image-Classification-Using-MobileNetv2","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tanim-mishkat%2FImproved-Image-Classification-Using-MobileNetv2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tanim-mishkat%2FImproved-Image-Classification-Using-MobileNetv2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tanim-mishkat%2FImproved-Image-Classification-Using-MobileNetv2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tanim-mishkat%2FImproved-Image-Classification-Using-MobileNetv2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tanim-mishkat","download_url":"https://codeload.github.com/tanim-mishkat/Improved-Image-Classification-Using-MobileNetv2/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tanim-mishkat%2FImproved-Image-Classification-Using-MobileNetv2/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273068856,"owners_count":25039911,"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-09-01T02:00:09.058Z","response_time":120,"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":["colab-butterflies","computer-vision","data-augmentation","deep-learning","image-classification","keras","mixed-precision","mobilenetv2","tensorflow","transfer-learning"],"created_at":"2025-09-01T03:18:42.969Z","updated_at":"2026-04-21T05:32:36.602Z","avatar_url":"https://github.com/tanim-mishkat.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🦋 Assignment Project: Butterfly Image Classification with MobileNetV2\n\nThis repository documents the implementation of a **deep learning pipeline for butterfly species classification**, completed as part of an AI course assignment. The assignment required the following workflow:\n\n1. **Choose a Topic** → I selected *Butterfly Image Classification* within computer vision.\n2. **Review Literature** → Read and summarized **10 research papers** related to image classification, transfer learning, and accuracy improvement techniques.\n3. **Dataset Selection** → Identified a butterfly species dataset from Kaggle.\n4. **Baseline Code** → Chose an existing Kaggle notebook implementation.\n5. **Reimplementation \u0026 Improvement** → Rewrote the code into a clean, modular pipeline with enhancements in data quality, augmentation, evaluation, and accuracy.\n\n---\n\n## 📌 Project Overview\n\nThe goal of this project is to classify butterfly images into multiple species using a **transfer learning** approach with **MobileNetV2**. The workflow follows two-stage training:\n\n* **Stage 1:** Train a new classification head while keeping the MobileNetV2 backbone frozen.\n* **Stage 2:** Unfreeze the top layers of the backbone and fine-tune with a reduced learning rate.\n\nThis staged approach allows the model to preserve pretrained ImageNet features while adapting to butterfly-specific patterns.\n\n---\n\n## ✨ Key Features\n\n* **Dataset Handling**: Supports both folder-structured and CSV-structured datasets. Includes checks for corruption and duplicates (SHA-1 hashes). Class imbalance addressed with computed class weights.\n* **Preprocessing \u0026 Augmentation**: Images resized to 224×224, normalized to \\[0,1], cached for faster training. Augmentations include random flip, rotation, zoom, contrast, and translation.\n* **Transfer Learning**: MobileNetV2 backbone pretrained on ImageNet with custom classification head: `GlobalAveragePooling2D → Dropout → Dense(softmax)`.\n* **Training Strategy**: Two-stage pipeline with OOM-safe batch fallback, AdamW optimizer, label smoothing, and learning rate schedules.\n* **Regularization**: Dropout, L2 weight decay, and early stopping ensure generalization.\n* **Evaluation Tools**: Classification report, confusion matrix, hardest example mining, and automated metrics logging.\n* **Performance Optimizations**: Mixed precision training, Colab GPU-ready, and reproducible seeds.\n\n---\n\n## 📊 Alignment with 8 Key Factors for ML/DL Accuracy\n\nThe improvements were guided by the **8 Key Factors for ML/DL Accuracy** provided in the assignment:\n\n| Factor                                 | Implementation in Project                                                                                                  | Notes                                                       |\n| -------------------------------------- | -------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------- |\n| **1. Data Quality \u0026 Quantity**         | ✔ Removed duplicates and corrupt files\u003cbr\u003e✔ Class weights for imbalance\u003cbr\u003e✔ Consistent preprocessing (resize + normalize) | ✘ Limited to Kaggle dataset; no extra data collected        |\n| **2. Feature Engineering**             | ✔ Automated normalization and scaling\u003cbr\u003e✔ Dimensionality reduction via GAP                                                | ✘ No manual feature creation (CNN learns features directly) |\n| **3. Model Selection \u0026 Architecture**  | ✔ MobileNetV2 backbone\u003cbr\u003e✔ Shallow, regularized head design                                                               | ✘ Did not compare with other architectures due to time      |\n| **4. Hyperparameter Tuning**           | ✔ AdamW optimizer\u003cbr\u003e✔ Label smoothing\u003cbr\u003e✔ Batch size fallback\u003cbr\u003e✔ ReduceLROnPlateau                                     | ✘ No full hyperparameter sweep (compute-limited)            |\n| **5. Data Augmentation**               | ✔ Applied augmentations (flip, rotation, zoom, etc.)\u003cbr\u003e✔ Implemented MixUp (optional)                                     | ✘ Text/audio augmentation not applicable                    |\n| **6. Regularization \u0026 Generalization** | ✔ Dropout (0.25)\u003cbr\u003e✔ Weight Decay\u003cbr\u003e✔ Early Stopping                                                                     | ✘ Ensemble methods not implemented                          |\n| **7. Evaluation \u0026 Feedback Loop**      | ✔ Stratified validation split\u003cbr\u003e✔ Confusion matrix \u0026 hardest examples\u003cbr\u003e✔ JSON/CSV/PNG artifacts saved                   | ✘ No automated retraining loop                              |\n| **8. Computational Resources**         | ✔ Mixed precision for GPU efficiency\u003cbr\u003e✔ Early stopping for time savings                                                  | ✘ Did not use TPUs or multi-GPU training                    |\n\n\n---\n\n## 🚀 Getting Started\n\n### Run in Google Colab\n\n1. Upload your `kaggle.json` API key.\n2. Run notebook cells sequentially.\n3. Dataset auto-downloads and extracts.\n\n### Local Setup\n\n```bash\n# Clone repository\ngit clone https://github.com/your-username/butterfly-image-classification-mobilenetv2.git\ncd butterfly-image-classification-mobilenetv2\n\n# Create environment\npython -m venv .venv\nsource .venv/bin/activate   # Windows: .venv\\Scripts\\activate\n\n# Install dependencies\npip install -r requirements.txt\n```\n\n---\n\n## 🧠 Model Architecture\n\n* **Backbone:** MobileNetV2 (ImageNet pretrained)\n* **Head:** GlobalAveragePooling2D → Dropout(0.25) → Dense(NUM\\_CLASSES, softmax with L2 regularization)\n* **Optimizer:** AdamW (lr=3e-4, wd=1e-4)\n* **Loss Function:** Categorical Crossentropy (label smoothing=0.1)\n* **Training:** Two stages (frozen backbone → fine-tuning top \\~40%)\n\n---\n\n## 📈 Training Process\n\n1. **Stage 1:** Train only the classification head with backbone frozen.\n2. **Stage 2:** Unfreeze last 40% of MobileNetV2 layers, reduce learning rate, fine-tune.\n3. **Reason for Two Stages:** Directly training the whole model can destroy pretrained features; staged training preserves general patterns while adapting to butterfly images.\n\n---\n\n## 📊 Evaluation Artifacts\n\nAll evaluation results are stored under `results/`:\n\n* `metrics.json` — class-level + overall accuracy\n* `confusion_matrix.png` — visual class confusions\n* `hardest_examples_topN.json` — misclassified high-loss examples\n* `test_predictions.csv` — predictions for unlabeled test set\n\n---\n\n## 🛠 Requirements\n\n* Python 3.9+\n* TensorFlow 2.15+\n* scikit-learn\n* pandas, numpy, matplotlib\n* TensorFlow Probability (optional, for MixUp)\n\n---\n\n## 🗺 Future Improvements\n\n* Add support for **EfficientNet** and other backbones\n* Perform **hyperparameter sweeps** for LR, dropout, smoothing\n* Enable **test-time augmentation (TTA)**\n* Explore **ensembles** for improved robustness\n\n---\n\n## 📝 License\n\nMIT License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftanim-mishkat%2Fimproved-image-classification-using-mobilenetv2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftanim-mishkat%2Fimproved-image-classification-using-mobilenetv2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftanim-mishkat%2Fimproved-image-classification-using-mobilenetv2/lists"}