CS5720 - Week 10
Slide 182 of 200

Image Classification: End-to-End Pipeline

1
Data Collection & Preparation
Gathering, organizing, and preprocessing image data for training
Data Sources
• Public datasets (ImageNet, CIFAR)
• Web scraping with proper licensing
• Custom photography/collection
• Synthetic data generation
Preprocessing Steps
• Resize to consistent dimensions
• Normalize pixel values (0-1 or -1,1)
• Data augmentation techniques
• Train/validation/test splits
2
Model Architecture Selection
Choose or design a neural network architecture suitable for your task
Popular Architectures
• ResNet: Skip connections for deep networks
• EfficientNet: Balanced scaling
• Vision Transformer: Attention-based
• MobileNet: Lightweight for mobile
# PyTorch model selection import torchvision.models as models model = models.resnet50(pretrained=True) model.fc = nn.Linear(2048, num_classes)
Design Considerations
• Number of classes in your dataset
• Available computational resources
• Speed vs accuracy requirements
• Transfer learning opportunities
3
Training & Optimization
Train the model using your prepared data and optimize hyperparameters
Training Setup
• Loss function (CrossEntropyLoss)
• Optimizer (Adam, SGD)
• Learning rate scheduling
• Batch size configuration
# Training loop optimizer = torch.optim.Adam(model.parameters(), lr=0.001) scheduler = torch.optim.lr_scheduler.StepLR(optimizer, step_size=7) criterion = nn.CrossEntropyLoss()
Monitoring
• Track training/validation loss
• Monitor accuracy metrics
• Early stopping to prevent overfitting
• Visualize training progress
4
Evaluation & Testing
Assess model performance on unseen data and analyze results
Evaluation Metrics
• Accuracy: Overall correctness
• Precision/Recall per class
• F1-score: Balanced metric
• Confusion matrix analysis
# Evaluation from sklearn.metrics import classification_report y_pred = model.predict(X_test) print(classification_report(y_true, y_pred))
Analysis
• Identify misclassified examples
• Analyze per-class performance
• Check for bias or overfitting
• Compare with baseline models
5
Deployment & Inference
Deploy the trained model for real-world use and handle inference
Deployment Options
• Cloud APIs (AWS, Google Cloud)
• Edge devices (mobile, IoT)
• Web applications (Flask, FastAPI)
• Batch processing systems
# Simple API endpoint from flask import Flask, request app = Flask(__name__) @app.route('/predict', methods=['POST']) def predict(): image = preprocess(request.files['image']) prediction = model(image) return jsonify({'class': prediction})
Production Considerations
• Model optimization (quantization)
• Monitoring and logging
• Error handling and fallbacks
• Performance and scalability

Popular Classification Models Comparison

ResNet-50
76.1%
Deep residual learning with skip connections. Excellent baseline for most tasks.
EfficientNet-B0
77.3%
Balanced scaling of depth, width, and resolution. Great efficiency.
Vision Transformer
81.8%
Attention-based architecture. State-of-the-art with large datasets.
MobileNet-V3
75.2%
Optimized for mobile devices. Fast inference with reasonable accuracy.
Prepared by Dr. Gorkem Kar