CoolFace
Apppublic

Nausad/Vision_Transformer_Based_Image_Classification_Model

sourceHugging Facemitupdated 4mo agoView on Hugging Face
0likes
App README

๐Ÿ” CIFAR-10 Vision Transformer Classifier

A web-based image classification application powered by a custom Vision Transformer (ViT) trained from scratch on the CIFAR-10 dataset. Upload any image and get real-time predictions across 10 categories.


๐Ÿš€ Demo

Upload any image via drag-and-drop or file browser. The model resizes it to 32ร—32 pixels (the native CIFAR-10 resolution) and predicts one of 10 classes with confidence scores.

Supported Classes: airplane ยท automobile ยท bird ยท cat ยท deer ยท dog ยท frog ยท horse ยท ship ยท truck


๐Ÿง  Model Architecture

ComponentDetails
ArchitectureVision Transformer (ViT) โ€” built from scratch
Patch Size4 ร— 4 pixels
Embedding Dim256
Transformer Depth20 layers
Attention Heads8
MLP Dim512
Total Parameters~10.57 Million
Input Size32 ร— 32 ร— 3
Output Classes10

Training Details

MetricValue
DatasetCIFAR-10 (50K train / 10K test)
Epochs25
Training Accuracy72.59%
Test Accuracy70.51%

๐Ÿ› ๏ธ Tech Stack

  • โ€”Backend: Flask (Python)
  • โ€”ML Framework: PyTorch
  • โ€”Frontend: HTML5 ยท Vanilla CSS ยท JavaScript
  • โ€”Model: Custom Vision Transformer (no pretrained weights)
  • โ€”Containerization: Docker

๐Ÿ“ Project Structure

โ”œโ”€โ”€ flask_app.py          # Flask server (routes: /, /predict, /model-info)
โ”œโ”€โ”€ cifar10_model.pth     # Trained model weights
โ”œโ”€โ”€ requirements.txt      # Python dependencies
โ”œโ”€โ”€ Dockerfile            # Container configuration
โ””โ”€โ”€ templates/
    โ””โ”€โ”€ index.html        # Full-featured web UI

โš™๏ธ Run Locally

bash
# 1. Install dependencies
pip install -r requirements.txt

# 2. Start the Flask server
python flask_app.py

# 3. Open in browser
# โ†’ http://127.0.0.1:5000

๐Ÿณ Run with Docker

bash
# Build the image
docker build -t cifar10-vit .

# Run the container
docker run -p 7860:7860 cifar10-vit

# Open in browser
# โ†’ http://localhost:7860

๐Ÿ“Š Features

  • โ€”๐Ÿ–ผ๏ธ Drag & Drop upload โ€” supports JPEG, PNG, WEBP, BMP
  • โ€”๐Ÿ”ฒ 32ร—32 pixel simulator โ€” see exactly what the model processes
  • โ€”๐Ÿ“Š Animated probability bars for all 10 classes
  • โ€”โšก Real-time inference with latency display (milliseconds)
  • โ€”๐ŸŽจ Warm beige premium UI with glassmorphism cards

๐Ÿ‘ค Author

Nausad Ali Built with โค๏ธ and a Cup of Coffee


๐Ÿ“„ License

This project is licensed under the MIT License.