diff --git a/.gitattributes b/.gitattributes index a6344aac8c09253b3b630fb776ae94478aa0275b..02103bb277d581f7d574df2ffcba1c15860e165f 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,35 +1,16 @@ -*.7z filter=lfs diff=lfs merge=lfs -text -*.arrow filter=lfs diff=lfs merge=lfs -text -*.bin filter=lfs diff=lfs merge=lfs -text -*.bz2 filter=lfs diff=lfs merge=lfs -text -*.ckpt filter=lfs diff=lfs merge=lfs -text -*.ftz filter=lfs diff=lfs merge=lfs -text -*.gz filter=lfs diff=lfs merge=lfs -text -*.h5 filter=lfs diff=lfs merge=lfs -text -*.joblib filter=lfs diff=lfs merge=lfs -text -*.lfs.* filter=lfs diff=lfs merge=lfs -text -*.mlmodel filter=lfs diff=lfs merge=lfs -text -*.model filter=lfs diff=lfs merge=lfs -text -*.msgpack filter=lfs diff=lfs merge=lfs -text -*.npy filter=lfs diff=lfs merge=lfs -text -*.npz filter=lfs diff=lfs merge=lfs -text -*.onnx filter=lfs diff=lfs merge=lfs -text -*.ot filter=lfs diff=lfs merge=lfs -text -*.parquet filter=lfs diff=lfs merge=lfs -text -*.pb filter=lfs diff=lfs merge=lfs -text -*.pickle filter=lfs diff=lfs merge=lfs -text -*.pkl filter=lfs diff=lfs merge=lfs -text -*.pt filter=lfs diff=lfs merge=lfs -text -*.pth filter=lfs diff=lfs merge=lfs -text -*.rar filter=lfs diff=lfs merge=lfs -text -*.safetensors filter=lfs diff=lfs merge=lfs -text -saved_model/**/* filter=lfs diff=lfs merge=lfs -text -*.tar.* filter=lfs diff=lfs merge=lfs -text -*.tar filter=lfs diff=lfs merge=lfs -text -*.tflite filter=lfs diff=lfs merge=lfs -text -*.tgz filter=lfs diff=lfs merge=lfs -text -*.wasm filter=lfs diff=lfs merge=lfs -text -*.xz filter=lfs diff=lfs merge=lfs -text -*.zip filter=lfs diff=lfs merge=lfs -text -*.zst filter=lfs diff=lfs merge=lfs -text -*tfevents* filter=lfs diff=lfs merge=lfs -text +.pkl filter=lfs diff=lfs merge=lfs -text +artifacts.zip filter=lfs diff=lfs merge=lfs -text +ml/artifacts/figures/class_distribution.png filter=lfs diff=lfs merge=lfs -text +ml/artifacts/figures/cnn/confusion_matrix.png filter=lfs diff=lfs merge=lfs -text +ml/artifacts/figures/cnn/per_class_f1.png filter=lfs diff=lfs merge=lfs -text +ml/artifacts/figures/cnn/training_curves.png filter=lfs diff=lfs merge=lfs -text +ml/artifacts/figures/comparison/comparison_radar.png filter=lfs diff=lfs merge=lfs -text +ml/artifacts/figures/mlp/confusion_matrix.png filter=lfs diff=lfs merge=lfs -text +ml/artifacts/figures/mlp/per_class_f1.png filter=lfs diff=lfs merge=lfs -text +ml/artifacts/figures/mlp/training_curves.png filter=lfs diff=lfs merge=lfs -text +ml/artifacts/figures/resnet/confusion_matrix.png filter=lfs diff=lfs merge=lfs -text +ml/artifacts/figures/resnet/per_class_f1.png filter=lfs diff=lfs merge=lfs -text +ml/artifacts/figures/sample_images.png filter=lfs diff=lfs merge=lfs -text +ml/artifacts/figures/vit/confusion_matrix.png filter=lfs diff=lfs merge=lfs -text +ml/artifacts/figures/vit/per_class_f1.png filter=lfs diff=lfs merge=lfs -text +models/vit_best.pth filter=lfs diff=lfs merge=lfs -text diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..5629b3e4f89360cbd9704c52edcf59ed1f6556b8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,34 @@ +# Model checkpoints & artifacts +ml/artifacts/checkpoints/*.pth +ml/artifacts/checkpoints/*.pt +ml/artifacts/checkpoints/*.ckpt + +# Python +__pycache__/ +*.py[cod] +*$py.class +*.egg-info/ +dist/ +build/ +*.egg + +# Virtual environments +venv/ +env/ +.env + +# Jupyter +.ipynb_checkpoints/ + +# OS files +.DS_Store +Thumbs.db + +# IDE +.vscode/ +.idea/ + +backend.log +tunnel.log + + diff --git a/.slugignore.txt b/.slugignore.txt new file mode 100644 index 0000000000000000000000000000000000000000..54165434574c2f5d8113a005a83f910d03dd4f2f --- /dev/null +++ b/.slugignore.txt @@ -0,0 +1,4 @@ +*.psd +*.pdf +/test +/spec \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..b815ea5114998b5e56f1806717c967930b392be3 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,46 @@ +# Unified Dockerfile for Hugging Face Spaces (or Render) +# Builds the Vite React Frontend and serves it statically via FastAPI Backend + +# Stage 1: Build Frontend +FROM node:20-alpine as frontend-builder +WORKDIR /app/frontend +COPY frontend/package*.json ./ +RUN npm ci +COPY frontend/ ./ +RUN npm run build + +# Stage 2: Build Backend & Serve +FROM python:3.11-slim + +WORKDIR /app + +# Install system dependencies +RUN apt-get update && apt-get install -y --no-install-recommends \ + gcc \ + && rm -rf /var/lib/apt/lists/* + +# Copy backend requirements and install +COPY backend/requirements.txt ./backend/ +RUN pip install --no-cache-dir -r backend/requirements.txt + +# Copy backend source code and config +COPY backend/ ./backend/ +COPY ml/src/ ./ml/src/ +COPY data/breed_metadata.csv ./data/ +# Copy the built frontend +COPY --from=frontend-builder /app/frontend/dist ./frontend/dist +# Copy the exported model artifact +COPY models/vit_best.pth ./models/vit_best.pth + +# Set runtime environments +ENV PYTHONPATH=/app +ENV MODEL_PATH=/app/models/vit_best.pth +ENV METADATA_PATH=/app/data/breed_metadata.csv +ENV MODEL_NAME=vit +ENV MODEL_VERSION=v2.0 + +# Hugging Face Spaces run explicitly on 7860 +EXPOSE 7860 + +# Run Uvicorn via HTTP (Hugging Face / Render friendly) +CMD ["uvicorn", "backend.app.main:app", "--host", "0.0.0.0", "--port", "7860"] diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..dcfbb30d03166787f0a448a37a79275331eb939c --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 Ajaya and team + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/Procfile b/Procfile new file mode 100644 index 0000000000000000000000000000000000000000..e6cb5adcafb2ef16e9c62753c9caf23f4984536b --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +web: python app.py \ No newline at end of file diff --git a/README.md b/README.md index bc6616a5b53f31f18e0a943e4af78a7a56d431a6..700108619a961e87af1873141f1514c8543bf953 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,126 @@ --- -title: Cattllassifier Coding -emoji: ๐ +title: Cattle Breed Classifier +emoji: ๐ colorFrom: blue -colorTo: blue +colorTo: green sdk: docker pinned: false --- -Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference +# ๐ Indigenous Cattle Breed Classifier + +Identifying indigenous Indian cattle and buffalo breeds requires specialized domain expertise that many farmers and agricultural workers may lack. Proper identification is critical for optimizing milk yield projections, managing livestock lifespans, and preserving regional biodiversity. + +This project solves this by delivering an end-to-end deep learning pipeline and an accessible web application capable of identifying **26 distinct indigenous cattle and buffalo breeds** from an image. + +     + +### ๐ข Live Demo +**Test the fully deployed Vision Transformer natively in the browser here:** +๐ **[https://huggingface.co/spaces/amoghakoulapure/cattle-breed-classifier](https://huggingface.co/spaces/amoghakoulapure/cattle-breed-classifier)** + +--- + +## ๐ Data Gathering & Information + +The foundation of any robust computer vision model is its data. Our dataset comprises thousands of images distributed across 26 target classes, which include **21 Cow breeds** and **5 Buffalo breeds**. + +To handle raw data efficiently, we developed a dynamic pre-processing layer that structurally manages unbalanced classes, unifies image ratios, and performs aggressive augmentation. + +
+
+
+
+
+
+