CoolFace
Apppublic

MinhTien30122003/SVM_vs_CNN

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

Spiral SVM vs ANN Benchmark Demo

A small web benchmark comparing SVM (RBF, scikit-learn) and ANN (PyTorch) on spiral classification variants. The current app is intentionally visual-first: users train and compare boundaries for 2-spiral and 3-spiral notebook-style benchmarks.

Live demo (Hugging Face Spaces): SVM_vs_CNN


Features

  • —Visual side-by-side boundary comparison: SVM vs ANN.
  • —Benchmark variants restricted to 2 spirals and 3 spirals.
  • —Notebook-aligned setup for key comparisons (including 3-spiral SVM behavior).
  • —Clean FastAPI backend with a single benchmark API endpoint.
  • —Lightweight UI with per-variant discussion notes shown after training completes.

Architecture (summary)

ComponentDescription
SVMRBF SVM via scikit-learn; benchmark uses notebook-aligned hyperparameters for 2/3-spiral settings.
ANNPyTorch ANN (ann_state_dict.pt) loaded for inference and retrained for benchmark visualization.
BackendFastAPI + Uvicorn; /train-compare triggers data generation, model fitting, and boundary rendering.

Project layout

text
Spiral_SVM_ANN_Demo/
├── src/
│   ├── app.py             # FastAPI routes + /demo UI HTML
│   ├── inference.py       # Spiral generation, train/compare, boundary rendering
│   └── modeling.py        # ANN module definitions + CSV loader
├── scripts/
│   └── train_models.py    # Export base SVM/ANN artifacts for app startup
├── requirements.txt
├── Dockerfile             # Docker deploy (HF Spaces: port 7860)
├── DEPLOY.md              # Deployment notes
├── models/
│   ├── svm_rbf.joblib
│   └── ann_state_dict.pt
├── data/
│   └── spiralsdataset.csv
└── static/css/
    ├── theme.css
    └── components.css

Local setup

Requirements: Python 3.10+ (recommended), pip.

bash
cd Spiral_SVM_ANN_Demo
python -m venv .venv
source .venv/bin/activate   # Windows: .venv\Scripts\activate
pip install -r requirements.txt

Prepare model artifacts

bash
python scripts/train_models.py

Run the server

bash
uvicorn src.app:app --reload --host 0.0.0.0 --port 7860

Environment variables (optional)

VariablePurpose
SVM_PATHAbsolute path to svm_rbf.joblib if not using the default models/ location.
ANN_PATHAbsolute path to ann_state_dict.pt if not using the default models/ location.

API overview

MethodPathDescription
GET/Redirects to /demo.
GET/demoWeb benchmark UI.
GET/apiJSON: model load status + endpoint hints.
GET/healthHealth check.
POST/train-compareTrain and compare on spiral variant (n_classes: 2 or 3).

See /docs for request/response schemas.


Deployment

  • —Hugging Face Spaces (Docker): use this repo with Dockerfile (port 7860).
  • —Optional workflow notes in DEPLOY.md.

Benchmark notes

  • —2-spiral: SVM often produces a smoother visual boundary than ANN.
  • —3-spiral: with notebook-aligned setup, both can fit strongly in benchmark mode.
  • —This app is configured as a visual benchmark (not a point-by-point prediction tool).

License

Educational / portfolio demo; source and weights are governed by your own repository terms.