Skip to content

fsRakib/Image-Classification-CNN

Repository files navigation

🐾 Cat vs Dog AI - Deep Learning Image Classifier

A production-ready deep learning application that classifies images as cats or dogs with ~92% accuracy.
Deployed with Railway (backend) and Streamlit Cloud (frontend) for seamless access worldwide.

Python TensorFlow Streamlit FastAPI Railway License


🌐 Live Demo


πŸ“– Table of Contents


✨ Features

🎯 Two Powerful Interfaces

Feature Web App (Streamlit) REST API (FastAPI)
User Interface βœ… Interactive web UI ❌ API only (integrate with your app)
Real-time Classification βœ… Instant visual results βœ… JSON response
Batch Processing ❌ One image at a time βœ… Up to 10 images per request
Integration ❌ Standalone app βœ… Any language/platform
Auto Documentation ❌ N/A βœ… Swagger UI + ReDoc
Mobile Friendly βœ… Responsive design βœ… Mobile apps can integrate
Cloud Deployment βœ… Streamlit Cloud βœ… Railway
Best For End-users, demos Developers, production systems

🎨 Web Application Highlights

  • πŸ–ΌοΈ Modern UI with gradient animations and smooth transitions
  • 🎯 Drag-and-drop image upload with instant preview
  • πŸ“Š Confidence meters with visual progress bars
  • πŸ“± Mobile responsive design that works everywhere
  • ⚑ Auto model download from Google Drive (111 MB, cached)
  • πŸš€ Fast inference ~100-300ms per image
  • 🎨 Animated result cards color-coded by prediction
  • πŸ“ˆ Detailed metrics expandable technical information

οΏ½οΏ½ REST API Highlights

  • 🌐 RESTful endpoints following industry best practices
  • πŸ“¦ Batch prediction process up to 10 images in one request
  • πŸ”“ CORS enabled ready for web and mobile apps
  • βœ… Input validation file type, size, and format checks
  • πŸ’š Health checks monitor API and model status
  • πŸ›‘οΈ Production-ready with comprehensive logging
  • πŸ“š Interactive docs Swagger UI at /docs and ReDoc at /redoc
  • ⚑ Async support high-performance with uvicorn
  • πŸ“Š Detailed responses confidence scores, probabilities, metadata

🎬 Demo

Web Application

Try it live: https://cat-dog-prediction.streamlit.app/

Upload any cat or dog image and get instant AI predictions!

API Response Example

{
  "success": true,
  "filename": "cat.jpg",
  "prediction": "Cat",
  "confidence_percentage": 98.5,
  "probabilities": {
    "cat": 98.5,
    "dog": 1.5
  }
}

πŸš€ Quick Start

Prerequisites

  • βœ… Python 3.8+ (Download)
  • βœ… pip package manager
  • βœ… Git (Download)
  • βœ… Internet connection (for model download)

Local Development

1. Clone Repository

git clone https://github.com/fsRakib/Image-Classification-CNN.git
cd Image-Classification-CNN

2. Create Virtual Environment

# Windows
python -m venv venv
.\venv\Scripts\Activate.ps1

# Linux/Mac
python -m venv venv
source venv/bin/activate

3. Install Dependencies

pip install -r requirements.txt

4. Run Backend API

uvicorn api:app --host 0.0.0.0 --port 8000 --reload

Access at: http://localhost:8000

5. Run Streamlit Frontend (Optional)

streamlit run streamlit_app.py

Access at: http://localhost:8501


πŸ“‘ API Documentation

Available Endpoints

Endpoint Method Description
/ GET API information
/health GET Health check
/model/info GET Model details
/predict POST Single image prediction
/predict/batch POST Batch predictions (up to 10)

Example: Single Prediction

curl -X POST "https://web-production-c142d.up.railway.app/predict" -F "file=@cat.jpg"

Response:

{
  "success": true,
  "prediction": "Cat",
  "confidence_percentage": 98.5,
  "probabilities": { "cat": 98.5, "dog": 1.5 }
}

πŸ’‘ Usage Examples

Python

import requests

url = "https://web-production-c142d.up.railway.app/predict"
with open("cat.jpg", "rb") as f:
    response = requests.post(url, files={"file": f})
    print(response.json())

JavaScript

const formData = new FormData();
formData.append("file", fileInput.files[0]);

fetch("https://web-production-c142d.up.railway.app/predict", {
  method: "POST",
  body: formData
})
.then(res => res.json())
.then(data => console.log(data));

πŸ—οΈ Architecture

System Flow

User β†’ Streamlit Cloud (UI) β†’ Railway.app (API) β†’ CNN Model β†’ Prediction

Model Details

  • Architecture: Convolutional Neural Network (CNN)
  • Framework: TensorFlow/Keras
  • Input: 128Γ—128Γ—3 RGB images
  • Accuracy: ~92%
  • Model Size: 111 MB
  • Dataset: 25,000 cat/dog images

πŸ“ Project Structure

Image-Classification-CNN/
β”œβ”€β”€ api.py                    # FastAPI backend
β”œβ”€β”€ streamlit_app.py          # Streamlit frontend
β”œβ”€β”€ api_client.py             # API client wrapper
β”œβ”€β”€ requirements.txt          # Dependencies
β”œβ”€β”€ Procfile                  # Railway config
β”œβ”€β”€ railway.json              # Railway build settings
β”œβ”€β”€ dogs_vs_cats_production_model.keras  # Model (111 MB)
└── README.md                 # Documentation

🚒 Deployment

Current Deployment

  • Backend: Railway.app (Auto-deploy from main branch)
  • Frontend: Streamlit Cloud (Auto-deploy from main branch)

Deploy Your Own

Backend to Railway:

  1. Fork repository
  2. Sign up on Railway.app
  3. New project β†’ Deploy from GitHub
  4. Select repository (auto-detects config)

Frontend to Streamlit Cloud:

  1. Sign up on Streamlit.io/cloud
  2. New app β†’ Select repository
  3. Main file: streamlit_app.py
  4. Add secret: API_BASE_URL = "your-railway-url"

πŸ› Troubleshooting

Common Issues

Model Download Fails

  • Check internet connection
  • Download manually: [Google Drive Link]
  • Place in project root

API Connection Error

  • Verify Railway backend is running
  • Check Streamlit secrets configuration
  • Test: curl https://your-url/health

Module Not Found

  • Activate virtual environment
  • Run: pip install -r requirements.txt

Port Already in Use

  • Use different port: uvicorn api:app --port 8001
  • Or kill process: netstat -ano | findstr :8000

🀝 Contributing

Contributions welcome! Please:

  1. Fork the repository
  2. Create feature branch
  3. Make changes
  4. Test thoroughly
  5. Submit pull request

πŸ“ License

MIT License - see LICENSE file


οΏ½οΏ½ Acknowledgments

  • Kaggle Dogs vs Cats dataset
  • TensorFlow & Keras teams
  • FastAPI & Streamlit teams
  • Railway & Streamlit Cloud

πŸ“Š Project Stats

  • Model Size: 111 MB
  • Training Images: 25,000
  • Accuracy: ~92%
  • Inference Time: 100-300ms
  • Supported Formats: JPG, JPEG, PNG
  • Max File Size: 10MB

πŸ“§ Contact

Developer: Fahim Shahriar Rakib


Made with ❀️ using TensorFlow, FastAPI, and Streamlit

⭐ Star this repo if you found it helpful!

Report Bug Β· Request Feature

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages