CoolFace
Apppublic

santosh3110/Ecoclassify-Wildlife_Classifier

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
README.md387 linesDownload Raw Back to root
1---2title: EcoClassify - Wildlife Classifier3emoji: ๐Ÿฆ4colorFrom: green5colorTo: blue6sdk: streamlit7sdk_version: "1.36.0"8app_file: app.py9pinned: false10---11 12# ๐Ÿฆ‰ EcoClassify โ€“ Wildlife Image Classifier  13 14![Python](https://img.shields.io/badge/python-3.10-blue.svg)15![Streamlit](https://img.shields.io/badge/Streamlit-1.36.0-ff69b4.svg)16![PyTorch](https://img.shields.io/badge/PyTorch-2.2-red.svg)17![License](https://img.shields.io/badge/License-Apache%202.0-green.svg)18 19> **AI-powered wildlife conservation.**  20EcoClassify is an **end-to-end computer vision project** that classifies camera trap images into wildlife species using **transfer learning (ResNet50).**  21It includes **model explainability (Grad-CAM)**, **batch inference**, **fine-tuning via Streamlit UI**, and **MLflow/DagsHub integration** for experiment tracking. It was born out of the need to help researchers, educators, and nature lovers quickly identify species without needing to be a machine learning wizard. This project was developed as part of my internship at **Euron**, with heartfelt thanks to **Sudhanshu Kumar, Director of Euron,** for his guidance and mentorship.22 23๐Ÿ”— **Live Demo on Streamlit Cloud**:  24[![Streamlit App](https://img.shields.io/badge/Launch%20App-Streamlit-brightgreen?logo=streamlit)](https://ecoclassify---wildlife-image-classifier-ojyez7lpcmvjx25vmxr95c.streamlit.app/)25 26๐Ÿ”— **Live Demo on Hugging Face**: [![Hugging Face Spaces](https://img.shields.io/badge/Launch%20App-HuggingFace-orange?logo=huggingface)](https://huggingface.co/spaces/santosh3110/Ecoclassify-Wildlife_Classifier)27 28---29 30## ๐Ÿ“ธ App Screenshots  31 32| Inference (Single Image) | Grad-CAM Explainability |33|---------------------------|--------------------------|34| ![inference](app_inference_tab.png) | ![gradcam](app_gradcam.png) |  35 36| Batch Inference | Fine-Tuning |37|-----------------|-------------|38| ![batch](app_batch_inf.png) | ![finetune](app_finetune.png) |  39 40---41 42## ๐Ÿ“– Table of Contents  43 441. [About](#-about)  452. [Features](#-features)  463. [Architecture](#-architecture)  474. [Dataset](#-dataset)  485. [Installation](#-installation)  496. [Usage](#-usage)  507. [Streamlit App](#-streamlit-app)  518. [Training & Evaluation](#-training--evaluation)  529. [Explainability](#-explainability)  5310. [Batch Inference](#-batch-inference)  5411. [Fine-Tuning](#-fine-tuning)  5512. [Design Docs](#-design-docs)  5613. [Results](#-results)  5714. [Future Work](#-future-work)  5815. [Acknowledgements](#-acknowledgements)  59 60---61 62## ๐ŸŒ About  63 64Camera traps capture **millions of images** in wildlife conservation projects. Manual classification is slow, error-prone, and not scalable.  65 66**EcoClassify** provides:  67- ๐Ÿ”ฌ Automated **species classification** (7 classes + Blank).  68- ๐Ÿ–ผ๏ธ **Explainability dashboard** (Grad-CAM heatmaps).  69- โšก **Batch inference** for CSV/ZIP datasets.  70- ๐ŸŽ›๏ธ **Fine-tuning** interface for custom datasets.  71- ๐Ÿ“Š **MLflow/DagsHub** experiment logging.  72 73---74 75## ๐Ÿš€ Features  76 77- โœ… Species classification: *Antelope_Duiker, Bird, Civet_Genet, Hog, Leopard, Monkey_Prosimian, Rodent, Blank*.  78- โœ… **Transfer learning** with ResNet50 backbone.   79- โœ… **Grad-CAM** explainability for predictions.  80- โœ… **Streamlit app** with multiple tabs: Inference, Batch, Fine-tuning.  81- โœ… **Config-driven training** (YAML params & config).  82- โœ… **Experiment tracking** with MLflow + DagsHub.  83 84---85 86## ๐Ÿ—๏ธ Architecture  87 88### System Architecture  89 90```mermaid91flowchart TD92    A[User Uploads Image] --> B[Preprocessing & Augmentation]93    B --> C[Model Inference: ResNet50]94    C --> D[Predictions: Species + Confidence ]95    C --> E[Explainability Engine: Grad-CAM]96    D & E --> F[Streamlit Dashboard: Results]97    F --> G[Download CSV / Fine-tune Model]98```99 100### End-to-End Pipeline  101 102```mermaid103graph LR104    A[Data Ingestion] --> B[Data Loader]105    B --> C[Training Pipeline with MLflow Logging]106    C --> D[Evaluation of Models with MLflow Logging]107    D --> E[Batch Inference]108    E --> F[Streamlit App]109    F --> G[Model Fine Tuning]110```111 112### Project Structure  113 114```115.116EcoClassify---Wildlife-Image-Classifier/117โ”‚118โ”œโ”€โ”€ app.py                     # Streamlit app entry point119โ”œโ”€โ”€ main.py                    # Orchestrates full training โ†’ eval โ†’ inference pipeline120โ”œโ”€โ”€ setup.py                   # Package setup121โ”œโ”€โ”€ requirements.txt           # Dependencies122โ”œโ”€โ”€ README.md                  # Documentation123โ”œโ”€โ”€ LICENSE124โ”œโ”€โ”€ colab_code.ipynb           # Code for running the repo on Google Colab125โ”œโ”€โ”€ params.yaml                # Hyperparameters126โ”œโ”€โ”€ init_project_structure.py  # Script to bootstrap project tree127โ”‚128โ”œโ”€โ”€ artifacts/                 # All experiment outputs129โ”‚   โ”œโ”€โ”€ base_model/            # Initial CNN model130โ”‚   โ”œโ”€โ”€ resnet50_model/        # ResNet50 base model131โ”‚   โ”œโ”€โ”€ training/              # Trained model checkpoints132โ”‚   โ”œโ”€โ”€ prepare_callbacks/     # Callback checkpoints133โ”‚   โ”œโ”€โ”€ evaluation/            # Confusion matrices & reports134โ”‚   โ”œโ”€โ”€ explanations/          # Grad-CAM heatmaps135โ”‚   โ”œโ”€โ”€ batch_inference/       # Batch predictions136โ”‚   โ”œโ”€โ”€ data_ingestion/        # Raw & processed datasets137โ”‚   โ””โ”€โ”€ streamlit_outputs/     # Models & mappings saved from app138โ”‚139โ”œโ”€โ”€ config/140โ”‚   โ””โ”€โ”€ config.yaml            # Centralized config file141โ”‚ 142โ”œโ”€โ”€ docs/                      # Project Documents143โ”‚   โ”œโ”€โ”€ PRD.pdf                # Product Requirements & Specification Document144โ”‚   โ”œโ”€โ”€ HLD.pdf                # High Level Design Document145โ”‚   โ””โ”€โ”€ LLD.pdf                # Low Level Design Document146โ”‚147โ”œโ”€โ”€ logs/148โ”‚   โ””โ”€โ”€ running_logs.log       # Pipeline logs149โ”‚150โ”œโ”€โ”€ research/                  # Notebooks for experiments151โ”‚   โ””โ”€โ”€ experiment.ipynb152โ”‚   153โ”‚154โ””โ”€โ”€ src/ecoclassify/           # Source code (modular package)155    โ”œโ”€โ”€ components/            # Core ML components156    โ”‚   โ”œโ”€โ”€ customcnn_base_model.py157    โ”‚   โ”œโ”€โ”€ resnet50_model.py158    โ”‚   โ”œโ”€โ”€ training.py159    โ”‚   โ”œโ”€โ”€ evaluation.py160    โ”‚   โ”œโ”€โ”€ explanation_generator.py161    โ”‚   โ”œโ”€โ”€ fine_tuning.py162    โ”‚   โ”œโ”€โ”€ batch_inference.py163    โ”‚   โ”œโ”€โ”€ data_ingestion.py164    โ”‚   โ””โ”€โ”€ data_loader.py165    โ”‚166    โ”œโ”€โ”€ pipeline/              # Orchestrated stages167    โ”‚   โ”œโ”€โ”€ stage_01_data_ingestion.py168    โ”‚   โ”œโ”€โ”€ stage_02_customcnn_base_model.py169    โ”‚   โ”œโ”€โ”€ stage_03_resnet_50_model.py170    โ”‚   โ”œโ”€โ”€ stage_04_model_training.py171    โ”‚   โ”œโ”€โ”€ stage_05_model_evaluation.py172    โ”‚   โ”œโ”€โ”€ stage_06_generate_explanations.py173    โ”‚   โ””โ”€โ”€ stage_07_batch_inference.py174    โ”‚175    โ”œโ”€โ”€ config/                # Config manager176    โ”‚   โ””โ”€โ”€ configuration.py177    โ”‚178    โ”œโ”€โ”€ constants/             # File paths & constants179    โ”‚   โ””โ”€โ”€ paths.py180    โ”‚181    โ”œโ”€โ”€ entity/                # Config/data entities182    โ”‚   โ””โ”€โ”€ config_entity.py183    โ”‚184    โ”œโ”€โ”€ utils/                 # Utility functions185    โ”‚   โ”œโ”€โ”€ common.py186    โ”‚   โ””โ”€โ”€ logger.py187    โ”‚188    โ””โ”€โ”€ __init__.py189```190 191---192 193## ๐Ÿ“š Dataset  194 195- **Source**: Conser-vision Practice Area: Image Classification by drivendata.org196- **Provided by**:  197  *The Pan African Programme: The Cultured Chimpanzee, Wild Chimpanzee Foundation, DrivenData. (2022). Conser-vision Practice Area: Image Classification. Retrieved [July 12 2025] from https://www.drivendata.org/competitions/87/competition-image-classification-wildlife-conservation/.*  198 199---200 201## โš™๏ธ Installation  202 203```bash204git clone https://github.com/santosh3110/EcoClassify---Wildlife-Image-Classifier.git205cd EcoClassify---Wildlife-Image-Classifier206conda create -n ecoclassify python=3.10 -y207conda activate ecoclassify208pip install -r requirements.txt209```210 211(Optional: install PyTorch with CUDA if using GPU).  212 213---214 215## โ–ถ๏ธ Usage  216 217### Run Streamlit App  218 219```bash220streamlit run app.py221```222 223App opens at **http://localhost:8501**.  224 225### CLI Training  226 227```bash228python ecoclassify/pipelines/main.py229```230 231---232 233## ๐Ÿ–ฅ๏ธ Streamlit App  234 235๐Ÿ‘‰ Try EcoClassify directly without setup: [Live Demo on Hugging Face ๐Ÿš€](https://huggingface.co/spaces/santosh3110/Ecoclassify-Wildlife_Classifier)236 237Tabs available:  238 2391. **About** โ€“ Project info, dataset, motivation.  2402. **Inference** โ€“ Upload images โ†’ classification + Grad-CAM heatmaps.  2413. **Batch Inference** โ€“ Upload CSV + ZIP โ†’ get predictions CSV.  2424. **Fine-Tuning** โ€“ Upload dataset (train/val) โ†’ retrain ResNet50 with custom hyperparameters.  243 244---245 246## ๐Ÿ“Š Model Training & Evaluation  247 248- Models trained:  249  - **CustomCNN** (100 epochs)  250  - **ResNet50 (transfer learning)** (50 epochs)  251 252- Evaluation scope:253  - Confusion matrix254  - Classification report255  - Calibration metrics (temperature scaling)256  - **Artifacts** stored under artifacts/257 258### Results Summary259 260| Model     | Temperature | Uncalibrated Accuracy | Calibrated Accuracy | Uncalibrated Precision | Calibrated Precision | Uncalibrated Recall | Calibrated Recall | Uncalibrated F1 | Calibrated F1 | Uncalibrated Log-Loss | Calibrated Log-Loss |261|:----------|:-----------:|:---------------------:|:-------------------:|:----------------------:|:--------------------:|:--------------------:|:-------------------:|:----------------:|:----------------:|:----------------------:|:----------------------:|262| CustomCNN | 0.66        | 0.70                  | 0.70                | 0.70                   | 0.70                 | 0.70                 | 0.70                | 0.69             | 0.69          | 0.89                   | 0.83                   |263| ResNet50  | 0.82        | 0.89                  | 0.89                | 0.89                   | 0.89                 | 0.89                 | 0.89                | 0.89             | 0.89          | 0.41                   | 0.39                   |264 265### Macro & Weighted Averages266 267| Model     | Macro Precision | Macro Recall | Macro F1 | Weighted Precision | Weighted Recall | Weighted F1 |268|:----------|:----------------:|:------------:|:--------:|:------------------:|:---------------:|:-----------:|269| CustomCNN | 0.72            | 0.70         | 0.71     | 0.70               | 0.70            | 0.69       |270| ResNet50  | 0.90            | 0.90         | 0.90     | 0.89               | 0.89            | 0.89       |271 272### Per-class Metrics273 274### CustomCNN275 276| Class            | Precision | Recall | F1-score | Support |277|:-----------------:|:---------:|:------:|:--------:|:-------:|278| antelope_duiker  | 0.50      | 0.50   | 0.50     | 495.00  |279| bird             | 0.75      | 0.69   | 0.72     | 328.00  |280| blank            | 0.62      | 0.36   | 0.46     | 443.00  |281| civet_genet      | 0.80      | 0.92   | 0.86     | 485.00  |282| hog              | 0.92      | 0.79   | 0.85     | 195.00  |283| leopard          | 0.91      | 0.87   | 0.89     | 451.00  |284| monkey_prosimian | 0.57      | 0.79   | 0.66     | 498.00  |285| rodent           | 0.69      | 0.70   | 0.70     | 403.00  |286 287### ResNet50288 289| Class            | Precision | Recall | F1-score | Support |290|:-----------------:|:---------:|:------:|:--------:|:-------:|291| antelope_duiker  | 0.81      | 0.81   | 0.81     | 495.00  |292| bird             | 0.93      | 0.96   | 0.95     | 328.00  |293| blank            | 0.77      | 0.62   | 0.68     | 443.00  |294| civet_genet      | 0.94      | 0.97   | 0.96     | 485.00  |295| hog              | 0.97      | 0.98   | 0.98     | 195.00  |296| leopard          | 0.94      | 0.98   | 0.96     | 451.00  |297| monkey_prosimian | 0.90      | 0.93   | 0.91     | 498.00  |298| rodent           | 0.89      | 0.95   | 0.92     | 403.00  |299 300### Training visuals:301- CustomCNN Training Chart: ![customcnn_training.png](customcnn_training.png)302- ResNet50 Training Chart: ![resnet50_training.png](resnet50_training.png)303 304- Results tracked via ![**MLflow & DagsHub**](https://dagshub.com/santoshkumarguntupalli/EcoClassify---Wildlife-Image-Classifier/experiments)305 306### Confusion matrices:307 308| CustomCNN confusion matrix| ResNet50 confusion matrix |309|---------------------------|---------------------------|310| ![customcnn_confusion](artifacts/evaluation/customcnn/confusion_matrix.png) | ![resnet50_confusion](artifacts/evaluation/resnet50/confusion_matrix.png)|  311 312---313 314## ๐Ÿ”Ž Explainability  315 316- **Grad-CAM** highlights model focus regions.  317- Outputs side-by-side comparison:  318  - Original Image  319  - Heatmap Overlay  320- Sample Grad-CAM heatmaps generated on Val dataset:321    ![alt text](artifacts/explanations/ZJ000039_gradcam.png)322    ![alt text](artifacts/explanations/ZJ003443_gradcam.png)323    ![alt text](artifacts/explanations/ZJ013423_gradcam.png)324    ![alt text](artifacts/explanations/ZJ012512_gradcam.png)325---326 327## ๐Ÿ“ฆ Batch Inference  328 329- Upload **CSV** (image paths) + **ZIP** (images).  330- Pipeline produces **predictions.csv** with class & confidence.  331 332---333 334## ๐Ÿ› ๏ธ Fine-Tuning  335 336- Upload dataset in structure:  337 338```339dataset.zip340 โ”œโ”€โ”€ train/341 โ”‚   โ”œโ”€โ”€ class1/342 โ”‚   โ”œโ”€โ”€ class2/343 โ””โ”€โ”€ val/344     โ”œโ”€โ”€ class1/345     โ”œโ”€โ”€ class2/346```347 348- Configure hyperparams (epochs, batch size, LR, early stopping).  349- Retrains ResNet50 on uploaded data.  350- Outputs: new model weights + mapping.  351 352---353 354## ๐Ÿ“„ Design Docs  355 356๐Ÿ“Œ Included in `/docs`:  357 358- **PRD** โ€“ Product Requirements & Specs  359- **HLD** โ€“ High-Level Architecture Design  360- **LLD** โ€“ Low-Level Implementation Design  361 362---363 364## ๐Ÿงฉ Future Work  365 366- ๐Ÿš€ Deploy as **FastAPI + Docker** microservice.  367- ๐Ÿ“ฑ Extend to **mobile app** for field researchers.  368- ๐Ÿงช Add **ensemble models** (ResNet + ViT).  369- ๐Ÿพ Multi-label support (detect multiple species in one frame).  370 371---372 373## โค๏ธ Acknowledgements  374 375- The Pan African Programme: The Cultured Chimpanzee, Wild Chimpanzee Foundation, DrivenData. (2022). Conser-vision Practice Area: Image Classification. Retrieved [July 12 2025] from https://www.drivendata.org/competitions/87/competition-image-classification-wildlife-conservation/. 376- Mentorship: **Sudhanshu Kumar (Euron)**  377- Frameworks: PyTorch, Streamlit, MLflow, TorchCAM  378 379---380 381## ๐Ÿ“œ License  382 383Apache 2.0 License ยฉ 2025 Santosh Kumar Guntupalli  384 385---386 387โœจ *Made with love for Wildlife & AI* ๐Ÿ†๐ŸŒฑ