Skip to content

ziraddingulumjanly/Traffic-Sign-Recognition-with-PyTorch

Repository files navigation

German Traffic Sign Recognition with PyTorch

A compact, production-style computer vision project for classifying German traffic signs from the GTSRB dataset.

Cover Image

This repository is designed to be simple but professional:

  • PyTorch training pipeline
  • Torchvision dataset download with download=True
  • CNN baseline and ResNet18 transfer learning
  • validation split, test evaluation, and saved metrics
  • Matplotlib-only reporting figures
  • FastAPI inference endpoint
  • Dockerfile, Makefile, pyproject.toml, requirements.txt, GitHub Actions

Dataset

The project uses torchvision.datasets.GTSRB, so the dataset can be downloaded directly from code:

from torchvision.datasets import GTSRB

train_dataset = GTSRB(root="data", split="train", download=True)
test_dataset = GTSRB(root="data", split="test", download=True)

Setup

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

Full training

make train

Evaluation

make evaluate

FastAPI

Run locally:

make api

Then open:

http://localhost:8000/docs

Health check:

curl http://localhost:8000/health

Image prediction:

curl -X POST "http://localhost:8000/predict" \
  -F "file=@path/to/sign.png"

Docker

Build:

make docker-build

Run:

make docker-run

The container expects the trained model to exist at:

models/gtsrb_resnet18_best.pt

You can mount your local model folder:

docker run --rm -p 8000:8000 \
  -v "$(pwd)/models:/app/models" \
  gtsrb-classifier:latest

Matplotlib style

The plotting utilities in src/gtsrb_classifier/plots.py use a clean Matplotlib recipe style:

plt.rcParams["figure.dpi"] = 600
plt.rcParams["savefig.dpi"] = 600
plt.rcParams["mathtext.fontset"] = "cm"
plt.rcParams["font.family"] = "serif"

Reusable plotting functions:

from gtsrb_classifier.plots import plot_confusion_matrix, plot_training_curves

About

PyTorch traffic sign classification with CNN, ResNet18 transfer learning, FastAPI, Docker, testing, and CI/CD

Topics

Resources

License

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors