Lesson 23-24: Computer Vision
VisionClassifier Platform: From Fragmented CV Scripts to a Unified Computer Vision Stack
Introduction
Computer vision prototypes usually die in notebooks: one script for preprocessing, another for training, a third for evaluation, and nothing that tracks experiments or serves inference behind a stable HTTP contract. week_23_24_aiml_integrated_project is a self-contained capstone that consolidates the full vision pipeline into one runnable system:
An installable Python package (
week2324_python) with concept-named modules for preprocessing, CNNs, pooling, datasets, training loops, evaluation, export, and deploymentA FastAPI backend exposing two API surfaces: a lab path for topic exploration and a product path for experiment lifecycle management
VisionClassifier Platform — a React dashboard with a guided pipeline, component studio, live training monitor, and multipart image inference
PostgreSQL-backed experiment metadata (async SQLAlchemy + Alembic), named Docker volumes for artifacts and dataset caches, and offline-safe synthetic fallbacks when CIFAR archives cannot be downloaded
The engineer payoff is traceability and boundaries. A quick CNN smoke test is not a stray script—it is train_simple_cnn behind a lab route with capped batches. Production training is not a blocking HTTP call—it is POST /api/v1/cv/experiments/{id}/train returning HTTP 202 while asyncio.create_task runs ResNet fine-tuning in a worker thread, with the dashboard polling run status until completion or failure.
Core Components
The stack is layered. Each topic below is a distinct building block; together they form one coherent image-classification platform.
Image preprocessing and normalization
image_pipeline.py handles OpenCV/PIL ingestion, ImageNet-style normalization profiles (CIFAR10_MEAN / CIFAR100_MEAN), and build_inference_transform for 224×224 upload tensors. preprocess_upload_bytes powers multipart inference on the product API.
Convolutional network architectures
SimpleCNN provides a pedagogical three-block classifier for CIFAR-10 smoke tests. ImageClassifier is a deeper three-block production-style CNN with checkpoint saving. build_resnet18_classifier wraps torchvision ResNet18 with a replaceable FC head for 100-way CIFAR-100 classification. inspect_feature_maps in cnn/debug.py exposes spatial activations for architecture demos.
Pooling strategies
pytorch_strategies.py compares MaxPool+Flatten vs Global Average Pooling parameter counts on PyTorch modules. keras_demos.py mirrors the same concepts in TensorFlow/Keras for side-by-side analysis—useful when explaining spatial reduction trade-offs without retraining full pipelines.
Dataset pipeline and EDA
cifar10.py and cifar100.py build train/val dataloaders with cache-aware download logic. synthetic.py provides deterministic offline datasets when network downloads fail inside Docker. summary.py implements fast EDA (dataset_summary_static, run_eda_report(fast=True)) that avoids loading 170MB archives on dashboard requests. cifar100_labels.py and superclass_map.py supply class metadata without touching torchvision downloads.
Training engine
loop.py defines train_epoch and evaluate with optional max_batches caps for dashboard-friendly runtimes. checkpoint.py saves rich .pth payloads (model, optimizer, epoch, val accuracy). schedulers.py builds cosine annealing schedules. hyperparam_search.py and regularization.py support tuning and weight-decay demos on the lab surface. trainers.py orchestrates train_simple_cnn, train_image_classifier, and train_resnet_cifar100.
Evaluation and ensemble
metrics.py implements evaluate_classification with confusion-matrix-friendly outputs. averaging.py supports multi-checkpoint ensemble prediction on the lab surface.
Export and deployment
torchscript.py traces models to TorchScript artifacts. demo_checkpoint.py bootstraps a demo .pth on API startup so inference is available before the first real training job completes. classifier_engine/pipeline.py composes the product layer: explain, run_cifar100_product_train, run_inference_on_bytes, run_export, deployment_demo.
Background training orchestration
Keep going with the full lesson
The rest of this lesson — plus its implementation guide, runnable scripts and source code — is included with the course or an All Access plan. Create a free account to start the free lessons in every course.
Already a member? Sign in